diff --git a/annotations/src/main/resources/revisions/scuttler/0.json b/annotations/src/main/resources/revisions/scuttler/0.json index d6d95c813a..7f2885cdcf 100644 --- a/annotations/src/main/resources/revisions/scuttler/0.json +++ b/annotations/src/main/resources/revisions/scuttler/0.json @@ -1 +1 @@ -{fields:[{name:ammo,type:float},{name:controller,type:mindustry.entities.units.UnitController},{name:crawlTime,type:float},{name:elevation,type:float},{name:flag,type:double},{name:health,type:float},{name:isShooting,type:boolean},{name:mineTile,type:mindustry.world.Tile},{name:mounts,type:"mindustry.entities.units.WeaponMount[]"},{name:plans,type:arc.struct.Queue},{name:rotation,type:float},{name:segmentRot,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq},{name:team,type:mindustry.game.Team},{name:type,type:mindustry.type.UnitType},{name:updateBuilding,type:boolean},{name:vel,type:arc.math.geom.Vec2},{name:x,type:float},{name:y,type:float}]} \ No newline at end of file +{fields:[{name:ammo,type:float},{name:controller,type:mindustry.entities.units.UnitController},{name:elevation,type:float},{name:flag,type:double},{name:health,type:float},{name:isShooting,type:boolean},{name:mineTile,type:mindustry.world.Tile},{name:mounts,type:"mindustry.entities.units.WeaponMount[]"},{name:plans,type:arc.struct.Queue},{name:rotation,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq},{name:team,type:mindustry.game.Team},{name:type,type:mindustry.type.UnitType},{name:updateBuilding,type:boolean},{name:vel,type:arc.math.geom.Vec2},{name:x,type:float},{name:y,type:float}]} \ No newline at end of file diff --git a/core/assets-raw/sprites/units/neoplasm/scuttler-segment0.png b/core/assets-raw/sprites/units/neoplasm/scuttler-segment0.png new file mode 100644 index 0000000000..e9c533963f Binary files /dev/null and b/core/assets-raw/sprites/units/neoplasm/scuttler-segment0.png differ diff --git a/core/assets-raw/sprites/units/neoplasm/scuttler-segment1.png b/core/assets-raw/sprites/units/neoplasm/scuttler-segment1.png new file mode 100644 index 0000000000..6870a618e2 Binary files /dev/null and b/core/assets-raw/sprites/units/neoplasm/scuttler-segment1.png differ diff --git a/core/assets-raw/sprites/units/neoplasm/scuttler-segment2.png b/core/assets-raw/sprites/units/neoplasm/scuttler-segment2.png new file mode 100644 index 0000000000..834ca5aaef Binary files /dev/null and b/core/assets-raw/sprites/units/neoplasm/scuttler-segment2.png differ diff --git a/core/assets-raw/sprites/units/neoplasm/scuttler-segment3.png b/core/assets-raw/sprites/units/neoplasm/scuttler-segment3.png new file mode 100644 index 0000000000..cb92fc0a35 Binary files /dev/null and b/core/assets-raw/sprites/units/neoplasm/scuttler-segment3.png differ diff --git a/core/assets-raw/sprites/units/scuttler.png b/core/assets-raw/sprites/units/scuttler.png deleted file mode 100644 index f281d6d03d..0000000000 Binary files a/core/assets-raw/sprites/units/scuttler.png and /dev/null differ diff --git a/core/src/mindustry/content/Fx.java b/core/src/mindustry/content/Fx.java index f664dc42ac..ff1904b857 100644 --- a/core/src/mindustry/content/Fx.java +++ b/core/src/mindustry/content/Fx.java @@ -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); diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index a04625ae13..c3a2da5080 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -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 diff --git a/core/src/mindustry/entities/comp/CrawlComp.java b/core/src/mindustry/entities/comp/CrawlComp.java index f14c0c7519..780f40ea6a 100644 --- a/core/src/mindustry/entities/comp/CrawlComp.java +++ b/core/src/mindustry/entities/comp/CrawlComp.java @@ -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(); } } diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index dc4312a2fa..f89cb44459 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -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 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; diff --git a/tools/src/mindustry/tools/Generators.java b/tools/src/mindustry/tools/Generators.java index 416656cd33..084a785fa3 100644 --- a/tools/src/mindustry/tools/Generators.java +++ b/tools/src/mindustry/tools/Generators.java @@ -409,6 +409,7 @@ public class Generators{ ObjectSet outlined = new ObjectSet<>(); try{ + Unit sample = type.constructor.get(); type.load(); type.loadIcon(); type.init(); @@ -430,14 +431,26 @@ public class Generators{ outliner.get(type.footRegion); outliner.get(type.legBaseRegion); outliner.get(type.baseJointRegion); - if(type.constructor.get() instanceof Legsc) outliner.get(type.legRegion); + if(sample instanceof Legsc) outliner.get(type.legRegion); - Pixmap image = outline.get(get(type.region)); + Pixmap image = type.segments > 0 ? get(type.segmentRegions[0]) : outline.get(get(type.region)); + + //draw each extra segment on top before it is saved as outline + if(sample instanceof Crawlc){ + for(int i = 0; i < type.segments; i++){ + save(outline.get(get(type.segmentRegions[i])), type.name + "-segment-outline" + i); + + if(i > 0){ + drawCenter(image, get(type.segmentRegions[i])); + } + } + save(image, type.name); + } save(image, type.name + "-outline"); //draw mech parts - if(type.constructor.get() instanceof Mechc){ + if(sample instanceof Mechc){ drawCenter(image, get(type.baseRegion)); drawCenter(image, get(type.legRegion)); drawCenter(image, get(type.legRegion).flipX()); @@ -456,14 +469,16 @@ public class Generators{ } //draw base region on top to mask weapons - image.draw(get(type.region), true); + if(type.drawBody) image.draw(get(type.region), true); int baseColor = Color.valueOf("ffa665").rgba(); - Pixmap baseCell = get(type.cellRegion); - Pixmap cell = new Pixmap(type.cellRegion.width, type.cellRegion.height); - cell.each((x, y) -> cell.set(x, y, Color.muli(baseCell.getRaw(x, y), baseColor))); + if(type.drawCell){ + Pixmap baseCell = get(type.cellRegion); + Pixmap cell = new Pixmap(type.cellRegion.width, type.cellRegion.height); + cell.each((x, y) -> cell.set(x, y, Color.muli(baseCell.getRaw(x, y), baseColor))); - image.draw(cell, image.width / 2 - cell.width / 2, image.height / 2 - cell.height / 2, true); + image.draw(cell, image.width / 2 - cell.width / 2, image.height / 2 - cell.height / 2, true); + } for(Weapon weapon : type.weapons){ weapon.load();