From 61dbd33f515c8ef128dada5b474147c5b0ff4e6f Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 3 Oct 2017 17:06:46 -0400 Subject: [PATCH] A few more minor bugfixes; added targeting debugging --- android/AndroidManifest.xml | 4 +- build.gradle | 2 +- core/src/io/anuke/mindustry/Control.java | 4 +- core/src/io/anuke/mindustry/Mindustry.java | 6 +- core/src/io/anuke/mindustry/Renderer.java | 2 +- .../anuke/mindustry/entities/BulletType.java | 1 + core/src/io/anuke/mindustry/world/Block.java | 4 -- .../world/blocks/ProductionBlocks.java | 2 +- .../mindustry/world/blocks/WeaponBlocks.java | 13 ++--- .../mindustry/world/blocks/types/Conduit.java | 5 ++ .../world/blocks/types/Conveyor.java | 9 +-- .../world/blocks/types/LiquidRouter.java | 5 ++ .../mindustry/world/blocks/types/Turret.java | 56 ++++++++++++++++--- 13 files changed, 79 insertions(+), 34 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index b87b9ed31f..77d679c121 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="11" + android:versionName="2.1" > diff --git a/build.gradle b/build.gradle index c07f35ac9b..31a3a1c792 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,7 @@ project(":core") { apply plugin: "java" dependencies { - compile 'com.github.anuken:ucore:2a0a7a54cc' + compile 'com.github.anuken:ucore:7d37e1f5d0' compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx-ai:1.8.1" } diff --git a/core/src/io/anuke/mindustry/Control.java b/core/src/io/anuke/mindustry/Control.java index 6e283b8b6c..5bb71ff718 100644 --- a/core/src/io/anuke/mindustry/Control.java +++ b/core/src/io/anuke/mindustry/Control.java @@ -352,8 +352,8 @@ public class Control extends Module{ } } - if(Inputs.keyDown(Keys.Y)){ - new TestEnemy(0).set(player.x, player.y).add(); + if(Inputs.keyUp(Keys.Y)){ + new FastEnemy(0).set(player.x, player.y).add(); } } diff --git a/core/src/io/anuke/mindustry/Mindustry.java b/core/src/io/anuke/mindustry/Mindustry.java index ba9a7a05f7..50f5a0f153 100644 --- a/core/src/io/anuke/mindustry/Mindustry.java +++ b/core/src/io/anuke/mindustry/Mindustry.java @@ -26,9 +26,9 @@ public class Mindustry extends ModuleCore { @Override public void init(){ - add(Vars.control = new Control()); - add(Vars.renderer = new Renderer()); - add(Vars.ui = new UI()); + module(Vars.control = new Control()); + module(Vars.renderer = new Renderer()); + module(Vars.ui = new UI()); } @Override diff --git a/core/src/io/anuke/mindustry/Renderer.java b/core/src/io/anuke/mindustry/Renderer.java index 4ecb4b90dc..6b33582d07 100644 --- a/core/src/io/anuke/mindustry/Renderer.java +++ b/core/src/io/anuke/mindustry/Renderer.java @@ -282,7 +282,7 @@ public class Renderer extends RendererModule{ if(android && player.breaktime > 0){ Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(0)); Tile tile = World.tile(Mathf.scl2(vec.x, tilesize), Mathf.scl2(vec.y, tilesize)); - if(tile.breakable() && tile.block() != ProductionBlocks.core){ + if(tile != null && tile.breakable() && tile.block() != ProductionBlocks.core){ float fract = player.breaktime / tile.block().breaktime; Draw.color(Color.YELLOW, Color.SCARLET, fract); Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26); diff --git a/core/src/io/anuke/mindustry/entities/BulletType.java b/core/src/io/anuke/mindustry/entities/BulletType.java index 24c364168b..95f6b9db31 100644 --- a/core/src/io/anuke/mindustry/entities/BulletType.java +++ b/core/src/io/anuke/mindustry/entities/BulletType.java @@ -50,6 +50,7 @@ public abstract class BulletType extends BaseBulletType{ lifetime = 110f; hitsize = 8f; } + public void draw(Bullet b){ float rad = 8f; Draw.color(Color.GRAY); diff --git a/core/src/io/anuke/mindustry/world/Block.java b/core/src/io/anuke/mindustry/world/Block.java index 0234347db3..cf42d9b163 100644 --- a/core/src/io/anuke/mindustry/world/Block.java +++ b/core/src/io/anuke/mindustry/world/Block.java @@ -1,7 +1,6 @@ package io.anuke.mindustry.world; import com.badlogic.gdx.graphics.g2d.TextureRegion; -import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.entities.TileEntity; @@ -12,9 +11,6 @@ import io.anuke.ucore.core.Draw; public class Block{ private static int lastid; private static Array blocks = new Array(); - - protected static Vector2 vector = new Vector2(); - protected static Vector2 vector2 = new Vector2(); protected static TextureRegion temp = new TextureRegion(); public final String name; diff --git a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java index 8339e8a50d..36d2247cab 100644 --- a/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/ProductionBlocks.java @@ -40,7 +40,7 @@ public class ProductionBlocks{ }}, liquidrouter = new LiquidRouter("liquidrouter"){{ - + formalName = "liquid router"; }}, conveyor = new Conveyor("conveyor"){{ diff --git a/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java index 6d3e65cdf7..e1eb5689e2 100644 --- a/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java +++ b/core/src/io/anuke/mindustry/world/blocks/WeaponBlocks.java @@ -42,11 +42,11 @@ public class WeaponBlocks{ protected void shoot(Tile tile){ TurretEntity entity = tile.entity(); - vector.set(4, -2).rotate(entity.rotation); - bullet(tile, entity.rotation); + Angles.vector.set(4, -2).rotate(entity.rotation); + bullet(tile, entity.rotation); - vector.set(4, 2).rotate(entity.rotation); - bullet(tile, entity.rotation); + Angles.vector.set(4, 2).rotate(entity.rotation); + bullet(tile, entity.rotation); } }, @@ -77,7 +77,7 @@ public class WeaponBlocks{ for(int i = 0; i < 7; i ++) Timers.run(i/1.5f, ()->{ - vector.set(4, 0).setAngle(entity.rotation); + Angles.translation(entity.rotation, 4f); bullet(tile, entity.rotation + Mathf.range(30)); }); } @@ -115,7 +115,6 @@ public class WeaponBlocks{ ammo = Item.coal; ammoMultiplier = 5; health = 110; - overPrediction = 0.09f; } }, @@ -159,7 +158,7 @@ public class WeaponBlocks{ inaccuracy = 7f; formalName = "plasma turret"; range = 60f; - reload = 2f; + reload = 3f; bullet = BulletType.plasmaflame; ammo = Item.coal; health = 180; diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Conduit.java b/core/src/io/anuke/mindustry/world/blocks/types/Conduit.java index 2adb9ab5ba..f2d4a2c9c7 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Conduit.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Conduit.java @@ -21,6 +21,11 @@ public class Conduit extends Block{ update = true; } + @Override + public String description(){ + return "Transports liquids"; + } + @Override public void draw(Tile tile){ ConduitEntity entity = tile.entity(); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Conveyor.java b/core/src/io/anuke/mindustry/world/blocks/types/Conveyor.java index df3edb912c..ae3a2372e0 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Conveyor.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Conveyor.java @@ -16,6 +16,7 @@ import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Timers; import io.anuke.ucore.util.Mathf; +import io.anuke.ucore.util.Tmp; public class Conveyor extends Block{ protected float speed = 0.02f; @@ -38,12 +39,12 @@ public class Conveyor extends Block{ (Timers.time() % ((20 / 100f) / speed) < (10 / 100f) / speed && accept(Item.stone, tile, null) ? "" : "move"), tile.worldx(), tile.worldy(), tile.rotation * 90); for(ItemPos pos : entity.convey){ - vector.set(tilesize, 0).rotate(tile.rotation * 90); - vector2.set(-tilesize / 2, pos.y*tilesize/2).rotate(tile.rotation * 90); + Tmp.v1.set(tilesize, 0).rotate(tile.rotation * 90); + Tmp.v2.set(-tilesize / 2, pos.y*tilesize/2).rotate(tile.rotation * 90); Draw.rect("icon-" + pos.item.name(), - tile.x * tilesize + vector.x * pos.pos + vector2.x, - tile.y * tilesize + vector.y * pos.pos + vector2.y, 4, 4); + tile.x * tilesize + Tmp.v1.x * pos.pos + Tmp.v2.x, + tile.y * tilesize + Tmp.v1.y * pos.pos + Tmp.v2.y, 4, 4); } } diff --git a/core/src/io/anuke/mindustry/world/blocks/types/LiquidRouter.java b/core/src/io/anuke/mindustry/world/blocks/types/LiquidRouter.java index eae2daaa1f..2b9efc207d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/LiquidRouter.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/LiquidRouter.java @@ -16,6 +16,11 @@ public class LiquidRouter extends Conduit{ solid = true; } + @Override + public String description(){ + return "Splits input liquid into 3 directions"; + } + @Override public void update(Tile tile){ ConduitEntity entity = tile.entity(); diff --git a/core/src/io/anuke/mindustry/world/blocks/types/Turret.java b/core/src/io/anuke/mindustry/world/blocks/types/Turret.java index 18ce6414a9..48cbea34d1 100644 --- a/core/src/io/anuke/mindustry/world/blocks/types/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/types/Turret.java @@ -1,10 +1,10 @@ package io.anuke.mindustry.world.blocks.types; + import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import com.badlogic.gdx.graphics.Color; -import com.badlogic.gdx.math.MathUtils; import io.anuke.mindustry.Vars; import io.anuke.mindustry.entities.Bullet; @@ -34,7 +34,6 @@ public class Turret extends Block{ protected int maxammo = 400; protected float rotatespeed = 0.2f; protected float shootCone = 8f; - protected float overPrediction = 0f; public Turret(String name) { super(name); @@ -51,6 +50,10 @@ public class Turret extends Block{ public void drawOver(Tile tile){ TurretEntity entity = tile.entity(); Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90); + + if(Vars.debug){ + drawTargeting(tile); + } } @Override @@ -70,7 +73,6 @@ public class Turret extends Block{ @Override public void drawPlace(int x, int y, boolean valid){ - //TODO? Draw.color(Color.PURPLE); Draw.thick(1f); Draw.dashcircle(x*Vars.tilesize, y*Vars.tilesize, range); @@ -109,9 +111,9 @@ public class Turret extends Block{ if(entity.target != null){ float targetRot = Angles.predictAngle(tile.worldx(), tile.worldy(), - entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed + overPrediction); - - entity.rotation = MathUtils.lerpAngleDeg(entity.rotation, targetRot, + entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed); + + entity.rotation = Mathf.slerp(entity.rotation, targetRot, rotatespeed*Timers.delta()); float reload = Vars.multiplier*this.reload; @@ -129,18 +131,54 @@ public class Turret extends Block{ return new TurretEntity(); } + void drawTargeting(Tile tile){ + TurretEntity entity = tile.entity(); + + if(entity.target == null) return; + + float dst = entity.distanceTo(entity.target); + float hittime = dst / bullet.speed; + + float angle = Angles.predictAngle(tile.worldx(), tile.worldy(), + entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed); + + float predictX = entity.target.x + entity.target.xvelocity * hittime, + predictY = entity.target.y + entity.target.yvelocity * hittime; + + Draw.color(Color.GREEN); + Draw.line(tile.worldx(), tile.worldy(), entity.target.x, entity.target.y); + + Draw.color(Color.RED); + Draw.line(tile.worldx(), tile.worldy(), entity.target.x + entity.target.xvelocity * hittime, + entity.target.y + entity.target.yvelocity * hittime); + + Draw.color(Color.PURPLE); + Draw.thick(2f); + Draw.lineAngle(tile.worldx(), tile.worldy(), angle, 7f); + + Draw.reset(); + + if(Timers.getTime(tile, "reload") <= 0){ + Timers.run(hittime, ()->{ + Effects.effect("spawn", predictX, predictY); + }); + } + } + protected void shoot(Tile tile){ TurretEntity entity = tile.entity(); float inac = Mathf.range(inaccuracy); - vector.set(0, 4).setAngle(entity.rotation + inac); - Bullet out = new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, entity.rotation + inac).add(); + Angles.translation(entity.rotation + inac, 4f); + + Bullet out = new Bullet(bullet, tile.entity, + tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), entity.rotation + inac).add(); out.damage = (int)(bullet.damage*Vars.multiplier); } protected void bullet(Tile tile, float angle){ - Bullet out = new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, angle).add(); + Bullet out = new Bullet(bullet, tile.entity, tile.worldx() + Angles.x(), tile.worldy() + Angles.y(), angle).add(); out.damage = (int)(bullet.damage*Vars.multiplier); }