Broke 90% of all code

This commit is contained in:
Anuken
2018-01-27 14:43:35 -05:00
parent 93cd497c8d
commit 78c8dc4902
36 changed files with 582 additions and 745 deletions

View File

@@ -8,6 +8,7 @@ import io.anuke.mindustry.core.*;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.io.PlatformFunction; import io.anuke.mindustry.io.PlatformFunction;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.BlockLoader; import io.anuke.mindustry.world.BlockLoader;
import io.anuke.ucore.UCore; import io.anuke.ucore.UCore;
import io.anuke.ucore.core.Core; import io.anuke.ucore.core.Core;
@@ -16,6 +17,8 @@ import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.modules.ModuleCore; import io.anuke.ucore.modules.ModuleCore;
import static io.anuke.mindustry.Vars.*;
import java.util.Locale; import java.util.Locale;
public class Mindustry extends ModuleCore { public class Mindustry extends ModuleCore {
@@ -26,23 +29,26 @@ public class Mindustry extends ModuleCore {
@Override @Override
public void init(){ public void init(){
if(args.contains("-debug", false)) debug = true;
Settings.defaults("locale", "default"); Settings.defaults("locale", "default");
Settings.load("io.anuke.moment"); Settings.load("io.anuke.moment");
loadBundle(); loadBundle();
BlockLoader.load(); BlockLoader.load();
UCore.log("Total blocks loaded: " + Block.getAllBlocks().size);
module(Vars.world = new World()); module(world = new World());
module(Vars.control = new Control()); module(control = new Control());
module(Vars.logic = new Logic()); module(logic = new Logic());
module(Vars.renderer = new Renderer()); module(renderer = new Renderer());
module(Vars.ui = new UI()); module(ui = new UI());
module(Vars.netServer = new NetServer()); module(netServer = new NetServer());
module(Vars.netClient = new NetClient()); module(netClient = new NetClient());
} }
@Override @Override
public void dispose() { public void dispose() {
GameState.set(State.menu); state.set(State.menu);
platforms.onGameExit(); platforms.onGameExit();
Net.dispose(); Net.dispose();
super.dispose(); super.dispose();
@@ -91,7 +97,7 @@ public class Mindustry extends ModuleCore {
@Override @Override
public void postInit(){ public void postInit(){
Vars.control.reset(); control.reset();
} }
@Override @Override

View File

@@ -3,10 +3,15 @@ package io.anuke.mindustry;
import com.badlogic.gdx.Application.ApplicationType; import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import io.anuke.mindustry.core.*; import io.anuke.mindustry.core.*;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.Player; 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.ucore.UCore; import io.anuke.ucore.UCore;
import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.scene.ui.layout.Unit;
public class Vars{ public class Vars{
@@ -77,6 +82,8 @@ public class Vars{
public static final int port = 6567; public static final int port = 6567;
public static final int webPort = 6568; public static final int webPort = 6568;
public static final GameState state = new GameState();
public static Control control; public static Control control;
public static Logic logic; public static Logic logic;
public static Renderer renderer; public static Renderer renderer;
@@ -86,4 +93,10 @@ public class Vars{
public static NetClient netClient; public static NetClient netClient;
public static Player player; public static Player player;
public static final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping();
public static final EntityGroup<Enemy> enemyGroup = Entities.addGroup(Enemy.class).enableMapping();
public static final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
public static final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
public static final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
} }

View File

@@ -122,7 +122,7 @@ public class Pathfind{
//go through each spawnpoint, and if it's not found a path yet, update it //go through each spawnpoint, and if it's not found a path yet, update it
for(SpawnPoint point : Vars.control.getSpawnPoints()){ for(SpawnPoint point : Vars.control.getSpawnPoints()){
if(point.request == null){ if(point.request == null || point.finder == null){
resetPathFor(point); resetPathFor(point);
} }
@@ -150,13 +150,13 @@ public class Pathfind{
//warmup //warmup
for(int i = 0; i < 100; i ++){ for(int i = 0; i < 100; i ++){
point.finder.searchNodePath(point.start, Vars.control.getCore(), Vars.control.getDifficulty().heuristic, point.path); point.finder.searchNodePath(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.path.clear(); point.path.clear();
} }
Timers.mark(); Timers.mark();
for(int i = 0; i < amount; i ++){ for(int i = 0; i < amount; i ++){
point.finder.searchNodePath(point.start, Vars.control.getCore(), Vars.control.getDifficulty().heuristic, point.path); point.finder.searchNodePath(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.path.clear(); point.path.clear();
} }
UCore.log("Time elapsed: " + Timers.elapsed() + "ms\nAverage MS per path: " + Timers.elapsed()/amount); UCore.log("Time elapsed: " + Timers.elapsed() + "ms\nAverage MS per path: " + Timers.elapsed()/amount);
@@ -176,7 +176,7 @@ public class Pathfind{
point.pathTiles = null; point.pathTiles = null;
point.request = new PathFinderRequest<>(point.start, Vars.control.getCore(), Vars.control.getDifficulty().heuristic, point.path); point.request = new PathFinderRequest<>(point.start, Vars.world.getCore(), Vars.control.getDifficulty().heuristic, point.path);
point.request.statusChanged = true; //IMPORTANT! point.request.statusChanged = true; //IMPORTANT!
} }

View File

@@ -1,99 +1,63 @@
package io.anuke.mindustry.core; package io.anuke.mindustry.core;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Buttons; import com.badlogic.gdx.Input.Buttons;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Mindustry; import io.anuke.mindustry.Mindustry;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.game.DefaultKeybinds;
import io.anuke.mindustry.entities.effect.Shield; import io.anuke.mindustry.game.EventType.GameOver;
import io.anuke.mindustry.entities.enemies.Enemy; import io.anuke.mindustry.game.EventType.PlayEvent;
import io.anuke.mindustry.entities.enemies.EnemyTypes; import io.anuke.mindustry.game.EventType.ResetEvent;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.EventType.WaveEvent;
import io.anuke.mindustry.game.Tutorial;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.input.AndroidInput; import io.anuke.mindustry.input.AndroidInput;
import io.anuke.mindustry.input.DesktopInput; import io.anuke.mindustry.input.DesktopInput;
import io.anuke.mindustry.input.InputHandler; import io.anuke.mindustry.input.InputHandler;
import io.anuke.mindustry.io.Saves; import io.anuke.mindustry.io.Saves;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import io.anuke.mindustry.resource.Weapon; import io.anuke.mindustry.resource.Weapon;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Map; import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.UCore; import io.anuke.ucore.UCore;
import io.anuke.ucore.core.*; import io.anuke.ucore.core.*;
import io.anuke.ucore.core.Inputs.Axis;
import io.anuke.ucore.core.Inputs.DeviceType; import io.anuke.ucore.core.Inputs.DeviceType;
import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.graphics.Lines;
import io.anuke.ucore.modules.Module; import io.anuke.ucore.modules.Module;
import io.anuke.ucore.scene.ui.layout.Unit; import io.anuke.ucore.scene.ui.layout.Unit;
import io.anuke.ucore.util.Atlas; import io.anuke.ucore.util.Atlas;
import io.anuke.ucore.util.Input;
import io.anuke.ucore.util.InputProxy; import io.anuke.ucore.util.InputProxy;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
/**Control module.
* Handles all input, saving, keybinds and keybinds.
* Should <i>not</i> handle any game-critical state.
* This class is not created in the headless server.
*/
public class Control extends Module{ public class Control extends Module{
Tutorial tutorial = new Tutorial(); private Tutorial tutorial = new Tutorial();
boolean hiscore = false; private boolean hiscore = false;
final Array<Weapon> weapons = new Array<>(); private boolean shouldUpdateItems = false;
final int[] items = new int[Item.getAllItems().size]; private boolean wasPaused = false;
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping(); private Saves saves;
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);
Array<EnemySpawn> spawns; private float respawntime;
int wave = 1; private InputHandler input;
int lastUpdated = -1;
float wavetime;
float extrawavetime;
int enemies = 0;
GameMode mode = GameMode.waves;
Difficulty difficulty = Difficulty.normal;
Tile core;
Array<SpawnPoint> spawnpoints = new Array<>();
boolean shouldUpdateItems = false;
boolean wasPaused = false;
Saves saves;
float respawntime;
InputHandler input;
boolean friendlyFire;
private InputProxy proxy; private InputProxy proxy;
private float controlx, controly; private float controlx, controly;
private boolean controlling; private boolean controlling;
public Control(){ public Control(){
if(Mindustry.args.contains("-debug", false))
Vars.debug = true;
saves = new Saves(); saves = new Saves();
Inputs.useControllers(!Vars.gwt); Inputs.useControllers(!Vars.gwt);
log("Total blocks loaded: " + Block.getAllBlocks().size);
Lines.setCircleVertices(14);
Gdx.input.setCatchBackKey(true); Gdx.input.setCatchBackKey(true);
if(android){ if(android){
@@ -139,54 +103,7 @@ public class Control extends Module{
Musics.load("1.ogg", "2.ogg", "3.ogg", "4.ogg"); Musics.load("1.ogg", "2.ogg", "3.ogg", "4.ogg");
KeyBinds.defaults( DefaultKeybinds.load();
"move_x", new Axis(Input.A, Input.D),
"move_y", new Axis(Input.S, Input.W),
"select", Input.MOUSE_LEFT,
"break", Input.MOUSE_RIGHT,
"shoot", Input.MOUSE_LEFT,
"zoom_hold", Input.CONTROL_LEFT,
"zoom", new Axis(Input.SCROLL),
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
"pause", Input.SPACE,
"dash", Input.SHIFT_LEFT,
"rotate_alt", new Axis(Input.R, Input.E),
"rotate", new Axis(Input.SCROLL),
"player_list", Input.TAB,
"chat", Input.ENTER,
"weapon_1", Input.NUM_1,
"weapon_2", Input.NUM_2,
"weapon_3", Input.NUM_3,
"weapon_4", Input.NUM_4,
"weapon_5", Input.NUM_5,
"weapon_6", Input.NUM_6
);
KeyBinds.defaults(
DeviceType.controller,
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
"select", Input.CONTROLLER_R_BUMPER,
"break", Input.CONTROLLER_L_BUMPER,
"shoot", Input.CONTROLLER_R_TRIGGER,
"zoom_hold", Input.ANY_KEY,
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
"menu", Input.CONTROLLER_X,
"pause", Input.CONTROLLER_L_TRIGGER,
"dash", Input.CONTROLLER_Y,
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
"player_list", Input.CONTROLLER_START,
"chat", Input.ENTER,
"weapon_1", Input.NUM_1,
"weapon_2", Input.NUM_2,
"weapon_3", Input.NUM_3,
"weapon_4", Input.NUM_4,
"weapon_5", Input.NUM_5,
"weapon_6", Input.NUM_6
);
for(int i = 0; i < Vars.saveSlots; i ++){ for(int i = 0; i < Vars.saveSlots; i ++){
Settings.defaults("save-" + i + "-autosave", !Vars.gwt); Settings.defaults("save-" + i + "-autosave", !Vars.gwt);
@@ -212,60 +129,58 @@ public class Control extends Module{
player.isAndroid = Vars.android; player.isAndroid = Vars.android;
player.isLocal = true; player.isLocal = true;
spawns = WaveCreator.getSpawns();
saves.load(); saves.load();
}
public void reset(){ Events.on(PlayEvent.class, () -> {
weapons.clear(); renderer.clearTiles();
weapons.add(Weapon.blaster); player.x = world.getCore().worldx();
player.weaponLeft = player.weaponRight = weapons.first(); player.y = world.getCore().worldy() - Vars.tilesize*2;
lastUpdated = -1; Core.camera.position.set(player.x, player.y, 0);
wave = 1;
extrawavetime = maxwavespace;
wavetime = waveSpacing();
Entities.clear();
enemies = 0;
player.add(); ui.hudfrag.updateItems();
player.heal(); state.set(State.playing);
clearItems(); });
spawnpoints.clear();
respawntime = -1;
hiscore = false;
for(Block block : Block.getAllBlocks()){ Events.on(ResetEvent.class, () -> {
block.onReset(); player.weaponLeft = player.weaponRight = Weapon.blaster;
}
ui.hudfrag.updateItems(); player.add();
ui.hudfrag.updateWeapons(); player.heal();
}
public void play(){ respawntime = -1;
if(core == null) return; hiscore = false;
renderer.clearTiles();
player.x = core.worldx(); ui.hudfrag.updateItems();
player.y = core.worldy() - Vars.tilesize*2; ui.hudfrag.updateWeapons();
});
Core.camera.position.set(player.x, player.y, 0); Events.on(WaveEvent.class, () -> {
Sounds.play("spawn");
//multiplying by 2 so you start with more time in the beginning int last = Settings.getInt("hiscore" + world.getMap().name);
wavetime = waveSpacing()*2;
//hacky, but I doubt anyone will use this many resources if(state.wave > last && !state.mode.infiniteResources && !state.mode.toggleWaves){
if(mode.infiniteResources){ Settings.putInt("hiscore" + world.getMap().name, state.wave);
Arrays.fill(items, 999999999); Settings.save();
} hiscore = true;
}
ui.hudfrag.updateItems(); Mindustry.platforms.updateRPC();
});
GameState.set(State.playing); Events.on(GameOver.class, () -> {
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
Sounds.play("corexplode");
for(int i = 0; i < 16; i ++){
Timers.run(i*2, ()-> Effects.effect(Fx.explosion, world.getCore().worldx()+Mathf.range(40), world.getCore().worldy()+Mathf.range(40)));
}
Effects.effect(Fx.coreexplosion, world.getCore().worldx(), world.getCore().worldy());
ui.restart.show();
});
} }
public Saves getSaves(){ public Saves getSaves(){
@@ -276,178 +191,27 @@ public class Control extends Module{
return controlling; return controlling;
} }
public boolean isFriendlyFire() { public InputHandler input(){
return friendlyFire;
}
public void setFriendlyFire(boolean friendlyFire) {
if(this.friendlyFire != friendlyFire && Net.active() && Net.server()){
Vars.netServer.handleFriendlyFireChange(friendlyFire);
}
this.friendlyFire = friendlyFire;
}
public Tile getCore(){
return core;
}
public Array<SpawnPoint> getSpawnPoints(){
return spawnpoints;
}
public void setCore(Tile tile){
this.core = tile;
}
public InputHandler getInput(){
return input; return input;
} }
public void addSpawnPoint(Tile tile){
SpawnPoint point = new SpawnPoint();
point.start = tile;
spawnpoints.add(point);
}
public void playMap(Map map){ public void playMap(Map map){
ui.loadfrag.show(); ui.loadfrag.show();
saves.resetSave(); saves.resetSave();
Timers.run(16, ()->{ Timers.run(16, ()->{
reset(); logic.reset();
world.loadMap(map); world.loadMap(map);
play(); logic.play();
}); });
Timers.run(18, ()-> ui.loadfrag.hide()); Timers.run(18, ()-> ui.loadfrag.hide());
} }
public GameMode getMode(){
return mode;
}
public void setMode(GameMode mode){
this.mode = mode;
}
public boolean hasWeapon(Weapon weapon){
return weapons.contains(weapon, true);
}
public void addWeapon(Weapon weapon){
weapons.add(weapon);
}
public Array<Weapon> getWeapons(){
return weapons;
}
public void setWaveData(int enemies, int wave, float wavetime){
this.wave = wave;
this.wavetime = wavetime;
this.enemies = enemies;
this.extrawavetime = maxwavespace;
}
public void runWave(){
if(Net.client() && Net.active()){
return;
}
Sounds.play("spawn");
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 ++;
int last = Settings.getInt("hiscore" + world.getMap().name);
if(wave > last && !mode.infiniteResources && !mode.toggleWaves){
Settings.putInt("hiscore" + world.getMap().name, wave);
Settings.save();
hiscore = true;
}
wavetime = waveSpacing();
extrawavetime = maxwavespace;
Mindustry.platforms.updateRPC();
}
public void enemyDeath(){
enemies --;
}
public void coreDestroyed(){
Effects.shake(5, 6, Core.camera.position.x, Core.camera.position.y);
Sounds.play("corexplode");
for(int i = 0; i < 16; i ++){
Timers.run(i*2, ()-> Effects.effect(Fx.explosion, core.worldx()+Mathf.range(40), core.worldy()+Mathf.range(40)));
}
Effects.effect(Fx.coreexplosion, core.worldx(), core.worldy());
ui.restart.show();
if(Net.active() && Net.server()) netServer.handleGameOver();
}
public boolean isGameOver(){
return core != null && core.block() != ProductionBlocks.core;
}
float waveSpacing(){
return wavespace * getDifficulty().timeScaling;
}
public Difficulty getDifficulty(){
return difficulty;
}
public void setDifficulty(Difficulty d){
this.difficulty = d;
}
public boolean isHighScore(){ public boolean isHighScore(){
return hiscore; return hiscore;
} }
public int getEnemiesRemaining(){
return enemies;
}
public float getWaveCountdown(){
return wavetime;
}
public float getRespawnTime(){ public float getRespawnTime(){
return respawntime; return respawntime;
} }
@@ -456,80 +220,20 @@ public class Control extends Module{
this.respawntime = respawntime; this.respawntime = respawntime;
} }
public int getWave(){
return wave;
}
public Tutorial getTutorial(){ public Tutorial getTutorial(){
return tutorial; return tutorial;
} }
public void clearItems(){
Arrays.fill(items, 0);
addItem(Item.stone, 40);
if(debug){
Arrays.fill(items, 99999);
}
}
public int getAmount(Item item){
return items[item.id];
}
public void addItem(Item item, int amount){
items[item.id] += amount;
shouldUpdateItems = true;
}
public boolean hasItems(ItemStack[] items){
for(ItemStack stack : items)
if(!hasItem(stack))
return false;
return true;
}
public boolean hasItems(ItemStack[] items, int scaling){
for(ItemStack stack : items)
if(!hasItem(stack.item, stack.amount * scaling))
return false;
return true;
}
public boolean hasItem(ItemStack req){
return items[req.item.id] >= req.amount;
}
public boolean hasItem(Item item, int amount){
return items[item.id] >= amount;
}
public void removeItem(ItemStack req){
items[req.item.id] -= req.amount;
if(items[req.item.id] < 0) items[req.item.id] = 0; //prevents negative item glitches in multiplayer
shouldUpdateItems = true;
}
public void removeItems(ItemStack... reqs){
for(ItemStack req : reqs)
removeItem(req);
}
public int[] getItems(){
return items;
}
@Override @Override
public void pause(){ public void pause(){
wasPaused = GameState.is(State.paused); wasPaused = state.is(State.paused);
if(GameState.is(State.playing)) GameState.set(State.paused); if(state.is(State.playing)) state.set(State.paused);
} }
@Override @Override
public void resume(){ public void resume(){
if(GameState.is(State.paused) && !wasPaused){ if(state.is(State.paused) && !wasPaused){
GameState.set(State.playing); state.set(State.playing);
} }
} }
@@ -588,86 +292,40 @@ public class Control extends Module{
saves.update(); saves.update();
if(debug && GameState.is(State.playing)){ if(shouldUpdateItems && (Timers.get("updateItems", 8) || state.is(State.paused))){
//debug actions
if(Inputs.keyTap(Keys.P)){
Effects.effect(Fx.shellsmoke, player);
Effects.effect(Fx.shellexplosion, player);
}
if(Inputs.keyTap(Keys.C)){
enemyGroup.clear();
enemies = 0;
}
if(Inputs.keyTap(Keys.F)){
wavetime = 0f;
}
if(Inputs.keyTap(Keys.G)){
Vars.world.pathfinder().benchmark();
}
if(Inputs.keyDown(Keys.I)){
wavetime -= delta() * 10f;
}
if(Inputs.keyTap(Keys.U)){
Vars.showPaths = !Vars.showPaths;
}
if(Inputs.keyTap(Keys.O)){
Vars.noclip = !Vars.noclip;
}
if(Inputs.keyTap(Keys.Y)){
if(Inputs.keyDown(Keys.SHIFT_LEFT)){
new Enemy(EnemyTypes.healer).set(player.x, player.y).add();
}else{
float px = player.x, py = player.y;
Timers.run(30f, ()-> new Enemy(EnemyTypes.fortress).set(px, py).add());
}
}
}
if(shouldUpdateItems && (Timers.get("updateItems", 8) || GameState.is(State.paused))){
ui.hudfrag.updateItems(); ui.hudfrag.updateItems();
shouldUpdateItems = false; shouldUpdateItems = false;
} }
if(!GameState.is(State.menu)){ if(!state.is(State.menu)){
input.update(); input.update();
if(core.block() != ProductionBlocks.core && !ui.restart.isShown()){ if(Inputs.keyTap("pause") && !ui.restart.isShown() && !Net.active() && (state.is(State.paused) || state.is(State.playing))){
coreDestroyed(); state.set(state.is(State.playing) ? State.paused : State.playing);
}
if(Inputs.keyTap("pause") && !ui.restart.isShown() && !Net.active() && (GameState.is(State.paused) || GameState.is(State.playing))){
GameState.set(GameState.is(State.playing) ? State.paused : State.playing);
} }
if(Inputs.keyTap("menu")){ if(Inputs.keyTap("menu")){
if(GameState.is(State.paused)){ if(state.is(State.paused)){
ui.paused.hide(); ui.paused.hide();
GameState.set(State.playing); state.set(State.playing);
}else if (!ui.restart.isShown()){ }else if (!ui.restart.isShown()){
if(ui.chatfrag.chatOpen()) { if(ui.chatfrag.chatOpen()) {
ui.chatfrag.hide(); ui.chatfrag.hide();
}else{ }else{
ui.paused.show(); ui.paused.show();
GameState.set(State.paused); state.set(State.paused);
} }
} }
} }
if(!GameState.is(State.paused) || Net.active()){ if(!state.is(State.paused) || Net.active()){
if(respawntime > 0){ if(respawntime > 0){
respawntime -= delta(); respawntime -= delta();
if(respawntime <= 0){ if(respawntime <= 0){
player.set(core.worldx(), core.worldy()-Vars.tilesize*2); player.set(world.getSpawnX(), world.getSpawnY());
player.heal(); player.heal();
player.add(); player.add();
Effects.sound("respawn"); Effects.sound("respawn");
@@ -678,34 +336,6 @@ public class Control extends Module{
if(tutorial.active()){ if(tutorial.active()){
tutorial.update(); tutorial.update();
} }
if(!tutorial.active() && !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);
} }
} }
} }

View File

@@ -1,21 +1,33 @@
package io.anuke.mindustry.core; package io.anuke.mindustry.core;
import io.anuke.mindustry.Mindustry; import io.anuke.mindustry.game.Difficulty;
import io.anuke.ucore.core.Timers; import io.anuke.mindustry.game.EventType.StateChange;
import io.anuke.mindustry.game.GameMode;
import io.anuke.mindustry.game.Inventory;
import io.anuke.ucore.core.Events;
public class GameState{ public class GameState{
private static State state = State.menu; private State state = State.menu;
public static void set(State astate){ public final Inventory inventory = new Inventory();
if((astate == State.playing && state == State.menu) || (astate == State.menu && state != State.menu)){ int wave = 1;
Timers.runTask(5f, Mindustry.platforms::updateRPC); int lastUpdated = -1;
} float wavetime;
float extrawavetime;
int enemies = 0;
boolean gameOver = false;
GameMode mode = GameMode.waves;
Difficulty difficulty = Difficulty.normal;
boolean friendlyFire;
public void set(State astate){
//TODO update RPC handler
Events.fire(StateChange.class, state, astate);
state = astate; state = astate;
} }
public static boolean is(State astate){ public boolean is(State astate){
return state == astate; return state == astate;
} }

View File

@@ -3,50 +3,33 @@ package io.anuke.mindustry.core;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State; 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.entities.enemies.Enemy;
import io.anuke.mindustry.game.*; import io.anuke.mindustry.game.*;
import io.anuke.mindustry.game.EventType.GameOver;
import io.anuke.mindustry.game.EventType.PlayEvent;
import io.anuke.mindustry.game.EventType.ResetEvent;
import io.anuke.mindustry.graphics.Fx; import io.anuke.mindustry.graphics.Fx;
import io.anuke.mindustry.net.Net; 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.Tile;
import io.anuke.mindustry.world.blocks.ProductionBlocks; import io.anuke.mindustry.world.blocks.ProductionBlocks;
import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Effects;
import io.anuke.ucore.core.Events;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.Entities; import io.anuke.ucore.entities.Entities;
import io.anuke.ucore.entities.EntityGroup;
import io.anuke.ucore.modules.Module; import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
/**Logic module.
* Handles all logic for entities and waves.
* Handles game state events.
* Does not store any game state itself.
*
* This class should <i>not</i> call any outside methods to change state of modules, but instead fire events.
*/
public class Logic extends Module { public class Logic extends Module {
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class).enableMapping(); private final Array<EnemySpawn> spawns = WaveCreator.getSpawns();
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 @Override
public void init(){ public void init(){
@@ -55,44 +38,43 @@ public class Logic extends Module {
} }
public void play(){ public void play(){
wavetime = wavespace * difficulty.timeScaling * 2; state.wavetime = wavespace * state.difficulty.timeScaling * 2;
if(mode.infiniteResources){ if(state.mode.infiniteResources){
Arrays.fill(items, 999999999); state.inventory.fill();
} }
Events.fire(PlayEvent.class);
} }
public void reset(){ public void reset(){
lastUpdated = -1; state.wave = 1;
wave = 1; state.extrawavetime = maxwavespace;
extrawavetime = maxwavespace; state.wavetime = wavespace * state.difficulty.timeScaling;
wavetime = wavespace * difficulty.timeScaling; state.enemies = 0;
enemies = 0; state.lastUpdated = -1;
state.gameOver = false;
state.inventory.clearItems();
Entities.clear(); Entities.clear();
Arrays.fill(items, 0); Events.fire(ResetEvent.class);
spawnpoints.clear();
for(Block block : Block.getAllBlocks()){
block.onReset();
}
ui.hudfrag.updateItems();
ui.hudfrag.updateWeapons();
} }
public void runWave(){ public void runWave(){
if(lastUpdated < wave + 1){ if(state.lastUpdated < state.wave + 1){
world.pathfinder().resetPaths(); world.pathfinder().resetPaths();
lastUpdated = wave + 1; state.lastUpdated = state.wave + 1;
} }
for(EnemySpawn spawn : spawns){ for(EnemySpawn spawn : spawns){
for(int lane = 0; lane < spawnpoints.size; lane ++){ Array<SpawnPoint> spawns = world.getSpawns();
for(int lane = 0; lane < spawns.size; lane ++){
int fl = lane; int fl = lane;
Tile tile = spawnpoints.get(lane).start; Tile tile = spawns.get(lane).start;
int spawnamount = spawn.evaluate(wave, lane); int spawnamount = spawn.evaluate(state.wave, lane);
for(int i = 0; i < spawnamount; i ++){ for(int i = 0; i < spawnamount; i ++){
float range = 12f; float range = 12f;
@@ -102,51 +84,47 @@ public class Logic extends Module {
Enemy enemy = new Enemy(spawn.type); Enemy enemy = new Enemy(spawn.type);
enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range)); enemy.set(tile.worldx() + Mathf.range(range), tile.worldy() + Mathf.range(range));
enemy.lane = fl; enemy.lane = fl;
enemy.tier = spawn.tier(wave, fl); enemy.tier = spawn.tier(state.wave, fl);
enemy.add(); enemy.add();
Effects.effect(Fx.spawn, enemy); Effects.effect(Fx.spawn, enemy);
enemies ++; state.enemies ++;
}); });
} }
} }
} }
wave ++; state.wave ++;
state.wavetime = wavespace * state.difficulty.timeScaling;
wavetime = wavespace * difficulty.timeScaling; state.extrawavetime = maxwavespace;
extrawavetime = maxwavespace;
}
public void coreDestroyed(){
if(Net.active() && Net.server()) netServer.handleGameOver();
} }
public void updateLogic(){ public void updateLogic(){
if(!GameState.is(State.menu)){ if(!state.is(State.menu)){
if(core.block() != ProductionBlocks.core && !ui.restart.isShown()){ if(world.getCore().block() != ProductionBlocks.core && !state.gameOver){
coreDestroyed(); state.gameOver = true;
Events.fire(GameOver.class);
} }
if(!GameState.is(State.paused) || Net.active()){ if(!state.is(State.paused) || Net.active()){
if(!mode.toggleWaves){ if(!state.mode.toggleWaves){
if(enemies <= 0){ if(state.enemies <= 0){
wavetime -= delta(); state.wavetime -= delta();
if(lastUpdated < wave + 1 && wavetime < Vars.aheadPathfinding){ //start updating beforehand if(state.lastUpdated < state.wave + 1 && state.wavetime < Vars.aheadPathfinding){ //start updating beforehand
world.pathfinder().resetPaths(); world.pathfinder().resetPaths();
lastUpdated = wave + 1; state.lastUpdated = state.wave + 1;
} }
}else{ }else{
extrawavetime -= delta(); state.extrawavetime -= delta();
} }
} }
if(wavetime <= 0 || extrawavetime <= 0){ if(state.wavetime <= 0 || state.extrawavetime <= 0){
runWave(); runWave();
} }

View File

@@ -48,6 +48,7 @@ public class NetClient extends Module {
boolean gotData = false; boolean gotData = false;
boolean kicked = false; boolean kicked = false;
IntSet recieved = new IntSet(); IntSet recieved = new IntSet();
IntSet dead = new IntSet();
float playerSyncTime = 2; float playerSyncTime = 2;
float dataTimeout = 60*18; //18 seconds timeout float dataTimeout = 60*18; //18 seconds timeout
@@ -56,6 +57,7 @@ public class NetClient extends Module {
Net.handle(Connect.class, packet -> { Net.handle(Connect.class, packet -> {
Net.setClientLoaded(false); Net.setClientLoaded(false);
recieved.clear(); recieved.clear();
dead.clear();
connecting = true; connecting = true;
gotData = false; gotData = false;
kicked = false; kicked = false;
@@ -84,7 +86,7 @@ public class NetClient extends Module {
Timers.runFor(3f, Vars.ui.loadfrag::hide); Timers.runFor(3f, Vars.ui.loadfrag::hide);
GameState.set(State.menu); state.set(State.menu);
Vars.ui.showError("$text.disconnect"); Vars.ui.showError("$text.disconnect");
connecting = false; connecting = false;
@@ -174,7 +176,7 @@ public class NetClient extends Module {
Net.handle(EnemySpawnPacket.class, spawn -> { Net.handle(EnemySpawnPacket.class, spawn -> {
//duplicates. //duplicates.
if (Vars.control.enemyGroup.getByID(spawn.id) != null || if (Vars.control.enemyGroup.getByID(spawn.id) != null ||
recieved.contains(spawn.id)) return; recieved.contains(spawn.id) || dead.contains(spawn.id)) return;
recieved.add(spawn.id); recieved.add(spawn.id);
@@ -192,6 +194,7 @@ public class NetClient extends Module {
Net.handle(EnemyDeathPacket.class, spawn -> { Net.handle(EnemyDeathPacket.class, spawn -> {
Enemy enemy = Vars.control.enemyGroup.getByID(spawn.id); Enemy enemy = Vars.control.enemyGroup.getByID(spawn.id);
if (enemy != null) enemy.onDeath(); if (enemy != null) enemy.onDeath();
dead.add(spawn.id);
}); });
Net.handle(BulletPacket.class, packet -> { Net.handle(BulletPacket.class, packet -> {
@@ -289,7 +292,7 @@ public class NetClient extends Module {
Net.handle(KickPacket.class, packet -> { Net.handle(KickPacket.class, packet -> {
kicked = true; kicked = true;
Net.disconnect(); Net.disconnect();
GameState.set(State.menu); state.set(State.menu);
Vars.ui.showError("$text.server.kicked." + packet.reason.name()); Vars.ui.showError("$text.server.kicked." + packet.reason.name());
Vars.ui.loadfrag.hide(); Vars.ui.loadfrag.hide();
}); });
@@ -341,7 +344,7 @@ public class NetClient extends Module {
private void finishConnecting(){ private void finishConnecting(){
Net.send(new ConnectConfirmPacket(), SendMode.tcp); Net.send(new ConnectConfirmPacket(), SendMode.tcp);
GameState.set(State.playing); state.set(State.playing);
Net.setClientLoaded(true); Net.setClientLoaded(true);
connecting = false; connecting = false;
Vars.ui.loadfrag.hide(); Vars.ui.loadfrag.hide();

View File

@@ -265,7 +265,7 @@ public class NetServer extends Module{
public void handleGameOver(){ public void handleGameOver(){
Net.send(new GameOverPacket(), SendMode.tcp); Net.send(new GameOverPacket(), SendMode.tcp);
Timers.runTask(30f, () -> GameState.set(State.menu)); Timers.runTask(30f, () -> state.set(State.menu));
} }
public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){ public void handleBullet(BulletType type, Entity owner, float x, float y, float angle, short damage){

View File

@@ -53,6 +53,8 @@ public class Renderer extends RendererModule{
private BlockRenderer blocks = new BlockRenderer(); private BlockRenderer blocks = new BlockRenderer();
public Renderer() { public Renderer() {
Lines.setCircleVertices(14);
Core.cameraScale = baseCameraScale; Core.cameraScale = baseCameraScale;
Effects.setEffectProvider((name, color, x, y, rotation) -> { Effects.setEffectProvider((name, color, x, y, rotation) -> {
if(Settings.getBool("effects")){ if(Settings.getBool("effects")){
@@ -353,7 +355,7 @@ public class Renderer extends RendererModule{
tiley = Mathf.scl2(vec.y, tilesize); tiley = Mathf.scl2(vec.y, tilesize);
} }
InputHandler input = control.getInput(); InputHandler input = control.input();
//draw placement box //draw placement box
if((input.recipe != null && Vars.control.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android) if((input.recipe != null && Vars.control.hasItems(input.recipe.requirements) && (!ui.hasMouse() || android)

View File

@@ -7,12 +7,13 @@ import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.ai.Pathfind; import io.anuke.mindustry.ai.Pathfind;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.io.Maps; import io.anuke.mindustry.io.Maps;
import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.Net;
import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.Map; import io.anuke.mindustry.world.Map;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.WorldGenerator;
import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.DistributionBlocks; import io.anuke.mindustry.world.blocks.DistributionBlocks;
import io.anuke.mindustry.world.blocks.ProductionBlocks; import io.anuke.mindustry.world.blocks.ProductionBlocks;
@@ -23,17 +24,20 @@ import io.anuke.ucore.modules.Module;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp; import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.control;
import static io.anuke.mindustry.Vars.tilesize; import static io.anuke.mindustry.Vars.tilesize;
import static io.anuke.mindustry.Vars.world;
public class World extends Module{ public class World extends Module{
private int seed; private int seed;
private Map currentMap; private Map currentMap;
private Tile[][] tiles; private Tile[][] tiles;
private Tile[] temptiles = new Tile[4];
private Pathfind pathfind = new Pathfind(); private Pathfind pathfind = new Pathfind();
private io.anuke.mindustry.io.Maps maps = new io.anuke.mindustry.io.Maps(); private Maps maps = new Maps();
private Tile core;
private Array<SpawnPoint> spawns = new Array<>();
private Tile[] temptiles = new Tile[4];
public World(){ public World(){
maps.loadMaps(); maps.loadMaps();
@@ -51,6 +55,14 @@ public class World extends Module{
maps.dispose(); maps.dispose();
} }
public Array<SpawnPoint> getSpawns(){
return spawns;
}
public Tile getCore(){
return core;
}
public Maps maps(){ public Maps maps(){
return maps; return maps;
} }
@@ -59,6 +71,14 @@ public class World extends Module{
return pathfind; return pathfind;
} }
public float getSpawnX(){
return core.worldx();
}
public float getSpawnY(){
return core.worldy() - Vars.tilesize/2;
}
public boolean solid(int x, int y){ public boolean solid(int x, int y){
Tile tile = tile(x, y); Tile tile = tile(x, y);
@@ -175,28 +195,27 @@ public class World extends Module{
createTiles(); createTiles();
} }
Vars.control.getSpawnPoints().clear(); spawns.clear();
Entities.resizeTree(0, 0, map.getWidth() * tilesize, map.getHeight() * tilesize); Entities.resizeTree(0, 0, map.getWidth() * tilesize, map.getHeight() * tilesize);
this.seed = seed; this.seed = seed;
WorldGenerator.generate(map.pixmap, tiles);
if(control.getCore() == null) return; core = WorldGenerator.generate(map.pixmap, tiles, spawns);
control.getInput().placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0, false, false); placeBlock(core.x, core.y, ProductionBlocks.core, 0);
if(!map.name.equals("tutorial")){ if(!map.name.equals("tutorial")){
setDefaultBlocks(); setDefaultBlocks();
}else{ }else{
Vars.control.getTutorial().setDefaultBlocks(control.getCore().x, control.getCore().y); Vars.control.getTutorial().setDefaultBlocks(core.x, core.y);
} }
pathfind.resetPaths(); pathfind.resetPaths();
} }
void setDefaultBlocks(){ void setDefaultBlocks(){
int x = control.getCore().x, y = control.getCore().y; int x = core.x, y = core.y;
int flip = Mathf.sign(!currentMap.flipBase); int flip = Mathf.sign(!currentMap.flipBase);
int fr = currentMap.flipBase ? 2 : 0; int fr = currentMap.flipBase ? 2 : 0;
@@ -249,6 +268,32 @@ public class World extends Module{
} }
} }
public void placeBlock(int x, int y, Block result, int rotation){
Tile tile = world.tile(x, y);
//just in case
if(tile == null) return;
tile.setBlock(result, rotation);
if(result.isMultiblock()){
int offsetx = -(result.width-1)/2;
int offsety = -(result.height-1)/2;
for(int dx = 0; dx < result.width; dx ++){
for(int dy = 0; dy < result.height; dy ++){
int worldx = dx + offsetx + x;
int worldy = dy + offsety + y;
if(!(worldx == x && worldy == y)){
Tile toplace = world.tile(worldx, worldy);
if(toplace != null)
toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety));
}
}
}
}
}
public TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){ public TileEntity findTileTarget(float x, float y, Tile tile, float range, boolean damaged){
Entity closest = null; Entity closest = null;
float dst = 0; float dst = 0;
@@ -283,6 +328,7 @@ public class World extends Module{
return (TileEntity) closest; return (TileEntity) closest;
} }
/**Raycast, but with world coordinates.*/
public GridPoint2 raycastWorld(float x, float y, float x2, float y2){ public GridPoint2 raycastWorld(float x, float y, float x2, float y2){
return raycast(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize), return raycast(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize),
Mathf.scl2(x2, tilesize), Mathf.scl2(y2, tilesize)); Mathf.scl2(x2, tilesize), Mathf.scl2(y2, tilesize));
@@ -290,8 +336,7 @@ public class World extends Module{
/** /**
* Input is in block coordinates, not world coordinates. * Input is in block coordinates, not world coordinates.
* @return null if no collisions found, block position otherwise. * @return null if no collisions found, block position otherwise.*/
*/
public GridPoint2 raycast(int x0f, int y0f, int x1, int y1){ public GridPoint2 raycast(int x0f, int y0f, int x1, int y1){
int x0 = x0f; int x0 = x0f;
int y0 = y0f; int y0 = y0f;

View File

@@ -82,7 +82,7 @@ public class Bullet extends BulletEntity{
@Override @Override
public Bullet add(){ public Bullet add(){
return super.add(Vars.control.bulletGroup); return super.add(Vars.bulletGroup);
} }
} }

View File

@@ -54,7 +54,7 @@ public class Player extends SyncEntity{
public boolean collides(SolidEntity other){ public boolean collides(SolidEntity other){
if(other instanceof Bullet){ if(other instanceof Bullet){
Bullet b = (Bullet)other; Bullet b = (Bullet)other;
if(!Vars.control.isFriendlyFire() && b.owner instanceof Player){ if(!Vars.logic.friendlyFire && b.owner instanceof Player){
return false; return false;
} }
} }
@@ -91,7 +91,7 @@ public class Player extends SyncEntity{
set(-9999, -9999); set(-9999, -9999);
Timers.run(respawnduration, () -> { Timers.run(respawnduration, () -> {
heal(); heal();
set(Vars.control.getCore().worldx(), Vars.control.getCore().worldy()); set(logic.getSpawnX(), logic.getSpawnY());
}); });
} }
@@ -159,8 +159,8 @@ public class Player extends SyncEntity{
vector.y += ya*speed; vector.y += ya*speed;
vector.x += xa*speed; vector.x += xa*speed;
boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.getInput().recipe == null boolean shooting = !Inputs.keyDown("dash") && Inputs.keyDown("shoot") && control.input().recipe == null
&& !ui.hasMouse() && !control.getInput().onConfigurable(); && !ui.hasMouse() && !control.input().onConfigurable();
if(shooting){ if(shooting){
weaponLeft.update(player, true); weaponLeft.update(player, true);

View File

@@ -88,7 +88,7 @@ public class Enemy extends SyncEntity {
@Override @Override
public Enemy add(){ public Enemy add(){
return add(Vars.control.enemyGroup); return add(Vars.enemyGroup);
} }
@Override @Override

View File

@@ -21,7 +21,7 @@ import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Strings; import io.anuke.ucore.util.Strings;
import io.anuke.ucore.util.Tmp; import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.world; import static io.anuke.mindustry.Vars.*;
public class EnemyType { public class EnemyType {
@@ -80,11 +80,11 @@ public class EnemyType {
Graphics.flush(); Graphics.flush();
if(Vars.showPaths){ if(showPaths){
Draw.tscl(0.25f); Draw.tscl(0.25f);
Draw.text((int)enemy.idletime + "\n" + Strings.toFixed(enemy.totalMove.x, 2) + ", " Draw.text((int)enemy.idletime + "\n" + Strings.toFixed(enemy.totalMove.x, 2) + ", "
+ Strings.toFixed(enemy.totalMove.x, 2), enemy.x, enemy.y); + Strings.toFixed(enemy.totalMove.x, 2), enemy.x, enemy.y);
Draw.tscl(Vars.fontscale); Draw.tscl(fontscale);
} }
Shaders.outline.lighten = 0f; Shaders.outline.lighten = 0f;
@@ -134,8 +134,8 @@ public class EnemyType {
enemy.angle = Mathf.slerp(enemy.angle, enemy.angleTo(enemy.target), turretrotatespeed * Timers.delta()); enemy.angle = Mathf.slerp(enemy.angle, enemy.angleTo(enemy.target), turretrotatespeed * Timers.delta());
} }
enemy.x = Mathf.clamp(enemy.x, 0, Vars.world.width() * Vars.tilesize); enemy.x = Mathf.clamp(enemy.x, 0, world.width() * tilesize);
enemy.y = Mathf.clamp(enemy.y, 0, Vars.world.height() * Vars.tilesize); enemy.y = Mathf.clamp(enemy.y, 0, world.height() * tilesize);
} }
public void move(Enemy enemy){ public void move(Enemy enemy){
@@ -147,7 +147,7 @@ public class EnemyType {
return; return;
} }
Tile core = Vars.control.getCore(); Tile core = world.getCore();
if(enemy.idletime > maxIdleLife){ if(enemy.idletime > maxIdleLife){
enemy.onDeath(); enemy.onDeath();
@@ -161,7 +161,7 @@ public class EnemyType {
vec = Tmp.v1.setZero(); vec = Tmp.v1.setZero();
if(targetCore) enemy.target = core.entity; if(targetCore) enemy.target = core.entity;
}else{ }else{
vec = Vars.world.pathfinder().find(enemy); vec = world.pathfinder().find(enemy);
vec.sub(enemy.x, enemy.y).limit(speed); vec.sub(enemy.x, enemy.y).limit(speed);
} }
@@ -171,7 +171,7 @@ public class EnemyType {
float attractRange = avoidRange + 7f; float attractRange = avoidRange + 7f;
float avoidSpeed = this.speed/2.7f; float avoidSpeed = this.speed/2.7f;
Entities.getNearby(Vars.control.enemyGroup, enemy.x, enemy.y, range, en -> { Entities.getNearby(enemyGroup, enemy.x, enemy.y, range, en -> {
Enemy other = (Enemy)en; Enemy other = (Enemy)en;
if(other == enemy) return; if(other == enemy) return;
float dst = other.distanceTo(enemy); float dst = other.distanceTo(enemy);
@@ -202,14 +202,14 @@ public class EnemyType {
} }
if(enemy.timer.get(timerTarget, 15) && !nearCore){ if(enemy.timer.get(timerTarget, 15) && !nearCore){
enemy.target = Vars.world.findTileTarget(enemy.x, enemy.y, null, range, false); enemy.target = world.findTileTarget(enemy.x, enemy.y, null, range, false);
//no tile found //no tile found
if(enemy.target == null){ if(enemy.target == null){
enemy.target = Entities.getClosest(Vars.control.playerGroup, enemy.x, enemy.y, range, e -> !((Player)e).isAndroid); enemy.target = Entities.getClosest(playerGroup, enemy.x, enemy.y, range, e -> !((Player)e).isAndroid);
} }
}else if(nearCore){ }else if(nearCore){
enemy.target = Vars.control.getCore().entity; enemy.target = world.getCore().entity;
} }
if(enemy.target != null && bullet != null){ if(enemy.target != null && bullet != null){
@@ -220,7 +220,7 @@ public class EnemyType {
public void updateShooting(Enemy enemy){ public void updateShooting(Enemy enemy){
float reload = this.reload / Math.max(enemy.tier / 1.5f, 1f); float reload = this.reload / Math.max(enemy.tier / 1.5f, 1f);
if(enemy.timer.get(timerReload, reload * Vars.multiplier)){ if(enemy.timer.get(timerReload, reload * multiplier)){
shoot(enemy); shoot(enemy);
} }
} }
@@ -234,7 +234,7 @@ public class EnemyType {
public void onDeath(Enemy enemy){ public void onDeath(Enemy enemy){
if(Net.active() && Net.server()){ if(Net.active() && Net.server()){
Vars.netServer.handleEnemyDeath(enemy); netServer.handleEnemyDeath(enemy);
} }
Effects.effect(Fx.explosion, enemy); Effects.effect(Fx.explosion, enemy);
@@ -249,7 +249,7 @@ public class EnemyType {
if(enemy.spawner != null){ if(enemy.spawner != null){
enemy.spawner.spawned --; enemy.spawner.spawned --;
}else{ }else{
Vars.control.enemyDeath(); Vars.control.enemyDeath(); //TODO
} }
} }
} }

View File

@@ -30,8 +30,8 @@ public class FortressType extends EnemyType {
@Override @Override
public void move(Enemy enemy){ public void move(Enemy enemy){
if(enemy.distanceTo(Vars.control.getCore().worldx(), if(enemy.distanceTo(Vars.world.getCore().worldx(),
Vars.control.getCore().worldy()) <= 90f){ Vars.world.getCore().worldy()) <= 90f){
if(Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn){ if(Timers.get(this, "spawn", spawnTime) && enemy.spawned < maxSpawn){
Angles.translation(enemy.angle, 20f); Angles.translation(enemy.angle, 20f);

View File

@@ -0,0 +1,62 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import io.anuke.ucore.core.Inputs.Axis;
import io.anuke.ucore.core.Inputs.DeviceType;
import io.anuke.ucore.core.KeyBinds;
import io.anuke.ucore.util.Input;
public class DefaultKeybinds {
public static void load(){
KeyBinds.defaults(
"move_x", new Axis(Input.A, Input.D),
"move_y", new Axis(Input.S, Input.W),
"select", Input.MOUSE_LEFT,
"break", Input.MOUSE_RIGHT,
"shoot", Input.MOUSE_LEFT,
"zoom_hold", Input.CONTROL_LEFT,
"zoom", new Axis(Input.SCROLL),
"menu", Gdx.app.getType() == ApplicationType.Android ? Input.BACK : Input.ESCAPE,
"pause", Input.SPACE,
"dash", Input.SHIFT_LEFT,
"rotate_alt", new Axis(Input.R, Input.E),
"rotate", new Axis(Input.SCROLL),
"player_list", Input.TAB,
"chat", Input.ENTER,
"weapon_1", Input.NUM_1,
"weapon_2", Input.NUM_2,
"weapon_3", Input.NUM_3,
"weapon_4", Input.NUM_4,
"weapon_5", Input.NUM_5,
"weapon_6", Input.NUM_6
);
KeyBinds.defaults(
DeviceType.controller,
"move_x", new Axis(Input.CONTROLLER_L_STICK_HORIZONTAL_AXIS),
"move_y", new Axis(Input.CONTROLLER_L_STICK_VERTICAL_AXIS),
"cursor_x", new Axis(Input.CONTROLLER_R_STICK_HORIZONTAL_AXIS),
"cursor_y", new Axis(Input.CONTROLLER_R_STICK_VERTICAL_AXIS),
"select", Input.CONTROLLER_R_BUMPER,
"break", Input.CONTROLLER_L_BUMPER,
"shoot", Input.CONTROLLER_R_TRIGGER,
"zoom_hold", Input.ANY_KEY,
"zoom", new Axis(Input.CONTROLLER_DPAD_DOWN, Input.CONTROLLER_DPAD_UP),
"menu", Input.CONTROLLER_X,
"pause", Input.CONTROLLER_L_TRIGGER,
"dash", Input.CONTROLLER_Y,
"rotate_alt", new Axis(Input.CONTROLLER_DPAD_RIGHT, Input.CONTROLLER_DPAD_LEFT),
"rotate", new Axis(Input.CONTROLLER_A, Input.CONTROLLER_B),
"player_list", Input.CONTROLLER_START,
"chat", Input.ENTER,
"weapon_1", Input.NUM_1,
"weapon_2", Input.NUM_2,
"weapon_3", Input.NUM_3,
"weapon_4", Input.NUM_4,
"weapon_5", Input.NUM_5,
"weapon_6", Input.NUM_6
);
}
}

View File

@@ -0,0 +1,27 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.ucore.function.Event;
public class EventType {
public interface PlayEvent extends Event{
void handle();
}
public interface ResetEvent extends Event{
void handle();
}
public interface WaveEvent extends Event{
void handle();
}
public interface GameOver extends Event{
void handle();
}
public interface StateChange extends Event{
void handle(State from, State to);
}
}

View File

@@ -0,0 +1,70 @@
package io.anuke.mindustry.game;
import io.anuke.mindustry.resource.Item;
import io.anuke.mindustry.resource.ItemStack;
import java.util.Arrays;
import static io.anuke.mindustry.Vars.debug;
public class Inventory {
private final int[] items = new int[Item.getAllItems().size];
public void clearItems(){
Arrays.fill(items, 0);
addItem(Item.stone, 40);
if(debug){
Arrays.fill(items, 99999);
}
}
public void fill(){
Arrays.fill(items, 999999999);
}
public int getAmount(Item item){
return items[item.id];
}
public void addItem(Item item, int amount){
items[item.id] += amount;
}
public boolean hasItems(ItemStack[] items){
for(ItemStack stack : items)
if(!hasItem(stack))
return false;
return true;
}
public boolean hasItems(ItemStack[] items, int scaling){
for(ItemStack stack : items)
if(!hasItem(stack.item, stack.amount * scaling))
return false;
return true;
}
public boolean hasItem(ItemStack req){
return items[req.item.id] >= req.amount;
}
public boolean hasItem(Item item, int amount){
return items[item.id] >= amount;
}
public void removeItem(ItemStack req){
items[req.item.id] -= req.amount;
if(items[req.item.id] < 0) items[req.item.id] = 0; //prevents negative item glitches in multiplayer
}
public void removeItems(ItemStack... reqs){
for(ItemStack req : reqs)
removeItem(req);
}
public int[] getItems(){
return items;
}
}

View File

@@ -12,4 +12,8 @@ public class SpawnPoint{
public PathFinder<Tile> finder; public PathFinder<Tile> finder;
public SmoothGraphPath path = new SmoothGraphPath(); public SmoothGraphPath path = new SmoothGraphPath();
public PathFinderRequest<Tile> request; public PathFinderRequest<Tile> request;
public SpawnPoint(Tile start){
this.start = start;
}
} }

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.game; package io.anuke.mindustry.game;
import com.badlogic.gdx.math.GridPoint2; import com.badlogic.gdx.math.GridPoint2;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState; import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.Item;
@@ -19,8 +18,7 @@ import io.anuke.ucore.util.Bundles;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp; import io.anuke.ucore.util.Tmp;
import static io.anuke.mindustry.Vars.control; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.world;
public class Tutorial{ public class Tutorial{
private Stage stage; private Stage stage;
@@ -32,7 +30,7 @@ public class Tutorial{
} }
public boolean active(){ public boolean active(){
return world.getMap() != null && world.getMap().name.equals("tutorial") && !GameState.is(State.menu); return world.getMap() != null && world.getMap().name.equals("tutorial") && !state.is(State.menu);
} }
public void buildUI(table table){ public void buildUI(table table){
@@ -73,7 +71,7 @@ public class Tutorial{
//info.setText(stage.text); //info.setText(stage.text);
if(stage.showBlock){ if(stage.showBlock){
Tile tile = world.tile(control.getCore().x + stage.blockPlaceX, control.getCore().y + stage.blockPlaceY); Tile tile = world.tile(world.getCore().x + stage.blockPlaceX, world.getCore().y + stage.blockPlaceY);
if(tile.block() == stage.targetBlock && (tile.getRotation() == stage.blockRotation || stage.blockRotation == -1)){ if(tile.block() == stage.targetBlock && (tile.getRotation() == stage.blockRotation || stage.blockRotation == -1)){
move(true); move(true);
@@ -88,7 +86,7 @@ public class Tutorial{
public void complete(){ public void complete(){
//new TextDialog("Congratulations!", "You have completed the tutorial!").padText(Unit.dp.inPixels(10f)).show(); //new TextDialog("Congratulations!", "You have completed the tutorial!").padText(Unit.dp.inPixels(10f)).show();
GameState.set(State.menu); state.set(State.menu);
reset(); reset();
} }
@@ -104,7 +102,7 @@ public class Tutorial{
if(current < 0 || current >= Stage.values().length){ if(current < 0 || current >= Stage.values().length){
break; break;
}else if(Vars.android == Stage.values()[current].androidOnly || Vars.android != Stage.values()[current].desktopOnly){ }else if(android == Stage.values()[current].androidOnly || android != Stage.values()[current].desktopOnly){
stage = Stage.values()[current]; stage = Stage.values()[current];
stage.onSwitch(); stage.onSwitch();
break; break;
@@ -121,7 +119,7 @@ public class Tutorial{
if(current < 0 || current >= Stage.values().length){ if(current < 0 || current >= Stage.values().length){
return false; return false;
}else if(Vars.android == Stage.values()[current].androidOnly || Vars.android != Stage.values()[current].desktopOnly){ }else if(android == Stage.values()[current].androidOnly || android != Stage.values()[current].desktopOnly){
return true; return true;
} }
} }
@@ -198,7 +196,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttondistribution").fireClick(); ui.<ImageButton>find("sectionbuttondistribution").fireClick();
} }
}, },
placeConveyorDesktop{ placeConveyorDesktop{
@@ -232,7 +230,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
//Vars.player.recipe = null; //player.recipe = null;
} }
}, },
placeDrill{ placeDrill{
@@ -247,7 +245,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttonproduction").fireClick(); ui.<ImageButton>find("sectionbuttonproduction").fireClick();
} }
}, },
blockInfo{ blockInfo{
@@ -273,7 +271,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
control.getInput().recipe = null; control.input().recipe = null;
} }
}, },
drillInfo{ drillInfo{
@@ -291,12 +289,12 @@ public class Tutorial{
void onSwitch(){ void onSwitch(){
for(int flip : new int[]{1, -1}){ for(int flip : new int[]{1, -1}){
world.tile(control.getCore().x + flip, control.getCore().y - 2).setBlock(DistributionBlocks.conveyor, 2 * flip); world.tile(world.getCore().x + flip, world.getCore().y - 2).setBlock(DistributionBlocks.conveyor, 2 * flip);
world.tile(control.getCore().x + flip*2, control.getCore().y - 2).setBlock(DistributionBlocks.conveyor, 2 * flip); world.tile(world.getCore().x + flip*2, world.getCore().y - 2).setBlock(DistributionBlocks.conveyor, 2 * flip);
world.tile(control.getCore().x + flip*2, control.getCore().y - 3).setBlock(DistributionBlocks.conveyor, 2 * flip); world.tile(world.getCore().x + flip*2, world.getCore().y - 3).setBlock(DistributionBlocks.conveyor, 2 * flip);
world.tile(control.getCore().x + flip*2, control.getCore().y - 3).setBlock(DistributionBlocks.conveyor, 1); world.tile(world.getCore().x + flip*2, world.getCore().y - 3).setBlock(DistributionBlocks.conveyor, 1);
world.tile(control.getCore().x + flip*2, control.getCore().y - 4).setFloor(Blocks.stone); world.tile(world.getCore().x + flip*2, world.getCore().y - 4).setFloor(Blocks.stone);
world.tile(control.getCore().x + flip*2, control.getCore().y - 4).setBlock(ProductionBlocks.stonedrill); world.tile(world.getCore().x + flip*2, world.getCore().y - 4).setBlock(ProductionBlocks.stonedrill);
} }
} }
@@ -335,7 +333,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttonweapon").fireClick(); ui.<ImageButton>find("sectionbuttonweapon").fireClick();
} }
}, },
placedTurretAmmo{ placedTurretAmmo{
@@ -345,10 +343,10 @@ public class Tutorial{
void onSwitch(){ void onSwitch(){
for(int i = 0; i < 4; i ++){ for(int i = 0; i < 4; i ++){
world.tile(control.getCore().x + 2, control.getCore().y - 2 + i).setBlock(DistributionBlocks.conveyor, 1); world.tile(world.getCore().x + 2, world.getCore().y - 2 + i).setBlock(DistributionBlocks.conveyor, 1);
} }
control.getInput().recipe = null; control.input().recipe = null;
} }
}, },
turretExplanation{ turretExplanation{
@@ -375,31 +373,7 @@ public class Tutorial{
} }
}, },
//TODO re-add tutorial on weapons //TODO re-add tutorial on weapons
/*
purchaseWeapons{
{
desktopOnly = true;
canBack = false;
}
void onSwitch(){
Vars.control.addItem(Item.steel, 60);
Vars.control.addItem(Item.iron, 60);
}
},
switchWeapons{
{
canBack = false;
desktopOnly = true;
}
void onSwitch(){
if(!Vars.control.getWeapons().contains(Weapon.triblaster, true)){
Vars.control.getWeapons().add(Weapon.triblaster);
Vars.ui.hudfrag.updateWeapons();
}
}
},*/
spawnWave{ spawnWave{
float warmup = 0f; float warmup = 0f;
{ {
@@ -409,14 +383,14 @@ public class Tutorial{
void update(Tutorial t){ void update(Tutorial t){
warmup += Timers.delta(); warmup += Timers.delta();
if(Vars.control.getEnemiesRemaining() == 0 && warmup > 60f){ if(state.enemies == 0 && warmup > 60f){
t.move(true); t.move(true);
} }
} }
void onSwitch(){ void onSwitch(){
warmup = 0f; warmup = 0f;
Vars.control.runWave(); logic.runWave();
} }
}, },
pumpDesc{ pumpDesc{
@@ -436,9 +410,9 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttonproduction").fireClick(); ui.<ImageButton>find("sectionbuttonproduction").fireClick();
Vars.control.addItem(Item.steel, 60); state.inventory.addItem(Item.steel, 60);
Vars.control.addItem(Item.iron, 60); state.inventory.addItem(Item.iron, 60);
} }
}, },
conduitUse{ conduitUse{
@@ -454,8 +428,8 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttondistribution").fireClick(); ui.<ImageButton>find("sectionbuttondistribution").fireClick();
world.tile(blockPlaceX + control.getCore().x, blockPlaceY + control.getCore().y).setBlock(Blocks.air); world.tile(blockPlaceX + world.getCore().x, blockPlaceY + world.getCore().y).setBlock(Blocks.air);
} }
}, },
conduitUse2{ conduitUse2{
@@ -471,7 +445,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
world.tile(blockPlaceX + control.getCore().x, blockPlaceY + control.getCore().y).setBlock(Blocks.air); world.tile(blockPlaceX + world.getCore().x, blockPlaceY + world.getCore().y).setBlock(Blocks.air);
} }
}, },
conduitUse3{ conduitUse3{
@@ -487,7 +461,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
world.tile(blockPlaceX + control.getCore().x, blockPlaceY + control.getCore().y).setBlock(Blocks.air); world.tile(blockPlaceX + world.getCore().x, blockPlaceY + world.getCore().y).setBlock(Blocks.air);
} }
}, },
generator{ generator{
@@ -502,10 +476,10 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
world.tile(blockPlaceX + control.getCore().x, blockPlaceY + control.getCore().y).setBlock(Blocks.air); world.tile(blockPlaceX + world.getCore().x, blockPlaceY + world.getCore().y).setBlock(Blocks.air);
Vars.ui.<ImageButton>find("sectionbuttonpower").fireClick(); ui.<ImageButton>find("sectionbuttonpower").fireClick();
Vars.control.addItem(Item.steel, 60); state.inventory.addItem(Item.steel, 60);
Vars.control.addItem(Item.iron, 60); state.inventory.addItem(Item.iron, 60);
} }
}, },
generatorExplain{ generatorExplain{
@@ -526,7 +500,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttonpower").fireClick(); ui.<ImageButton>find("sectionbuttonpower").fireClick();
} }
}, },
laserExplain{ laserExplain{
@@ -552,7 +526,7 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.ui.<ImageButton>find("sectionbuttonpower").fireClick(); ui.<ImageButton>find("sectionbuttonpower").fireClick();
} }
}, },
healingTurretExplain{ healingTurretExplain{
@@ -573,9 +547,9 @@ public class Tutorial{
} }
void onSwitch(){ void onSwitch(){
Vars.control.addItem(Item.stone, 40); state.inventory.addItem(Item.stone, 40);
Vars.control.addItem(Item.iron, 40); state.inventory.addItem(Item.iron, 40);
Vars.ui.<ImageButton>find("sectionbuttoncrafting").fireClick(); ui.<ImageButton>find("sectionbuttoncrafting").fireClick();
} }
}, },
@@ -586,18 +560,18 @@ public class Tutorial{
void onSwitch(){ void onSwitch(){
for(int i = 0; i < 5; i ++){ for(int i = 0; i < 5; i ++){
world.tile(control.getCore().x, control.getCore().y - 6 + i).setBlock(DistributionBlocks.conveyor, 1); world.tile(world.getCore().x, world.getCore().y - 6 + i).setBlock(DistributionBlocks.conveyor, 1);
} }
world.tile(control.getCore().x, control.getCore().y - 6 + 1).setBlock(DistributionBlocks.tunnel, 3); world.tile(world.getCore().x, world.getCore().y - 6 + 1).setBlock(DistributionBlocks.tunnel, 3);
world.tile(control.getCore().x, control.getCore().y - 6 + 2).setBlock(DefenseBlocks.stonewall, 0); world.tile(world.getCore().x, world.getCore().y - 6 + 2).setBlock(DefenseBlocks.stonewall, 0);
world.tile(control.getCore().x, control.getCore().y - 6 + 3).setBlock(DistributionBlocks.tunnel, 1); world.tile(world.getCore().x, world.getCore().y - 6 + 3).setBlock(DistributionBlocks.tunnel, 1);
world.tile(control.getCore().x+1, control.getCore().y - 8).setBlock(ProductionBlocks.irondrill); world.tile(world.getCore().x+1, world.getCore().y - 8).setBlock(ProductionBlocks.irondrill);
world.tile(control.getCore().x-1, control.getCore().y - 8).setBlock(ProductionBlocks.coaldrill); world.tile(world.getCore().x-1, world.getCore().y - 8).setBlock(ProductionBlocks.coaldrill);
world.tile(control.getCore().x+1, control.getCore().y - 7).setBlock(DistributionBlocks.conveyor, 2); world.tile(world.getCore().x+1, world.getCore().y - 7).setBlock(DistributionBlocks.conveyor, 2);
world.tile(control.getCore().x-1, control.getCore().y - 7).setBlock(DistributionBlocks.conveyor, 0); world.tile(world.getCore().x-1, world.getCore().y - 7).setBlock(DistributionBlocks.conveyor, 0);
} }
}, },
tunnelExplain{ tunnelExplain{

View File

@@ -0,0 +1,25 @@
package io.anuke.mindustry.game;
import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.resource.Weapon;
public class UpgradeInventory {
private final Array<Weapon> weapons = new Array<>();
public boolean hasWeapon(Weapon weapon){
return weapons.contains(weapon, true);
}
public void addWeapon(Weapon weapon){
weapons.add(weapon);
}
public Array<Weapon> getWeapons(){
return weapons;
}
public void reset(){
weapons.clear();
weapons.add(Weapon.blaster);
}
}

View File

@@ -31,14 +31,14 @@ public class GestureHandler extends GestureAdapter{
public boolean tap (float x, float y, int count, int button) { public boolean tap (float x, float y, int count, int button) {
if(ui.hasMouse() || input.brokeBlock) return false; if(ui.hasMouse() || input.brokeBlock) return false;
if(!control.getInput().placeMode.pan || control.getInput().recipe == null){ if(!control.input().placeMode.pan || control.input().recipe == null){
input.mousex = x; input.mousex = x;
input.mousey = y; input.mousey = y;
if(control.getInput().recipe == null) if(control.input().recipe == null)
control.getInput().breakMode.tapped(input.getBlockX(), input.getBlockY()); control.input().breakMode.tapped(input.getBlockX(), input.getBlockY());
else else
control.getInput().placeMode.tapped(input.getBlockX(), input.getBlockY()); control.input().placeMode.tapped(input.getBlockX(), input.getBlockY());
} }
return false; return false;
} }
@@ -47,13 +47,13 @@ public class GestureHandler extends GestureAdapter{
public boolean pan(float x, float y, float deltaX, float deltaY){ public boolean pan(float x, float y, float deltaX, float deltaY){
if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false; if(Vars.control.showCursor() && !Inputs.keyDown("select")) return false;
if(!Vars.control.showCursor() && !(control.getInput().recipe != null && Vars.control.hasItems(control.getInput().recipe.requirements) && control.getInput().placeMode.lockCamera) && if(!Vars.control.showCursor() && !(control.input().recipe != null && Vars.control.hasItems(control.input().recipe.requirements) && control.input().placeMode.lockCamera) &&
!(control.getInput().recipe == null && control.getInput().breakMode.lockCamera)){ !(control.input().recipe == null && control.input().breakMode.lockCamera)){
float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale; float dx = deltaX*Core.camera.zoom/Core.cameraScale, dy = deltaY*Core.camera.zoom/Core.cameraScale;
player.x -= dx; player.x -= dx;
player.y += dy; player.y += dy;
player.targetAngle = Mathf.atan2(dx, -dy); player.targetAngle = Mathf.atan2(dx, -dy);
}else if(control.getInput().placeMode.lockCamera && (control.getInput().placeMode.pan && control.getInput().recipe != null)){ }else if(control.input().placeMode.lockCamera && (control.input().placeMode.pan && control.input().recipe != null)){
input.mousex += deltaX; input.mousex += deltaX;
input.mousey += deltaY; input.mousey += deltaY;
} }
@@ -63,7 +63,7 @@ public class GestureHandler extends GestureAdapter{
@Override @Override
public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) { public boolean pinch (Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
if(control.getInput().recipe == null && !control.getInput().breakMode.lockCamera) if(control.input().recipe == null && !control.input().breakMode.lockCamera)
return false; return false;
if(pinch1.x < 0){ if(pinch1.x < 0){

View File

@@ -129,7 +129,7 @@ public abstract class InputHandler extends InputAdapter{
int rotation = Vars.control.getTutorial().getPlaceRotation(); int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock(); Block block = Vars.control.getTutorial().getPlaceBlock();
if(type != block || point.x != x - control.getCore().x || point.y != y - control.getCore().y if(type != block || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|| (rotation != -1 && rotation != this.rotation)){ || (rotation != -1 && rotation != this.rotation)){
return false; return false;
} }
@@ -173,7 +173,7 @@ public abstract class InputHandler extends InputAdapter{
int rotation = Vars.control.getTutorial().getPlaceRotation(); int rotation = Vars.control.getTutorial().getPlaceRotation();
Block block = Vars.control.getTutorial().getPlaceBlock(); Block block = Vars.control.getTutorial().getPlaceBlock();
if(block != Blocks.air || point.x != x - control.getCore().x || point.y != y - control.getCore().y if(block != Blocks.air || point.x != x - world.getCore().x || point.y != y - world.getCore().y
|| (rotation != -1 && rotation != this.rotation)){ || (rotation != -1 && rotation != this.rotation)){
return false; return false;
} }

View File

@@ -30,23 +30,23 @@ public enum PlaceMode{
float x = tilex * Vars.tilesize; float x = tilex * Vars.tilesize;
float y = tiley * Vars.tilesize; float y = tiley * Vars.tilesize;
boolean valid = control.getInput().validPlace(tilex, tiley, control.getInput().recipe.result) && (android || control.getInput().cursorNear()); boolean valid = control.input().validPlace(tilex, tiley, control.input().recipe.result) && (android || control.input().cursorNear());
Vector2 offset = control.getInput().recipe.result.getPlaceOffset(); Vector2 offset = control.input().recipe.result.getPlaceOffset();
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f; float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid")); Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.stroke(2f); Lines.stroke(2f);
Lines.crect(x + offset.x, y + offset.y, tilesize * control.getInput().recipe.result.width + si, Lines.crect(x + offset.x, y + offset.y, tilesize * control.input().recipe.result.width + si,
tilesize * control.getInput().recipe.result.height + si); tilesize * control.input().recipe.result.height + si);
control.getInput().recipe.result.drawPlace(tilex, tiley, control.getInput().rotation, valid); control.input().recipe.result.drawPlace(tilex, tiley, control.input().rotation, valid);
Lines.stroke(2f); Lines.stroke(2f);
if(control.getInput().recipe.result.rotate){ if(control.input().recipe.result.rotate){
Draw.color(Colors.get("placeRotate")); Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(control.getInput().rotation * 90); Tmp.v1.set(7, 0).rotate(control.input().rotation * 90);
Lines.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y); Lines.line(x, y, x + Tmp.v1.x, y + Tmp.v1.y);
} }
@@ -57,7 +57,7 @@ public enum PlaceMode{
} }
public void tapped(int tilex, int tiley){ public void tapped(int tilex, int tiley){
control.getInput().tryPlaceBlock(tilex, tiley, true); control.input().tryPlaceBlock(tilex, tiley, true);
} }
}, },
touch{ touch{
@@ -69,7 +69,7 @@ public enum PlaceMode{
} }
public void tapped(int x, int y){ public void tapped(int x, int y){
control.getInput().tryPlaceBlock(x, y, true); control.input().tryPlaceBlock(x, y, true);
} }
}, },
none{ none{
@@ -89,12 +89,12 @@ public enum PlaceMode{
public void draw(int tilex, int tiley, int endx, int endy){ public void draw(int tilex, int tiley, int endx, int endy){
Tile tile = world.tile(tilex, tiley); Tile tile = world.tile(tilex, tiley);
if(tile != null && control.getInput().validBreak(tilex, tiley)){ if(tile != null && control.input().validBreak(tilex, tiley)){
if(tile.isLinked()) if(tile.isLinked())
tile = tile.getLinked(); tile = tile.getLinked();
float fract = control.getInput().breaktime / tile.getBreakTime(); float fract = control.input().breaktime / tile.getBreakTime();
if(android && control.getInput().breaktime > 0){ if(android && control.input().breaktime > 0){
Draw.color(Colors.get("breakStart"), Colors.get("break"), fract); Draw.color(Colors.get("breakStart"), Colors.get("break"), fract);
Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fract) * 26); Lines.poly(tile.drawx(), tile.drawy(), 25, 4 + (1f - fract) * 26);
} }
@@ -112,7 +112,7 @@ public enum PlaceMode{
} }
public void tapped(int x, int y){ public void tapped(int x, int y){
control.getInput().tryDeleteBlock(x, y, true); control.input().tryDeleteBlock(x, y, true);
} }
}, },
areaDelete{ areaDelete{
@@ -155,7 +155,7 @@ public enum PlaceMode{
Tile tile = Vars.world.tile(cx, cy); Tile tile = Vars.world.tile(cx, cy);
if(tile != null && tile.getLinked() != null) if(tile != null && tile.getLinked() != null)
tile = tile.getLinked(); tile = tile.getLinked();
if(tile != null && control.getInput().validBreak(tile.x, tile.y)){ if(tile != null && control.input().validBreak(tile.x, tile.y)){
Lines.crect(tile.drawx(), tile.drawy(), Lines.crect(tile.drawx(), tile.drawy(),
tile.block().width * t, tile.block().height * t); tile.block().width * t, tile.block().height * t);
} }
@@ -163,7 +163,7 @@ public enum PlaceMode{
} }
Lines.stroke(2f); Lines.stroke(2f);
Draw.color(control.getInput().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid")); Draw.color(control.input().cursorNear() ? Colors.get("break") : Colors.get("breakInvalid"));
Lines.rect(x, y, x2 - x, y2 - y); Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f); Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y); Draw.crect("blank", x, y, x2 - x, y2 - y);
@@ -192,7 +192,7 @@ public enum PlaceMode{
for(int cx = tilex; cx <= endx; cx ++){ for(int cx = tilex; cx <= endx; cx ++){
for(int cy = tiley; cy <= endy; cy ++){ for(int cy = tiley; cy <= endy; cy ++){
if(control.getInput().tryDeleteBlock(cx, cy, first)){ if(control.input().tryDeleteBlock(cx, cy, first)){
first = false; first = false;
} }
} }
@@ -247,7 +247,7 @@ public enum PlaceMode{
} }
float t = Vars.tilesize; float t = Vars.tilesize;
Block block = control.getInput().recipe.result; Block block = control.input().recipe.result;
Vector2 offset = block.getPlaceOffset(); Vector2 offset = block.getPlaceOffset();
process(tilex, tiley, endx, endy); process(tilex, tiley, endx, endy);
@@ -276,7 +276,7 @@ public enum PlaceMode{
cursor.draw(tilex, tiley, endx, endy); cursor.draw(tilex, tiley, endx, endy);
}else{ }else{
Lines.stroke(2f); Lines.stroke(2f);
Draw.color(control.getInput().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid")); Draw.color(control.input().cursorNear() ? Colors.get("place") : Colors.get("placeInvalid"));
Lines.rect(x, y, x2 - x, y2 - y); Lines.rect(x, y, x2 - x, y2 - y);
Draw.alpha(0.3f); Draw.alpha(0.3f);
Draw.crect("blank", x, y, x2 - x, y2 - y); Draw.crect("blank", x, y, x2 - x, y2 - y);
@@ -289,15 +289,15 @@ public enum PlaceMode{
int px = tx + cx * Mathf.sign(ex - tx), int px = tx + cx * Mathf.sign(ex - tx),
py = ty + cy * Mathf.sign(ey - ty); py = ty + cy * Mathf.sign(ey - ty);
if(!control.getInput().validPlace(px, py, control.getInput().recipe.result) if(!control.input().validPlace(px, py, control.input().recipe.result)
|| !control.hasItems(control.getInput().recipe.requirements, amount)){ || !control.hasItems(control.input().recipe.requirements, amount)){
Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height); Lines.crect(px * t + offset.x, py * t + offset.y, t*block.width, t*block.height);
} }
amount ++; amount ++;
} }
} }
if(control.getInput().recipe.result.rotate){ if(control.input().recipe.result.rotate){
float cx = tx * t, cy = ty * t; float cx = tx * t, cy = ty * t;
Draw.color(Colors.get("placeRotate")); Draw.color(Colors.get("placeRotate"));
Tmp.v1.set(7, 0).rotate(rotation * 90); Tmp.v1.set(7, 0).rotate(rotation * 90);
@@ -310,12 +310,12 @@ public enum PlaceMode{
public void released(int tilex, int tiley, int endx, int endy){ public void released(int tilex, int tiley, int endx, int endy){
process(tilex, tiley, endx, endy); process(tilex, tiley, endx, endy);
control.getInput().rotation = this.rotation; control.input().rotation = this.rotation;
boolean first = true; boolean first = true;
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){ for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){ for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
if(control.getInput().tryPlaceBlock( if(control.input().tryPlaceBlock(
tilex + x * Mathf.sign(endx - tilex), tilex + x * Mathf.sign(endx - tilex),
tiley + y * Mathf.sign(endy - tiley), first)){ tiley + y * Mathf.sign(endy - tiley), first)){
first = false; first = false;
@@ -349,7 +349,7 @@ public enum PlaceMode{
else if(endy < tiley) else if(endy < tiley)
rotation = 3; rotation = 3;
else else
rotation = control.getInput().rotation; rotation = control.input().rotation;
if(endx < tilex){ if(endx < tilex){
int t = endx; int t = endx;

View File

@@ -34,7 +34,7 @@ public class DrawOperation implements Disposable{
} }
public void disposeFrom(){ public void disposeFrom(){
from.dispose(); if(from != null) from.dispose();
} }
} }

View File

@@ -263,7 +263,7 @@ public class NetworkIO {
Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed); Vars.world.loadMap(Vars.world.maps().getMap(mapid), seed);
Vars.renderer.clearTiles(); Vars.renderer.clearTiles();
Vars.player.set(Vars.control.getCore().worldx(), Vars.control.getCore().worldy()); Vars.player.set(Vars.world.getCore().worldx(), Vars.world.getCore().worldy());
for(int x = 0; x < Vars.world.width(); x ++){ for(int x = 0; x < Vars.world.width(); x ++){
for(int y = 0; y < Vars.world.height(); y ++){ for(int y = 0; y < Vars.world.height(); y ++){

View File

@@ -160,12 +160,12 @@ public class LoadDialog extends FloatingDialog{
hide(); hide();
try{ try{
slot.load(); slot.load();
GameState.set(State.playing); state.set(State.playing);
Vars.ui.paused.hide(); Vars.ui.paused.hide();
}catch(Exception e){ }catch(Exception e){
UCore.error(e); UCore.error(e);
Vars.ui.paused.hide(); Vars.ui.paused.hide();
GameState.set(State.menu); state.set(State.menu);
Vars.control.reset(); Vars.control.reset();
Vars.ui.showError("$text.save.corrupted"); Vars.ui.showError("$text.save.corrupted");
} }

View File

@@ -34,7 +34,7 @@ public class PausedDialog extends FloatingDialog{
shown(() -> { shown(() -> {
wasPaused = GameState.is(State.paused); wasPaused = GameState.is(State.paused);
if(!Net.active()) GameState.set(State.paused); if(!Net.active()) state.set(State.paused);
}); });
if(!Vars.android){ if(!Vars.android){
@@ -43,7 +43,7 @@ public class PausedDialog extends FloatingDialog{
content().addButton("$text.back", () -> { content().addButton("$text.back", () -> {
hide(); hide();
if((!wasPaused || Net.active()) && !GameState.is(State.menu)) if((!wasPaused || Net.active()) && !GameState.is(State.menu))
GameState.set(State.playing); state.set(State.playing);
}); });
content().row(); content().row();
@@ -88,7 +88,7 @@ public class PausedDialog extends FloatingDialog{
new imagebutton("icon-play-2", isize, () -> { new imagebutton("icon-play-2", isize, () -> {
hide(); hide();
if(!wasPaused && !GameState.is(State.menu)) if(!wasPaused && !GameState.is(State.menu))
GameState.set(State.playing); state.set(State.playing);
}).text("$text.back").padTop(4f); }).text("$text.back").padTop(4f);
new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f); new imagebutton("icon-tools", isize, ui.settings::show).text("$text.settings").padTop(4f);
@@ -130,7 +130,7 @@ public class PausedDialog extends FloatingDialog{
private void runExitSave(){ private void runExitSave(){
if(Vars.control.getSaves().getCurrent() == null || if(Vars.control.getSaves().getCurrent() == null ||
!Vars.control.getSaves().getCurrent().isAutosave()){ !Vars.control.getSaves().getCurrent().isAutosave()){
GameState.set(State.menu); state.set(State.menu);
Vars.control.getTutorial().reset(); Vars.control.getTutorial().reset();
return; return;
} }
@@ -145,7 +145,7 @@ public class PausedDialog extends FloatingDialog{
e = (e.getCause() == null ? e : e.getCause()); e = (e.getCause() == null ? e : e.getCause());
Vars.ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber()); Vars.ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
} }
GameState.set(State.menu); state.set(State.menu);
}); });
} }
} }

View File

@@ -24,7 +24,7 @@ public class RestartDialog extends Dialog {
getButtonTable().addButton("$text.menu", ()-> { getButtonTable().addButton("$text.menu", ()-> {
hide(); hide();
GameState.set(State.menu); state.set(State.menu);
control.reset(); control.reset();
}).size(130f, 60f); }).size(130f, 60f);
} }

View File

@@ -35,7 +35,7 @@ public class SettingsMenuDialog extends SettingsDialog{
hidden(()->{ hidden(()->{
if(!GameState.is(State.menu)){ if(!GameState.is(State.menu)){
if(!wasPaused || Net.active()) if(!wasPaused || Net.active())
GameState.set(State.playing); state.set(State.playing);
} }
}); });
@@ -45,7 +45,7 @@ public class SettingsMenuDialog extends SettingsDialog{
if(menu.getScene() != null){ if(menu.getScene() != null){
wasPaused = ((PausedDialog)menu).wasPaused; wasPaused = ((PausedDialog)menu).wasPaused;
} }
if(!Net.active()) GameState.set(State.paused); if(!Net.active()) state.set(State.paused);
Vars.ui.paused.hide(); Vars.ui.paused.hide();
} }
}); });

View File

@@ -33,7 +33,7 @@ public class BlocksFragment implements Fragment{
private boolean shown = true; private boolean shown = true;
public void build(){ public void build(){
InputHandler input = control.getInput(); InputHandler input = control.input();
new table(){{ new table(){{
abottom(); abottom();
@@ -197,7 +197,7 @@ public class BlocksFragment implements Fragment{
} }
void updateRecipe(){ void updateRecipe(){
Recipe recipe = Vars.control.getInput().recipe; Recipe recipe = Vars.control.input().recipe;
desctable.clear(); desctable.clear();
desctable.setTouchable(Touchable.enabled); desctable.setTouchable(Touchable.enabled);
@@ -229,7 +229,7 @@ public class BlocksFragment implements Fragment{
desclabel.setWrap(true); desclabel.setWrap(true);
boolean wasPaused = GameState.is(State.paused); boolean wasPaused = GameState.is(State.paused);
GameState.set(State.paused); state.set(State.paused);
FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo"); FloatingDialog d = new FloatingDialog("$text.blocks.blockinfo");
Table table = new Table(); Table table = new Table();
@@ -264,7 +264,7 @@ public class BlocksFragment implements Fragment{
} }
d.buttons().addButton("$text.ok", ()->{ d.buttons().addButton("$text.ok", ()->{
if(!wasPaused) GameState.set(State.playing); if(!wasPaused) state.set(State.playing);
d.hide(); d.hide();
}).size(110, 50).pad(10f); }).size(110, 50).pad(10f);

View File

@@ -69,7 +69,7 @@ public class HudFragment implements Fragment{
if (Net.active() && Vars.android) { if (Net.active() && Vars.android) {
ui.listfrag.visible = !ui.listfrag.visible; ui.listfrag.visible = !ui.listfrag.visible;
} else { } else {
GameState.set(GameState.is(State.paused) ? State.playing : State.paused); state.set(GameState.is(State.paused) ? State.playing : State.paused);
} }
}).update(i -> { }).update(i -> {
if (Net.active() && Vars.android) { if (Net.active() && Vars.android) {

View File

@@ -32,7 +32,7 @@ public class PlacementFragment implements Fragment{
public void build(){ public void build(){
if(!Vars.android) return; if(!Vars.android) return;
InputHandler input = control.getInput(); InputHandler input = control.input();
float s = 50f; float s = 50f;
float translation = Unit.dp.scl(54f); float translation = Unit.dp.scl(54f);
@@ -130,7 +130,7 @@ public class PlacementFragment implements Fragment{
defaults().padBottom(-5.5f); defaults().padBottom(-5.5f);
new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> { new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
control.getInput().resetCursor(); control.input().resetCursor();
input.breakMode = mode; input.breakMode = mode;
input.lastBreakMode = mode; input.lastBreakMode = mode;
if (!mode.both){ if (!mode.both){
@@ -174,7 +174,7 @@ public class PlacementFragment implements Fragment{
if (!mode.shown || mode.delete) continue; if (!mode.shown || mode.delete) continue;
new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> { new imagebutton("icon-" + mode.name(), "toggle", 10 * 3, () -> {
control.getInput().resetCursor(); control.input().resetCursor();
input.placeMode = mode; input.placeMode = mode;
input.lastPlaceMode = mode; input.lastPlaceMode = mode;
modeText(Bundles.format("text.mode.place", mode.toString())); modeText(Bundles.format("text.mode.place", mode.toString()));

View File

@@ -20,7 +20,7 @@ public class ToolFragment implements Fragment{
public boolean confirming; public boolean confirming;
public void build(){ public void build(){
InputHandler input = control.getInput(); InputHandler input = control.input();
float isize = 14*3; float isize = 14*3;
@@ -44,7 +44,7 @@ public class ToolFragment implements Fragment{
input.placeMode.released(px, py, px2, py2); input.placeMode.released(px, py, px2, py2);
confirming = false; confirming = false;
}else{ }else{
input.placeMode.tapped(control.getInput().getBlockX(), control.getInput().getBlockY()); input.placeMode.tapped(control.input().getBlockX(), control.input().getBlockY());
} }
}); });
@@ -61,8 +61,8 @@ public class ToolFragment implements Fragment{
tools.setPosition(v.x, v.y, Align.top); tools.setPosition(v.x, v.y, Align.top);
}else{ }else{
tools.setPosition(control.getInput().getCursorX(), tools.setPosition(control.input().getCursorX(),
Gdx.graphics.getHeight() - control.getInput().getCursorY() - 15*Core.cameraScale, Align.top); Gdx.graphics.getHeight() - control.input().getCursorY() - 15*Core.cameraScale, Align.top);
} }
if(input.placeMode != PlaceMode.areaDelete){ if(input.placeMode != PlaceMode.areaDelete){

View File

@@ -127,10 +127,6 @@ public class Block{
return name; return name;
} }
public void onReset(){
}
public boolean isSolidFor(Tile tile){ public boolean isSolidFor(Tile tile){
return false; return false;
} }

View File

@@ -2,13 +2,13 @@ package io.anuke.mindustry.world;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.IntMap; import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.ObjectMap;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.enemies.Enemy; import io.anuke.mindustry.entities.enemies.Enemy;
import io.anuke.mindustry.entities.enemies.EnemyTypes; import io.anuke.mindustry.entities.enemies.EnemyTypes;
import io.anuke.mindustry.game.SpawnPoint;
import io.anuke.mindustry.world.ColorMapper.BlockPair; import io.anuke.mindustry.world.ColorMapper.BlockPair;
import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.mindustry.world.blocks.Blocks;
import io.anuke.mindustry.world.blocks.SpecialBlocks; import io.anuke.mindustry.world.blocks.SpecialBlocks;
@@ -24,12 +24,12 @@ public class WorldGenerator {
put(Blocks.blackstone, Blocks.blackrock); put(Blocks.blackstone, Blocks.blackrock);
}}; }};
/**Returns world size.*/ /**Returns the core (starting) block. Should fill spawns with the correct spawnpoints.*/
public static void generate(Pixmap pixmap, Tile[][] tiles){ public static Tile generate(Pixmap pixmap, Tile[][] tiles, Array<SpawnPoint> spawns){
boolean hasenemies = true, hascore = false;
Noise.setSeed(Vars.world.getSeed()); Noise.setSeed(Vars.world.getSeed());
Tile core = null;
for(int x = 0; x < pixmap.getWidth(); x ++){ for(int x = 0; x < pixmap.getWidth(); x ++){
for(int y = 0; y < pixmap.getHeight(); y ++){ for(int y = 0; y < pixmap.getHeight(); y ++){
Block floor = Blocks.stone; Block floor = Blocks.stone;
@@ -45,12 +45,10 @@ public class WorldGenerator {
if(block == SpecialBlocks.playerSpawn){ if(block == SpecialBlocks.playerSpawn){
block = Blocks.air; block = Blocks.air;
Vars.control.setCore(Vars.world.tile(x, y)); core = Vars.world.tile(x, y);
hascore = true;
}else if(block == SpecialBlocks.enemySpawn){ }else if(block == SpecialBlocks.enemySpawn){
block = Blocks.air; block = Blocks.air;
Vars.control.addSpawnPoint(Vars.world.tile(x, y)); spawns.add(new SpawnPoint(tiles[x][y]));
hasenemies = true;
} }
if(block == Blocks.air && Mathf.chance(0.025) && rocks.containsKey(floor)){ if(block == Blocks.air && Mathf.chance(0.025) && rocks.containsKey(floor)){
@@ -92,15 +90,7 @@ public class WorldGenerator {
} }
} }
if(!hascore){ return core;
GameState.set(State.menu);
Vars.ui.showError("[orange]Invalid map:[] this map has no core!");
}
if(!hasenemies){
GameState.set(State.menu);
Vars.ui.showError("[orange]Invalid map:[] this map has no enemy spawnpoints!");
}
} }
private static IntMap<Block> map(Object...objects){ private static IntMap<Block> map(Object...objects){