Fixed ClassCastException thrown on Junction use and turret prediction

This commit is contained in:
Anuken 2017-09-11 17:50:42 -04:00
parent d53f12aeb9
commit 4c860a0315
8 changed files with 35 additions and 26 deletions

View File

@ -309,6 +309,10 @@ public class Control extends RendererModule{
if(Inputs.keyDown(Keys.SPACE)){
Effects.shake(6, 4);
}
if(Inputs.keyDown(Keys.Y)){
new TestEnemy(0).set(player.x, player.y).add();
}
}
if(GameState.is(State.menu)){

View File

@ -17,7 +17,7 @@ public class Inventory{
if(debug){
items.put(Item.stone, 2000);
items.put(Item.iron, 1);
items.put(Item.iron, 2000);
items.put(Item.steel, 2000);
items.put(Item.coal, 2000);
}

View File

@ -12,6 +12,7 @@ import io.anuke.mindustry.world.Tile;
import io.anuke.ucore.core.Draw;
import io.anuke.ucore.core.Effects;
import io.anuke.ucore.entities.*;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
public class Enemy extends DestructibleEntity{
@ -122,11 +123,11 @@ public class Enemy extends DestructibleEntity{
move();
xvelocity = x - lastx;
yvelocity = y - lasty;
xvelocity = (x - lastx) / Mathf.delta();
yvelocity = (y - lasty) / Mathf.delta();
if(target == null){
direction.add(xvelocity, yvelocity);
direction.add(xvelocity * Mathf.delta(), yvelocity * Mathf.delta());
direction.limit(speed*rotatespeed);
}else{
float angle = angleTo(target);

View File

@ -0,0 +1,22 @@
package io.anuke.mindustry.entities.enemies;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timers;
public class TestEnemy extends Enemy{
boolean dir = false;
public TestEnemy(int spawn) {
super(spawn);
maxhealth = 99999;
heal();
}
void move(){
if(Timers.get(this, "asd", 300)){
dir = !dir;
}
move(dir ? -0.3f * Mathf.delta() : 0.3f * Mathf.delta(), 0);
}
}

View File

@ -31,6 +31,7 @@ public class LevelDialog extends Dialog{
hide();
Vars.ui.showLoading();
Timers.run(16, ()->{
Vars.control.reset();
World.loadMap(selectedMap);
Vars.control.play();
});

View File

@ -98,7 +98,7 @@ public class ProductionBlocks{
int dir = source.relativeTo(tile.x, tile.y);
dir = (dir+4)%4;
Tile to = tile.getNearby()[dir];
Timers.run(15, ()->{
Timers.run(10, ()->{
to.block().handleItem(to, item, tile);
});
@ -109,7 +109,7 @@ public class ProductionBlocks{
int dir = source.relativeTo(dest.x, dest.y);
dir = (dir+4)%4;
Tile to = dest.getNearby()[dir];
return to != null && to.block() != junction && to.block().accept(item, dest, to);
return to != null && to.block() != junction && to.block().accept(item, to, dest);
}
@Override

View File

@ -62,25 +62,6 @@ public class Turret extends Block{
Renderer.drawBar(Color.GREEN, tile.worldx(), tile.worldy() + 13, fract);
}
@Override
public void drawOverlay(Tile tile){
/*
TurretEntity entity = tile.entity();
if(entity.ammo <= 0 && ammo != null){
Draw.tcolor(Color.SCARLET);
Draw.tscl(1 / 8f);
//Draw.text("No ammo!", tile.worldx(), tile.worldy() + tilesize);
}else if(ammo != null){
Draw.tscl(1 / 8f);
Draw.tcolor(Color.GREEN);
//Draw.text("Ammo: " + entity.ammo, tile.worldx(), tile.worldy() - tilesize);
}
Draw.tscl(Vars.fontscale);
*/
}
@Override
public boolean accept(Item item, Tile dest, Tile source){
return item == ammo && dest.<TurretEntity>entity().ammo < maxammo;
@ -107,7 +88,7 @@ public class Turret extends Block{
if(enemy != null){
entity.rotation = MathUtils.lerpAngleDeg(entity.rotation,
Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed - 0.1f),
Angles.predictAngle(tile.worldx(), tile.worldy(), enemy.x, enemy.y, enemy.xvelocity, enemy.yvelocity, bullet.speed),
0.2f*Mathf.delta());
float reload = Vars.multiplier*this.reload;
if(Timers.get(tile, reload)){

Binary file not shown.

After

Width:  |  Height:  |  Size: 877 KiB