Minor optimization / Fixed bullets piercing shield randomly

This commit is contained in:
Anuken
2018-09-04 19:45:41 -04:00
parent baa7cb3a10
commit ae6d2fb363
7 changed files with 31 additions and 19 deletions

View File

@@ -342,7 +342,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
float x = snappedX(), y = snappedY(); float x = snappedX(), y = snappedY();
Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf()*5f, 1f - healthf())); Draw.color(Color.BLACK, team.color, healthf() + Mathf.absin(Timers.time(), healthf()*5f, 1f - healthf()));
Draw.alpha(hitTime); Draw.alpha(hitTime / hitDuration);
Draw.rect(getPowerCellRegion(), x, y, rotation - 90); Draw.rect(getPowerCellRegion(), x, y, rotation - 90);
Draw.color(); Draw.color();
} }
@@ -433,7 +433,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
@Override @Override
public void update(){ public void update(){
hitTime = Math.max(0f, hitTime - Timers.delta()); hitTime -= Timers.delta();
if(Float.isNaN(x) || Float.isNaN(y)){ if(Float.isNaN(x) || Float.isNaN(y)){
TileEntity core = getClosestCore(); TileEntity core = getClosestCore();

View File

@@ -238,7 +238,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
} }
} }
if(onLiquid && velocity.len() > 0.4f && Timers.get(this, "flooreffect", 14 - (velocity.len() * floor.speedMultiplier) * 2f)){ if(onLiquid && velocity.len() > 0.4f && Mathf.chance((velocity.len() * floor.speedMultiplier) * 0.06f * Timers.delta())){
Effects.effect(floor.walkEffect, floor.liquidColor, x, y); Effects.effect(floor.walkEffect, floor.liquidColor, x, y);
} }
@@ -250,7 +250,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
if(onLiquid && floor.drownTime > 0){ if(onLiquid && floor.drownTime > 0){
drownTime += Timers.delta() * 1f / floor.drownTime; drownTime += Timers.delta() * 1f / floor.drownTime;
if(Timers.get(this, "drowneffect", 15)){ if(Mathf.chance(Timers.delta() * 0.05f)){
Effects.effect(floor.drownUpdateEffect, floor.liquidColor, x, y); Effects.effect(floor.drownUpdateEffect, floor.liquidColor, x, y);
} }
}else{ }else{
@@ -278,7 +278,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ
} }
public void damagePeriodic(float amount){ public void damagePeriodic(float amount){
damage(amount * Timers.delta(), Timers.get(this, "damageeffect", 20)); damage(amount * Timers.delta(), hitTime <= -20 + hitDuration);
} }
public void damage(float amount, boolean withEffect){ public void damage(float amount, boolean withEffect){

View File

@@ -30,7 +30,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
public Timer timer = new Timer(3); public Timer timer = new Timer(3);
private Team team; private Team team;
private Object data; private Object data;
private boolean supressCollision; private boolean supressCollision, supressOnce, initialized;
/**Internal use only!*/ /**Internal use only!*/
public Bullet(){ public Bullet(){
@@ -91,8 +91,14 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
return type.collidesTiles; return type.collidesTiles;
} }
public void supressCollision(){ public void supress(){
supressCollision = true; supressCollision = true;
supressOnce = true;
}
public void absorb(){
supressCollision = true;
remove();
} }
public void resetOwner(Entity entity, Team team){ public void resetOwner(Entity entity, Team team){
@@ -181,7 +187,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
public void update(){ public void update(){
super.update(); super.update();
if(type.hitTiles && collidesTiles() && !supressCollision){ if(type.hitTiles && collidesTiles() && !supressCollision && !initialized){
world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> { world.raycastEach(world.toTile(lastPosition().x), world.toTile(lastPosition().y), world.toTile(x), world.toTile(y), (x, y) -> {
Tile tile = world.tile(x, y); Tile tile = world.tile(x, y);
@@ -205,7 +211,12 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
}); });
} }
supressCollision = false; if(supressOnce){
supressCollision = false;
supressOnce = false;
}
initialized = true;
} }
@Override @Override
@@ -222,6 +233,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
timer.clear(); timer.clear();
team = null; team = null;
data = null; data = null;
initialized = false;
} }
@Override @Override

View File

@@ -51,6 +51,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
private int loadedPosition = -1; private int loadedPosition = -1;
private float updateTime; private float updateTime;
private float lastRipple;
private Tile tile; private Tile tile;
private Liquid liquid; private Liquid liquid;
private float amount, targetAmount; private float amount, targetAmount;
@@ -89,9 +90,12 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
reactPuddle(tile.floor().liquidDrop, liquid, amount, tile, reactPuddle(tile.floor().liquidDrop, liquid, amount, tile,
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f); (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
if(generation == 0 && Timers.get(tile, "ripple", 50)){ Puddle p = map.get(tile.packedPosition());
if(generation == 0 && p != null && p.lastRipple <= Timers.time() - 40f){
Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color, Effects.effect(BlockFx.ripple, tile.floor().liquidDrop.color,
(tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f); (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
p.lastRipple = Timers.time();
} }
return; return;
} }
@@ -111,8 +115,9 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
}else if(p.liquid == liquid){ }else if(p.liquid == liquid){
p.accepting = Math.max(amount, p.accepting); p.accepting = Math.max(amount, p.accepting);
if(generation == 0 && Timers.get(p, "ripple2", 50) && p.amount >= maxLiquid / 2f){ if(generation == 0 && p.lastRipple <= Timers.time() - 40f && p.amount >= maxLiquid / 2f){
Effects.effect(BlockFx.ripple, p.liquid.color, (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f); Effects.effect(BlockFx.ripple, p.liquid.color, (tile.worldx() + source.worldx()) / 2f, (tile.worldy() + source.worldy()) / 2f);
p.lastRipple = Timers.time();
} }
}else{ }else{
p.amount -= reactPuddle(p.liquid, liquid, amount, p.tile, p.x, p.y); p.amount -= reactPuddle(p.liquid, liquid, amount, p.tile, p.x, p.y);

View File

@@ -284,11 +284,7 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
@Override @Override
public void update(){ public void update(){
if(hitTime > 0){ hitTime -= Timers.delta();
hitTime -= Timers.delta();
}
if(hitTime < 0) hitTime = 0;
if(isDead()){ if(isDead()){
updateRespawning(); updateRespawning();

View File

@@ -70,7 +70,7 @@ public class DeflectorWall extends Wall{
bullet.updateVelocity(0f); bullet.updateVelocity(0f);
bullet.resetOwner(entity, Team.none); bullet.resetOwner(entity, Team.none);
bullet.scaleTime(1f); bullet.scaleTime(1f);
bullet.supressCollision(); bullet.supress();
((DeflectorEntity) entity).hit = 1f; ((DeflectorEntity) entity).hit = 1f;
} }

View File

@@ -187,8 +187,7 @@ public class CoreBlock extends StorageBlock{
if(bullet.getOwner() instanceof Player && bullet.getTeam() != tile.getTeam()){ if(bullet.getOwner() instanceof Player && bullet.getTeam() != tile.getTeam()){
Effects.effect(BulletFx.absorb, bullet); Effects.effect(BulletFx.absorb, bullet);
entity.shieldHeat = 1f; entity.shieldHeat = 1f;
bullet.supressCollision(); bullet.absorb();
bullet.remove();
} }
}); });