diff --git a/build.gradle b/build.gradle index 82190c74b5..2ad182dd72 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,7 @@ project(":core") { apply plugin: "java" dependencies { - compile 'com.github.Anuken:ucore:a1ae9be' + compile 'com.github.Anuken:ucore:dfceb01' compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-ai:1.8.1" } diff --git a/core/src/io/anuke/mindustry/Mindustry.java b/core/src/io/anuke/mindustry/Mindustry.java index 8b3f362030..8013577925 100644 --- a/core/src/io/anuke/mindustry/Mindustry.java +++ b/core/src/io/anuke/mindustry/Mindustry.java @@ -9,7 +9,6 @@ import io.anuke.mindustry.core.*; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.io.Formatter; import io.anuke.mindustry.world.Block; -import io.anuke.mindustry.world.World; import io.anuke.mindustry.world.blocks.*; import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Timers; diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index d1f0cd7aab..75f9fffaf0 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -4,11 +4,8 @@ import com.badlogic.gdx.Application.ApplicationType; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.utils.I18NBundle; -import io.anuke.mindustry.core.Control; -import io.anuke.mindustry.core.Renderer; -import io.anuke.mindustry.core.UI; +import io.anuke.mindustry.core.*; import io.anuke.mindustry.entities.Player; -import io.anuke.mindustry.world.World; import io.anuke.ucore.scene.ui.layout.Unit; public class Vars{ diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 40f43dbdbe..1a90a853e5 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -26,7 +26,6 @@ import io.anuke.mindustry.resource.Item; import io.anuke.mindustry.resource.ItemStack; import io.anuke.mindustry.resource.Weapon; import io.anuke.mindustry.world.*; -import io.anuke.mindustry.world.blocks.ProductionBlocks; import io.anuke.ucore.UCore; import io.anuke.ucore.core.*; import io.anuke.ucore.entities.Entities; @@ -179,17 +178,6 @@ public class Control extends Module{ GameState.set(State.playing); } - public void findCore(){ - for(int x = 0; x < Vars.world.width(); x ++){ - for(int y = 0; y < Vars.world.height(); y ++){ - if(world.tile(x, y).block() == ProductionBlocks.core){ - core = world.tile(x, y); - return; - } - } - } - } - public Tile getCore(){ return core; } @@ -433,6 +421,10 @@ public class Control extends Module{ wavetime = 0f; } + if(Inputs.keyUp(Keys.C)){ + GameState.set(State.playing); + } + if(Inputs.keyUp(Keys.U)){ Vars.showUI = !Vars.showUI; } diff --git a/core/src/io/anuke/mindustry/core/Renderer.java b/core/src/io/anuke/mindustry/core/Renderer.java index d93600c71e..c18ae0f841 100644 --- a/core/src/io/anuke/mindustry/core/Renderer.java +++ b/core/src/io/anuke/mindustry/core/Renderer.java @@ -99,8 +99,10 @@ public class Renderer extends RendererModule{ }else{ boolean smoothcam = Settings.getBool("smoothcam"); - if(control.core == null){ //how is this possible? apparently it is - control.findCore(); + if(control.core == null){ + ui.showGameError(); + GameState.set(State.menu); + return; } if(control.core.block() == ProductionBlocks.core){ @@ -250,9 +252,15 @@ public class Renderer extends RendererModule{ Tmp.tr2.setRegion(texture); Shaders.shield.region = Tmp.tr2; Shaders.shield.hits = shieldHits; + + if(Shaders.shield.isFallback){ + Draw.color(1f, 1f, 1f, 0.3f); + Shaders.outline.color = Color.SKY; + Shaders.outline.region = Tmp.tr2; + } Graphics.end(); - Graphics.shader(Shaders.shield); + Graphics.shader(Shaders.shield.isFallback ? Shaders.outline : Shaders.shield); Graphics.setScreen(); Core.batch.draw(texture, 0, Gdx.graphics.getHeight(), Gdx.graphics.getWidth(), -Gdx.graphics.getHeight()); @@ -260,6 +268,8 @@ public class Renderer extends RendererModule{ Graphics.shader(); Graphics.end(); Graphics.beginCam(); + + Draw.color(); } public void addShieldHit(float x, float y){ diff --git a/core/src/io/anuke/mindustry/core/UI.java b/core/src/io/anuke/mindustry/core/UI.java index 4481a56ebb..6057a492da 100644 --- a/core/src/io/anuke/mindustry/core/UI.java +++ b/core/src/io/anuke/mindustry/core/UI.java @@ -38,7 +38,7 @@ public class UI extends SceneModule{ Table loadingtable, desctable, configtable; MindustrySettingsDialog prefs; MindustryKeybindDialog keys; - Dialog about, restart, levels, upgrades, load, settingserror; + Dialog about, restart, levels, upgrades, load, settingserror, gameerror; MenuDialog menu; Tooltip tooltip; Tile configTile; @@ -162,6 +162,15 @@ public class UI extends SceneModule{ settingserror.hide(); }).size(80f, 55f).pad(4); + gameerror = new Dialog("An error has occured", "dialog"); + gameerror.content().add(new Label("[SCARLET]An unexpected error has occured, which would have caused a crash. " + + "[]Please report the exact circumstances under which this error occured to the developer: " + + "\n[ORANGE]anukendev@gmail.com[]"){{ + setWrap(true); + }}).width(600f).units(Unit.dp).pad(10f); + gameerror.buttons().addButton("OK", ()-> gameerror.hide()).size(200f, 50).units(Unit.dp); + //gameerror.setFillParent(true); + load = new LoadDialog(); upgrades = new UpgradeDialog(); @@ -298,10 +307,13 @@ public class UI extends SceneModule{ if(e instanceof Table){ ((Table)e).invalidateHierarchy(); } - } } + public void showGameError(){ + gameerror.show(); + } + public void updateWeapons(){ ((WeaponFragment)weaponfrag).updateWeapons(); } diff --git a/core/src/io/anuke/mindustry/world/World.java b/core/src/io/anuke/mindustry/core/World.java similarity index 95% rename from core/src/io/anuke/mindustry/world/World.java rename to core/src/io/anuke/mindustry/core/World.java index de5d069f8c..81bd39c401 100644 --- a/core/src/io/anuke/mindustry/world/World.java +++ b/core/src/io/anuke/mindustry/core/World.java @@ -1,4 +1,4 @@ -package io.anuke.mindustry.world; +package io.anuke.mindustry.core; import static io.anuke.mindustry.Vars.*; @@ -10,10 +10,12 @@ import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.Vars; import io.anuke.mindustry.ai.Pathfind; +import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.effect.Fx; import io.anuke.mindustry.resource.ItemStack; import io.anuke.mindustry.resource.Recipe; +import io.anuke.mindustry.world.*; import io.anuke.mindustry.world.blocks.*; import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Sounds; @@ -95,6 +97,11 @@ public class World extends Module{ } public Tile tile(int x, int y){ + if(tiles == null){ + ui.showGameError(); + GameState.set(State.menu); + return null; + } if(!Mathf.inBounds(x, y, tiles)) return null; return tiles[x][y]; } @@ -103,6 +110,10 @@ public class World extends Module{ return tile(Mathf.scl2(x, tilesize), Mathf.scl2(y, tilesize)); } + public Tile[][] getTiles(){ + return tiles; + } + public Tile[] getNearby(int x, int y){ temptiles[0] = tile(x+1, y); temptiles[1] = tile(x, y+1); @@ -179,7 +190,7 @@ public class World extends Module{ Generator.generate(mapPixmaps[map.ordinal()], tiles); //TODO multiblock core - placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0); + placeBlock(control.getCore().x, control.getCore().y, ProductionBlocks.core, 0, false); if(map != Map.tutorial){ setDefaultBlocks(); @@ -229,7 +240,7 @@ public class World extends Module{ } //TODO move to control or player? - public void placeBlock(int x, int y, Block result, int rotation){ + public void placeBlock(int x, int y, Block result, int rotation, boolean effects){ Tile tile = tile(x, y); //just in case @@ -251,15 +262,15 @@ public class World extends Module{ toplace.setLinked((byte)(dx + offsetx), (byte)(dy + offsety)); } - Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize); + if(effects) Effects.effect(Fx.place, worldx * Vars.tilesize, worldy * Vars.tilesize); } } }else{ - Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize); + if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize); } - Effects.shake(2f, 2f, player); - Sounds.play("place"); + //Effects.shake(2f, 2f, player); + if(effects) Sounds.play("place"); } //TODO move this to control? diff --git a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java index 69a456765e..783e3d6ee9 100644 --- a/core/src/io/anuke/mindustry/entities/enemies/Enemy.java +++ b/core/src/io/anuke/mindustry/entities/enemies/Enemy.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.entities.enemies; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.reflect.ClassReflection; @@ -37,6 +38,7 @@ public class Enemy extends DestructibleEntity{ protected boolean targetCore = false; protected boolean stopNearCore = true; protected float mass = 1f; + protected String className; public float idletime = 0f; public int spawn; @@ -56,6 +58,8 @@ public class Enemy extends DestructibleEntity{ maxhealth = 60; heal(); + + className = ClassReflection.getSimpleName(getClass()).toLowerCase(); } public float drawSize(){ @@ -252,7 +256,8 @@ public class Enemy extends DestructibleEntity{ @Override public void draw(){ - String region = ClassReflection.getSimpleName(getClass()).toLowerCase() + "-t" + Mathf.clamp(tier, 1, 3); + if(Timers.get(this, "asd", 30)) Gdx.app.error("ENEMY", "Currently drawing at " + x + " " + y); + String region = className + "-t" + Mathf.clamp(tier, 1, 3); Shaders.outline.color.set(tierColors[tier - 1]); Shaders.outline.region = Draw.region(region); diff --git a/core/src/io/anuke/mindustry/input/AndroidInput.java b/core/src/io/anuke/mindustry/input/AndroidInput.java index 4185afc536..a9093dafd6 100644 --- a/core/src/io/anuke/mindustry/input/AndroidInput.java +++ b/core/src/io/anuke/mindustry/input/AndroidInput.java @@ -87,7 +87,7 @@ public class AndroidInput extends InputAdapter{ if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && Vars.world.validPlace(tilex, tiley, player.recipe.result)){ - Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation); + Vars.world.placeBlock(tilex, tiley, player.recipe.result, player.rotation, true); for(ItemStack stack : player.recipe.requirements){ Vars.control.removeItem(stack); diff --git a/core/src/io/anuke/mindustry/input/Input.java b/core/src/io/anuke/mindustry/input/Input.java index b970beb563..95bd5d2910 100644 --- a/core/src/io/anuke/mindustry/input/Input.java +++ b/core/src/io/anuke/mindustry/input/Input.java @@ -56,7 +56,7 @@ public class Input{ Vars.world.validPlace(tilex(), tiley(), player.recipe.result) && !ui.hasMouse() && cursorNear() && Vars.control.hasItems(player.recipe.requirements)){ - Vars.world.placeBlock(tilex(), tiley(), player.recipe.result, player.rotation); + Vars.world.placeBlock(tilex(), tiley(), player.recipe.result, player.rotation, true); for(ItemStack stack : player.recipe.requirements){ Vars.control.removeItem(stack);