Multiple bugfixes, addition of Logic class
This commit is contained in:
@@ -97,7 +97,7 @@ io.anuke.ucore.scene.ui.Label$LabelStyle: {
|
|||||||
menuitem-shortcut: {font: default-font, fontColor: menuitem }
|
menuitem-shortcut: {font: default-font, fontColor: menuitem }
|
||||||
},
|
},
|
||||||
io.anuke.ucore.scene.ui.TextField$TextFieldStyle: {
|
io.anuke.ucore.scene.ui.TextField$TextFieldStyle: {
|
||||||
default: {font: default-font, fontColor: white, disabledFontColor: grey, selection: selection, background: button, cursor: cursor, messageFont: default-font, messageFontColor: grey }
|
default: {font: default-font-chat, fontColor: white, disabledFontColor: grey, selection: selection, background: button, cursor: cursor, messageFont: default-font, messageFontColor: grey }
|
||||||
}
|
}
|
||||||
io.anuke.ucore.scene.ui.CheckBox$CheckBoxStyle: {
|
io.anuke.ucore.scene.ui.CheckBox$CheckBoxStyle: {
|
||||||
default: {checkboxOn: check-on, checkboxOff: check-off, checkboxOnOver: check-on-over, checkboxOver: check-over, font: default-font, fontColor: white, disabledFontColor: grey }
|
default: {checkboxOn: check-on, checkboxOff: check-off, checkboxOnOver: check-on-over, checkboxOver: check-over, font: default-font, fontColor: white, disabledFontColor: grey }
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ public class Mindustry extends ModuleCore {
|
|||||||
|
|
||||||
module(Vars.world = new World());
|
module(Vars.world = new World());
|
||||||
module(Vars.control = new Control());
|
module(Vars.control = new Control());
|
||||||
|
module(Vars.logic = new Logic());
|
||||||
module(Vars.renderer = new Renderer());
|
module(Vars.renderer = new Renderer());
|
||||||
module(Vars.ui = new UI());
|
module(Vars.ui = new UI());
|
||||||
module(Vars.netServer = new NetServer());
|
module(Vars.netServer = new NetServer());
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ public class Vars{
|
|||||||
public static final int webPort = 6568;
|
public static final int webPort = 6568;
|
||||||
|
|
||||||
public static Control control;
|
public static Control control;
|
||||||
|
public static Logic logic;
|
||||||
public static Renderer renderer;
|
public static Renderer renderer;
|
||||||
public static UI ui;
|
public static UI ui;
|
||||||
public static World world;
|
public static World world;
|
||||||
|
|||||||
@@ -92,10 +92,6 @@ public class Control extends Module{
|
|||||||
|
|
||||||
log("Total blocks loaded: " + Block.getAllBlocks().size);
|
log("Total blocks loaded: " + Block.getAllBlocks().size);
|
||||||
|
|
||||||
for(Block block : Block.getAllBlocks()){
|
|
||||||
block.postInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
Lines.setCircleVertices(14);
|
Lines.setCircleVertices(14);
|
||||||
|
|
||||||
Gdx.input.setCatchBackKey(true);
|
Gdx.input.setCatchBackKey(true);
|
||||||
@@ -429,7 +425,7 @@ public class Control extends Module{
|
|||||||
}
|
}
|
||||||
|
|
||||||
float waveSpacing(){
|
float waveSpacing(){
|
||||||
return wavespace*getDifficulty().timeScaling;
|
return wavespace * getDifficulty().timeScaling;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Difficulty getDifficulty(){
|
public Difficulty getDifficulty(){
|
||||||
@@ -478,7 +474,7 @@ public class Control extends Module{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAmount(Item item){
|
public int getAmount(Item item){
|
||||||
return items[item.id];
|
return items[item.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
165
core/src/io/anuke/mindustry/core/Logic.java
Normal file
165
core/src/io/anuke/mindustry/core/Logic.java
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
package io.anuke.mindustry.core;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
|
import io.anuke.mindustry.Vars;
|
||||||
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
|
import io.anuke.mindustry.entities.Bullet;
|
||||||
|
import io.anuke.mindustry.entities.Player;
|
||||||
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
|
import io.anuke.mindustry.entities.effect.Shield;
|
||||||
|
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||||
|
import io.anuke.mindustry.game.*;
|
||||||
|
import io.anuke.mindustry.graphics.Fx;
|
||||||
|
import io.anuke.mindustry.net.Net;
|
||||||
|
import io.anuke.mindustry.resource.Item;
|
||||||
|
import io.anuke.mindustry.world.Block;
|
||||||
|
import io.anuke.mindustry.world.Tile;
|
||||||
|
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||||
|
import io.anuke.ucore.core.Effects;
|
||||||
|
import io.anuke.ucore.core.Timers;
|
||||||
|
import io.anuke.ucore.entities.Entities;
|
||||||
|
import io.anuke.ucore.entities.EntityGroup;
|
||||||
|
import io.anuke.ucore.modules.Module;
|
||||||
|
import io.anuke.ucore.util.Mathf;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import static io.anuke.mindustry.Vars.*;
|
||||||
|
|
||||||
|
public class Logic extends Module {
|
||||||
|
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
|
||||||
|
public final EntityGroup<Enemy> enemyGroup = Entities.addGroup(Enemy.class).enableMapping();
|
||||||
|
public final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||||
|
public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
|
||||||
|
public final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
|
||||||
|
|
||||||
|
public final int[] items = new int[Item.getAllItems().size];
|
||||||
|
|
||||||
|
Array<EnemySpawn> spawns = WaveCreator.getSpawns();
|
||||||
|
int wave = 1;
|
||||||
|
int lastUpdated = -1;
|
||||||
|
float wavetime;
|
||||||
|
float extrawavetime;
|
||||||
|
int enemies = 0;
|
||||||
|
GameMode mode = GameMode.waves;
|
||||||
|
Difficulty difficulty = Difficulty.normal;
|
||||||
|
boolean friendlyFire;
|
||||||
|
|
||||||
|
Tile core;
|
||||||
|
Array<SpawnPoint> spawnpoints = new Array<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(){
|
||||||
|
Entities.initPhysics();
|
||||||
|
Entities.collisions().setCollider(tilesize, world::solid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play(){
|
||||||
|
wavetime = wavespace * difficulty.timeScaling * 2;
|
||||||
|
|
||||||
|
if(mode.infiniteResources){
|
||||||
|
Arrays.fill(items, 999999999);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset(){
|
||||||
|
lastUpdated = -1;
|
||||||
|
wave = 1;
|
||||||
|
extrawavetime = maxwavespace;
|
||||||
|
wavetime = wavespace * difficulty.timeScaling;
|
||||||
|
enemies = 0;
|
||||||
|
Entities.clear();
|
||||||
|
|
||||||
|
Arrays.fill(items, 0);
|
||||||
|
spawnpoints.clear();
|
||||||
|
|
||||||
|
for(Block block : Block.getAllBlocks()){
|
||||||
|
block.onReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.hudfrag.updateItems();
|
||||||
|
ui.hudfrag.updateWeapons();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runWave(){
|
||||||
|
|
||||||
|
if(lastUpdated < wave + 1){
|
||||||
|
world.pathfinder().resetPaths();
|
||||||
|
lastUpdated = wave + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(EnemySpawn spawn : spawns){
|
||||||
|
for(int lane = 0; lane < spawnpoints.size; lane ++){
|
||||||
|
int fl = lane;
|
||||||
|
Tile tile = spawnpoints.get(lane).start;
|
||||||
|
int spawnamount = spawn.evaluate(wave, lane);
|
||||||
|
|
||||||
|
for(int i = 0; i < spawnamount; i ++){
|
||||||
|
float range = 12f;
|
||||||
|
|
||||||
|
Timers.run(i*5f, () -> {
|
||||||
|
|
||||||
|
Enemy enemy = new Enemy(spawn.type);
|
||||||
|
enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range));
|
||||||
|
enemy.lane = fl;
|
||||||
|
enemy.tier = spawn.tier(wave, fl);
|
||||||
|
enemy.add();
|
||||||
|
|
||||||
|
Effects.effect(Fx.spawn, enemy);
|
||||||
|
|
||||||
|
enemies ++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wave ++;
|
||||||
|
|
||||||
|
wavetime = wavespace * difficulty.timeScaling;
|
||||||
|
extrawavetime = maxwavespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void coreDestroyed(){
|
||||||
|
if(Net.active() && Net.server()) netServer.handleGameOver();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateLogic(){
|
||||||
|
if(!GameState.is(State.menu)){
|
||||||
|
|
||||||
|
if(core.block() != ProductionBlocks.core && !ui.restart.isShown()){
|
||||||
|
coreDestroyed();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!GameState.is(State.paused) || Net.active()){
|
||||||
|
|
||||||
|
if(!mode.toggleWaves){
|
||||||
|
|
||||||
|
if(enemies <= 0){
|
||||||
|
wavetime -= delta();
|
||||||
|
|
||||||
|
if(lastUpdated < wave + 1 && wavetime < Vars.aheadPathfinding){ //start updating beforehand
|
||||||
|
world.pathfinder().resetPaths();
|
||||||
|
lastUpdated = wave + 1;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
extrawavetime -= delta();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(wavetime <= 0 || extrawavetime <= 0){
|
||||||
|
runWave();
|
||||||
|
}
|
||||||
|
|
||||||
|
Entities.update(Entities.defaultGroup());
|
||||||
|
Entities.update(bulletGroup);
|
||||||
|
Entities.update(enemyGroup);
|
||||||
|
Entities.update(tileGroup);
|
||||||
|
Entities.update(shieldGroup);
|
||||||
|
Entities.update(playerGroup);
|
||||||
|
|
||||||
|
Entities.collideGroups(enemyGroup, bulletGroup);
|
||||||
|
Entities.collideGroups(playerGroup, bulletGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,7 +38,7 @@ public class Player extends SyncEntity{
|
|||||||
|
|
||||||
public Player(){
|
public Player(){
|
||||||
hitbox.setSize(5);
|
hitbox.setSize(5);
|
||||||
hitboxTile.setSize(4f);
|
hitboxTile.setSize(5f);
|
||||||
|
|
||||||
maxhealth = 200;
|
maxhealth = 200;
|
||||||
heal();
|
heal();
|
||||||
@@ -144,8 +144,9 @@ public class Player extends SyncEntity{
|
|||||||
|
|
||||||
Tile tile = world.tileWorld(x, y);
|
Tile tile = world.tileWorld(x, y);
|
||||||
|
|
||||||
if(tile != null && tile.floor().liquid && tile.block() == Blocks.air){
|
//if player is in solid block
|
||||||
damage(health+1); //drown
|
if(tile != null && ((tile.floor().liquid && tile.block() == Blocks.air) || tile.solid())){
|
||||||
|
damage(health+1); //die instantly
|
||||||
}
|
}
|
||||||
|
|
||||||
vector.set(0, 0);
|
vector.set(0, 0);
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ public class Block{
|
|||||||
public void drawLayer2(Tile tile){}
|
public void drawLayer2(Tile tile){}
|
||||||
public void drawSelect(Tile tile){}
|
public void drawSelect(Tile tile){}
|
||||||
public void drawPlace(int x, int y, int rotation, boolean valid){}
|
public void drawPlace(int x, int y, int rotation, boolean valid){}
|
||||||
public void postInit(){}
|
|
||||||
public void placed(Tile tile){}
|
public void placed(Tile tile){}
|
||||||
|
|
||||||
public void tapped(Tile tile){}
|
public void tapped(Tile tile){}
|
||||||
|
|||||||
Reference in New Issue
Block a user