Drownable legged units

This commit is contained in:
Anuken
2021-08-22 11:06:25 -04:00
parent 1d46fb5425
commit 4af101bf7d
8 changed files with 77 additions and 29 deletions
@@ -25,6 +25,7 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
@Import Team team;
@Import Vec2 vel;
transient Floor lastDeepFloor;
//TODO segments
transient float lastCrawlSlowdown = 1f;
transient float segmentRot, crawlTime;
@@ -55,13 +56,20 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
segmentRot = rotation;
}
@Override
@Replace
public Floor drownFloor(){
return lastDeepFloor;
}
@Override
public void update(){
if(moving()){
segmentRot = Angles.moveToward(segmentRot, rotation, type.segmentRotSpeed);
int radius = (int)Math.max(0, hitSize / tilesize);
int count = 0, solids = 0;
int count = 0, solids = 0, deeps = 0;
lastDeepFloor = null;
//calculate tiles under this unit, and apply slowdown + particle effects
for(int cx = -radius; cx <= radius; cx++){
@@ -75,6 +83,11 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
solids ++;
}
if(t.floor().isDeep()){
deeps ++;
lastDeepFloor = t.floor();
}
if(t.build != null && t.build.team != team){
t.build.damage(team, type.crawlDamage * Time.delta);
}
@@ -89,6 +102,11 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
}
}
//when most blocks under this unit cannot be drowned in, do not drown
if((float)deeps / count < 0.75f){
lastDeepFloor = null;
}
lastCrawlSlowdown = Mathf.lerp(1f, type.crawlSlowdown, Mathf.clamp((float)solids / count / type.crawlSlowdownFrac));
}
segmentRot = Angles.clampRange(segmentRot, rotation, type.segmentMaxRot);