Sweeping rework

This commit is contained in:
Anuken
2019-03-31 17:49:15 -04:00
parent 6392330e70
commit de0235ad94
45 changed files with 400 additions and 370 deletions

View File

@@ -43,6 +43,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public static int sleepingEntities = 0;
public Tile tile;
public Block block;
public Interval timer;
public float health;
public float timeScale = 1f, timeScaleDuration;
@@ -76,10 +77,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
this.tile = tile;
x = tile.drawx();
y = tile.drawy();
block = tile.block();
health = tile.block().health;
timer = new Interval(tile.block().timers);
health = block.health;
timer = new Interval(block.timers);
if(shouldAdd){
add();
@@ -134,7 +135,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
}
public void collision(Bullet other){
tile.block().handleBulletHit(this, other);
block.handleBulletHit(this, other);
}
public void kill(){
@@ -146,7 +147,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
float preHealth = health;
Call.onTileDamage(tile, health - tile.block().handleDamage(tile, damage));
Call.onTileDamage(tile, health - block.handleDamage(tile, damage));
if(health <= 0){
Call.onTileDestroyed(tile);
@@ -164,9 +165,9 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
}
public void removeFromProximity(){
tile.block().onProximityRemoved(tile);
block.onProximityRemoved(tile);
Point2[] nearby = Edges.getEdges(tile.block().size);
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
//remove this tile from all nearby tile's proximities
@@ -184,7 +185,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
tmpTiles.clear();
proximity.clear();
Point2[] nearby = Edges.getEdges(tile.block().size);
Point2[] nearby = Edges.getEdges(block.size);
for(Point2 point : nearby){
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
@@ -207,8 +208,8 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
proximity.add(tile);
}
tile.block().onProximityAdded(tile);
tile.block().onProximityUpdate(tile);
block.onProximityAdded(tile);
block.onProximityUpdate(tile);
}
public Array<Tile> proximity(){
@@ -227,7 +228,7 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
@Override
public float maxHealth(){
return tile.block().health;
return block.health;
}
@Override
@@ -239,7 +240,6 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
public void onDeath(){
if(!dead){
dead = true;
Block block = tile.block();
Events.fire(new BlockDestroyEvent(tile));
block.onDestroyed(tile);
@@ -262,22 +262,22 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
@Override
public void update(){
//TODO better smoke effect, this one is awful
if(health != 0 && health < tile.block().health && !(tile.block() instanceof Wall) &&
Mathf.chance(0.009f * Time.delta() * (1f - health / tile.block().health))){
if(health != 0 && health < block.health && !(block instanceof Wall) &&
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
}
timeScaleDuration -= Time.delta();
if(timeScaleDuration <= 0f || !tile.block().canOverdrive){
if(timeScaleDuration <= 0f || !block.canOverdrive){
timeScale = 1f;
}
if(health <= 0){
onDeath();
}
Block previous = tile.block();
tile.block().update(tile);
if(tile.block() == previous && cons != null){
Block previous = block;
block.update(tile);
if(block == previous && cons != null){
cons.update();
}
}