CrawlComp progress
This commit is contained in:
@@ -313,6 +313,13 @@ public class Fx{
|
||||
Lines.poly(e.x, e.y, 4, 13f * e.fout());
|
||||
}).layer(Layer.debris),
|
||||
|
||||
crawlDust = new Effect(30, e -> {
|
||||
color(Tmp.c1.set(e.color).mul(1.1f));
|
||||
randLenVectors(e.id, 2, 10f * e.finpow(), (x, y) -> {
|
||||
Fill.circle(e.x + x, e.y + y, e.fslope() * 3f + 0.3f);
|
||||
});
|
||||
}).layer(Layer.debris),
|
||||
|
||||
landShock = new Effect(12, e -> {
|
||||
color(Pal.lancerLaser);
|
||||
stroke(e.fout() * 3f);
|
||||
|
||||
@@ -2412,10 +2412,16 @@ public class UnitTypes implements ContentList{
|
||||
//region neoplasm
|
||||
|
||||
scuttler = new UnitType("scuttler"){{
|
||||
hitSize = 30f;
|
||||
hitSize = 44f;
|
||||
omniMovement = false;
|
||||
rotateSpeed = 1f;
|
||||
rotateSpeed = 2f;
|
||||
drawCell = false;
|
||||
segments = 4;
|
||||
drawBody = false;
|
||||
|
||||
segmentScl = 4f;
|
||||
segmentPhase = 5f;
|
||||
speed = 1f;
|
||||
}};
|
||||
|
||||
//endregion
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package mindustry.entities.comp;
|
||||
|
||||
import arc.math.*;
|
||||
import arc.math.geom.*;
|
||||
import mindustry.*;
|
||||
import mindustry.ai.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.content.*;
|
||||
@@ -8,18 +10,21 @@ import mindustry.entities.*;
|
||||
import mindustry.entities.EntityCollisions.*;
|
||||
import mindustry.gen.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.environment.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
|
||||
//TODO
|
||||
@Component
|
||||
abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
@Import float x, y, speedMultiplier;
|
||||
@Import float x, y, speedMultiplier, rotation, hitSize;
|
||||
@Import UnitType type;
|
||||
@Import Vec2 vel;
|
||||
|
||||
//TODO segments
|
||||
float segmentRot;
|
||||
float crawlTime;
|
||||
transient float lastCrawlSlowdown = 1f;
|
||||
transient float segmentRot, crawlTime;
|
||||
|
||||
@Replace
|
||||
@Override
|
||||
@@ -38,11 +43,49 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
public float floorSpeedMultiplier(){
|
||||
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
|
||||
//TODO take into account extra blocks
|
||||
return on.speedMultiplier * speedMultiplier;
|
||||
return on.speedMultiplier * speedMultiplier * lastCrawlSlowdown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(){
|
||||
//reset segment rotation on add
|
||||
segmentRot = rotation;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
//calculate tiles under this unit, and apply slowdown + particle effects
|
||||
for(int cx = -radius; cx <= radius; cx++){
|
||||
for(int cy = -radius; cy <= radius; cy++){
|
||||
if(cx*cx + cy*cy <= radius){
|
||||
count ++;
|
||||
Tile t = Vars.world.tileWorld(x + cx*tilesize, y + cy*tilesize);
|
||||
if(t != null){
|
||||
|
||||
if(t.solid()){
|
||||
solids ++;
|
||||
}
|
||||
|
||||
if(Mathf.chanceDelta(0.04)){
|
||||
Fx.crawlDust.at(t.worldx(), t.worldy(), t.floor().mapColor);
|
||||
}
|
||||
}else{
|
||||
solids ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lastCrawlSlowdown = Mathf.lerp(1f, type.crawlSlowdown, Mathf.clamp((float)solids / count / type.crawlSlowdownFrac));
|
||||
}
|
||||
segmentRot = Angles.clampRange(segmentRot, rotation, type.segmentMaxRot);
|
||||
|
||||
crawlTime += vel.len();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class UnitType extends UnlockableContent{
|
||||
public float itemOffsetY = 3f;
|
||||
public float lightRadius = -1f, lightOpacity = 0.6f;
|
||||
public Color lightColor = Pal.powerLight;
|
||||
public boolean drawCell = true, drawItems = true, drawShields = true;
|
||||
public boolean drawCell = true, drawItems = true, drawShields = true, drawBody = true;
|
||||
public int trailLength = 3;
|
||||
public float trailX = 4f, trailY = -3f, trailScl = 1f;
|
||||
/** Whether the unit can heal blocks. Initialized in init() */
|
||||
@@ -127,6 +127,14 @@ public class UnitType extends UnlockableContent{
|
||||
public boolean singleTarget = false;
|
||||
public boolean forceMultiTarget = false;
|
||||
|
||||
//for crawlers
|
||||
public int segments = 0;
|
||||
public float segmentSpacing = 2f;
|
||||
public float segmentScl = 4f, segmentPhase = 5f;
|
||||
public float segmentRotSpeed = 1f, segmentMaxRot = 30f;
|
||||
public float crawlSlowdown = 0.45f;
|
||||
public float crawlSlowdownFrac = 0.4f;
|
||||
|
||||
public ObjectSet<StatusEffect> immunities = new ObjectSet<>();
|
||||
public Sound deathSound = Sounds.bang;
|
||||
|
||||
@@ -134,6 +142,7 @@ public class UnitType extends UnlockableContent{
|
||||
public TextureRegion baseRegion, legRegion, region, shadowRegion, cellRegion,
|
||||
softShadowRegion, jointRegion, footRegion, legBaseRegion, baseJointRegion, outlineRegion;
|
||||
public TextureRegion[] wreckRegions;
|
||||
public TextureRegion[] segmentRegions, segmentOutlineRegions;
|
||||
|
||||
protected float buildTime = -1f;
|
||||
protected @Nullable ItemStack[] cachedRequirements;
|
||||
@@ -442,6 +451,13 @@ public class UnitType extends UnlockableContent{
|
||||
wreckRegions[i] = Core.atlas.find(name + "-wreck" + i);
|
||||
}
|
||||
|
||||
segmentRegions = new TextureRegion[segments];
|
||||
segmentOutlineRegions = new TextureRegion[segments];
|
||||
for(int i = 0; i < segments; i++){
|
||||
segmentRegions[i] = Core.atlas.find(name + "-segment" + i);
|
||||
segmentOutlineRegions[i] = Core.atlas.find(name + "-segment-outline" + i);
|
||||
}
|
||||
|
||||
clipSize = Math.max(region.width * 2f, clipSize);
|
||||
}
|
||||
|
||||
@@ -603,10 +619,14 @@ public class UnitType extends UnlockableContent{
|
||||
|
||||
Draw.z(z);
|
||||
|
||||
drawOutline(unit);
|
||||
if(unit instanceof Crawlc c){
|
||||
drawCrawl(c);
|
||||
}
|
||||
|
||||
if(drawBody) drawOutline(unit);
|
||||
drawWeaponOutlines(unit);
|
||||
if(engineSize > 0) drawEngine(unit);
|
||||
drawBody(unit);
|
||||
if(drawBody) drawBody(unit);
|
||||
if(drawCell) drawCell(unit);
|
||||
drawWeapons(unit);
|
||||
if(drawItems) drawItems(unit);
|
||||
@@ -873,6 +893,26 @@ public class UnitType extends UnlockableContent{
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
public void drawCrawl(Crawlc crawl){
|
||||
Unit unit = (Unit)crawl;
|
||||
applyColor(unit);
|
||||
|
||||
for(int p = 0; p < 2; p++){
|
||||
TextureRegion[] regions = p == 0 ? segmentOutlineRegions : segmentRegions;
|
||||
|
||||
for(int i = 0; i < segments; i++){
|
||||
float trns = Mathf.sin(crawl.crawlTime() + i * segmentPhase, segmentScl, segmentSpacing);
|
||||
|
||||
//at segment 0, rotation = segmentRot, but at the last segment it is rotation
|
||||
float rot = Mathf.slerp(crawl.segmentRot(), unit.rotation, i / (float)(segments - 1));
|
||||
float tx = Angles.trnsx(rot, trns), ty = Angles.trnsy(rot, trns);
|
||||
|
||||
//TODO merge outlines?
|
||||
Draw.rect(regions[i], unit.x + tx, unit.y + ty, rot - 90);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void drawMech(Mechc mech){
|
||||
Unit unit = (Unit)mech;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user