A few more minor bugfixes; added targeting debugging

This commit is contained in:
Anuken
2017-10-03 17:06:46 -04:00
parent 3e9aca023a
commit 61dbd33f51
13 changed files with 79 additions and 34 deletions

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.anuke.mindustry" package="io.anuke.mindustry"
android:versionCode="10" android:versionCode="11"
android:versionName="2.0" > android:versionName="2.1" >
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" /> <uses-sdk android:minSdkVersion="9" android:targetSdkVersion="25" />

View File

@@ -79,7 +79,7 @@ project(":core") {
apply plugin: "java" apply plugin: "java"
dependencies { dependencies {
compile 'com.github.anuken:ucore:2a0a7a54cc' compile 'com.github.anuken:ucore:7d37e1f5d0'
compile "com.badlogicgames.gdx:gdx:$gdxVersion" compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-ai:1.8.1" compile "com.badlogicgames.gdx:gdx-ai:1.8.1"
} }

View File

@@ -352,8 +352,8 @@ public class Control extends Module{
} }
} }
if(Inputs.keyDown(Keys.Y)){ if(Inputs.keyUp(Keys.Y)){
new TestEnemy(0).set(player.x, player.y).add(); new FastEnemy(0).set(player.x, player.y).add();
} }
} }

View File

@@ -26,9 +26,9 @@ public class Mindustry extends ModuleCore {
@Override @Override
public void init(){ public void init(){
add(Vars.control = new Control()); module(Vars.control = new Control());
add(Vars.renderer = new Renderer()); module(Vars.renderer = new Renderer());
add(Vars.ui = new UI()); module(Vars.ui = new UI());
} }
@Override @Override

View File

@@ -282,7 +282,7 @@ public class Renderer extends RendererModule{
if(android && player.breaktime > 0){ if(android && player.breaktime > 0){
Vector2 vec = Graphics.world(Gdx.input.getX(0), Gdx.input.getY(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)); 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; float fract = player.breaktime / tile.block().breaktime;
Draw.color(Color.YELLOW, Color.SCARLET, fract); Draw.color(Color.YELLOW, Color.SCARLET, fract);
Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26); Draw.circle(tile.worldx(), tile.worldy(), 4 + (1f - fract) * 26);

View File

@@ -50,6 +50,7 @@ public abstract class BulletType extends BaseBulletType<Bullet>{
lifetime = 110f; lifetime = 110f;
hitsize = 8f; hitsize = 8f;
} }
public void draw(Bullet b){ public void draw(Bullet b){
float rad = 8f; float rad = 8f;
Draw.color(Color.GRAY); Draw.color(Color.GRAY);

View File

@@ -1,7 +1,6 @@
package io.anuke.mindustry.world; package io.anuke.mindustry.world;
import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.entities.TileEntity;
@@ -12,9 +11,6 @@ import io.anuke.ucore.core.Draw;
public class Block{ public class Block{
private static int lastid; private static int lastid;
private static Array<Block> blocks = new Array<Block>(); private static Array<Block> blocks = new Array<Block>();
protected static Vector2 vector = new Vector2();
protected static Vector2 vector2 = new Vector2();
protected static TextureRegion temp = new TextureRegion(); protected static TextureRegion temp = new TextureRegion();
public final String name; public final String name;

View File

@@ -40,7 +40,7 @@ public class ProductionBlocks{
}}, }},
liquidrouter = new LiquidRouter("liquidrouter"){{ liquidrouter = new LiquidRouter("liquidrouter"){{
formalName = "liquid router";
}}, }},
conveyor = new Conveyor("conveyor"){{ conveyor = new Conveyor("conveyor"){{

View File

@@ -42,11 +42,11 @@ public class WeaponBlocks{
protected void shoot(Tile tile){ protected void shoot(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
vector.set(4, -2).rotate(entity.rotation); Angles.vector.set(4, -2).rotate(entity.rotation);
bullet(tile, entity.rotation); bullet(tile, entity.rotation);
vector.set(4, 2).rotate(entity.rotation); Angles.vector.set(4, 2).rotate(entity.rotation);
bullet(tile, entity.rotation); bullet(tile, entity.rotation);
} }
}, },
@@ -77,7 +77,7 @@ public class WeaponBlocks{
for(int i = 0; i < 7; i ++) for(int i = 0; i < 7; i ++)
Timers.run(i/1.5f, ()->{ Timers.run(i/1.5f, ()->{
vector.set(4, 0).setAngle(entity.rotation); Angles.translation(entity.rotation, 4f);
bullet(tile, entity.rotation + Mathf.range(30)); bullet(tile, entity.rotation + Mathf.range(30));
}); });
} }
@@ -115,7 +115,6 @@ public class WeaponBlocks{
ammo = Item.coal; ammo = Item.coal;
ammoMultiplier = 5; ammoMultiplier = 5;
health = 110; health = 110;
overPrediction = 0.09f;
} }
}, },
@@ -159,7 +158,7 @@ public class WeaponBlocks{
inaccuracy = 7f; inaccuracy = 7f;
formalName = "plasma turret"; formalName = "plasma turret";
range = 60f; range = 60f;
reload = 2f; reload = 3f;
bullet = BulletType.plasmaflame; bullet = BulletType.plasmaflame;
ammo = Item.coal; ammo = Item.coal;
health = 180; health = 180;

View File

@@ -21,6 +21,11 @@ public class Conduit extends Block{
update = true; update = true;
} }
@Override
public String description(){
return "Transports liquids";
}
@Override @Override
public void draw(Tile tile){ public void draw(Tile tile){
ConduitEntity entity = tile.entity(); ConduitEntity entity = tile.entity();

View File

@@ -16,6 +16,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw; import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Timers; import io.anuke.ucore.core.Timers;
import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Tmp;
public class Conveyor extends Block{ public class Conveyor extends Block{
protected float speed = 0.02f; 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); (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){ for(ItemPos pos : entity.convey){
vector.set(tilesize, 0).rotate(tile.rotation * 90); Tmp.v1.set(tilesize, 0).rotate(tile.rotation * 90);
vector2.set(-tilesize / 2, pos.y*tilesize/2).rotate(tile.rotation * 90); Tmp.v2.set(-tilesize / 2, pos.y*tilesize/2).rotate(tile.rotation * 90);
Draw.rect("icon-" + pos.item.name(), Draw.rect("icon-" + pos.item.name(),
tile.x * tilesize + vector.x * pos.pos + vector2.x, tile.x * tilesize + Tmp.v1.x * pos.pos + Tmp.v2.x,
tile.y * tilesize + vector.y * pos.pos + vector2.y, 4, 4); tile.y * tilesize + Tmp.v1.y * pos.pos + Tmp.v2.y, 4, 4);
} }
} }

View File

@@ -16,6 +16,11 @@ public class LiquidRouter extends Conduit{
solid = true; solid = true;
} }
@Override
public String description(){
return "Splits input liquid into 3 directions";
}
@Override @Override
public void update(Tile tile){ public void update(Tile tile){
ConduitEntity entity = tile.entity(); ConduitEntity entity = tile.entity();

View File

@@ -1,10 +1,10 @@
package io.anuke.mindustry.world.blocks.types; package io.anuke.mindustry.world.blocks.types;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.MathUtils;
import io.anuke.mindustry.Vars; import io.anuke.mindustry.Vars;
import io.anuke.mindustry.entities.Bullet; import io.anuke.mindustry.entities.Bullet;
@@ -34,7 +34,6 @@ public class Turret extends Block{
protected int maxammo = 400; protected int maxammo = 400;
protected float rotatespeed = 0.2f; protected float rotatespeed = 0.2f;
protected float shootCone = 8f; protected float shootCone = 8f;
protected float overPrediction = 0f;
public Turret(String name) { public Turret(String name) {
super(name); super(name);
@@ -51,6 +50,10 @@ public class Turret extends Block{
public void drawOver(Tile tile){ public void drawOver(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90); Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
if(Vars.debug){
drawTargeting(tile);
}
} }
@Override @Override
@@ -70,7 +73,6 @@ public class Turret extends Block{
@Override @Override
public void drawPlace(int x, int y, boolean valid){ public void drawPlace(int x, int y, boolean valid){
//TODO?
Draw.color(Color.PURPLE); Draw.color(Color.PURPLE);
Draw.thick(1f); Draw.thick(1f);
Draw.dashcircle(x*Vars.tilesize, y*Vars.tilesize, range); Draw.dashcircle(x*Vars.tilesize, y*Vars.tilesize, range);
@@ -109,9 +111,9 @@ public class Turret extends Block{
if(entity.target != null){ if(entity.target != null){
float targetRot = Angles.predictAngle(tile.worldx(), tile.worldy(), float targetRot = Angles.predictAngle(tile.worldx(), tile.worldy(),
entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed + overPrediction); entity.target.x, entity.target.y, entity.target.xvelocity, entity.target.yvelocity, bullet.speed);
entity.rotation = MathUtils.lerpAngleDeg(entity.rotation, targetRot, entity.rotation = Mathf.slerp(entity.rotation, targetRot,
rotatespeed*Timers.delta()); rotatespeed*Timers.delta());
float reload = Vars.multiplier*this.reload; float reload = Vars.multiplier*this.reload;
@@ -129,18 +131,54 @@ public class Turret extends Block{
return new TurretEntity(); 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){ protected void shoot(Tile tile){
TurretEntity entity = tile.entity(); TurretEntity entity = tile.entity();
float inac = Mathf.range(inaccuracy); float inac = Mathf.range(inaccuracy);
vector.set(0, 4).setAngle(entity.rotation + inac); Angles.translation(entity.rotation + inac, 4f);
Bullet out = new Bullet(bullet, tile.entity, tile.worldx()+vector.x, tile.worldy()+vector.y, entity.rotation + inac).add();
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); out.damage = (int)(bullet.damage*Vars.multiplier);
} }
protected void bullet(Tile tile, float angle){ 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); out.damage = (int)(bullet.damage*Vars.multiplier);
} }