CrawlComp progress

This commit is contained in:
Anuken
2021-08-21 15:32:25 -04:00
parent a6c8b3a2bd
commit 7afc6d3631
11 changed files with 129 additions and 18 deletions

View File

@@ -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<mindustry.entities.units.BuildPlan>},{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<mindustry.entities.units.StatusEntry>},{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}]} {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<mindustry.entities.units.BuildPlan>},{name:rotation,type:float},{name:shield,type:float},{name:spawnedByCore,type:boolean},{name:stack,type:mindustry.type.ItemStack},{name:statuses,type:arc.struct.Seq<mindustry.entities.units.StatusEntry>},{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}]}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 866 B

View File

@@ -313,6 +313,13 @@ public class Fx{
Lines.poly(e.x, e.y, 4, 13f * e.fout()); Lines.poly(e.x, e.y, 4, 13f * e.fout());
}).layer(Layer.debris), }).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 -> { landShock = new Effect(12, e -> {
color(Pal.lancerLaser); color(Pal.lancerLaser);
stroke(e.fout() * 3f); stroke(e.fout() * 3f);

View File

@@ -2412,10 +2412,16 @@ public class UnitTypes implements ContentList{
//region neoplasm //region neoplasm
scuttler = new UnitType("scuttler"){{ scuttler = new UnitType("scuttler"){{
hitSize = 30f; hitSize = 44f;
omniMovement = false; omniMovement = false;
rotateSpeed = 1f; rotateSpeed = 2f;
drawCell = false; drawCell = false;
segments = 4;
drawBody = false;
segmentScl = 4f;
segmentPhase = 5f;
speed = 1f;
}}; }};
//endregion //endregion

View File

@@ -1,6 +1,8 @@
package mindustry.entities.comp; package mindustry.entities.comp;
import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import mindustry.*;
import mindustry.ai.*; import mindustry.ai.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.content.*; import mindustry.content.*;
@@ -8,18 +10,21 @@ import mindustry.entities.*;
import mindustry.entities.EntityCollisions.*; import mindustry.entities.EntityCollisions.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*;
import mindustry.world.blocks.environment.*; import mindustry.world.blocks.environment.*;
import static mindustry.Vars.*;
//TODO //TODO
@Component @Component
abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
@Import float x, y, speedMultiplier; @Import float x, y, speedMultiplier, rotation, hitSize;
@Import UnitType type; @Import UnitType type;
@Import Vec2 vel; @Import Vec2 vel;
//TODO segments //TODO segments
float segmentRot; transient float lastCrawlSlowdown = 1f;
float crawlTime; transient float segmentRot, crawlTime;
@Replace @Replace
@Override @Override
@@ -38,11 +43,49 @@ abstract class CrawlComp implements Posc, Rotc, Hitboxc, Unitc{
public float floorSpeedMultiplier(){ public float floorSpeedMultiplier(){
Floor on = isFlying() ? Blocks.air.asFloor() : floorOn(); Floor on = isFlying() ? Blocks.air.asFloor() : floorOn();
//TODO take into account extra blocks //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 @Override
public void update(){ 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(); crawlTime += vel.len();
} }
} }

View File

@@ -118,7 +118,7 @@ public class UnitType extends UnlockableContent{
public float itemOffsetY = 3f; public float itemOffsetY = 3f;
public float lightRadius = -1f, lightOpacity = 0.6f; public float lightRadius = -1f, lightOpacity = 0.6f;
public Color lightColor = Pal.powerLight; 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 int trailLength = 3;
public float trailX = 4f, trailY = -3f, trailScl = 1f; public float trailX = 4f, trailY = -3f, trailScl = 1f;
/** Whether the unit can heal blocks. Initialized in init() */ /** Whether the unit can heal blocks. Initialized in init() */
@@ -127,6 +127,14 @@ public class UnitType extends UnlockableContent{
public boolean singleTarget = false; public boolean singleTarget = false;
public boolean forceMultiTarget = 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 ObjectSet<StatusEffect> immunities = new ObjectSet<>();
public Sound deathSound = Sounds.bang; public Sound deathSound = Sounds.bang;
@@ -134,6 +142,7 @@ public class UnitType extends UnlockableContent{
public TextureRegion baseRegion, legRegion, region, shadowRegion, cellRegion, public TextureRegion baseRegion, legRegion, region, shadowRegion, cellRegion,
softShadowRegion, jointRegion, footRegion, legBaseRegion, baseJointRegion, outlineRegion; softShadowRegion, jointRegion, footRegion, legBaseRegion, baseJointRegion, outlineRegion;
public TextureRegion[] wreckRegions; public TextureRegion[] wreckRegions;
public TextureRegion[] segmentRegions, segmentOutlineRegions;
protected float buildTime = -1f; protected float buildTime = -1f;
protected @Nullable ItemStack[] cachedRequirements; protected @Nullable ItemStack[] cachedRequirements;
@@ -442,6 +451,13 @@ public class UnitType extends UnlockableContent{
wreckRegions[i] = Core.atlas.find(name + "-wreck" + i); 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); clipSize = Math.max(region.width * 2f, clipSize);
} }
@@ -603,10 +619,14 @@ public class UnitType extends UnlockableContent{
Draw.z(z); Draw.z(z);
drawOutline(unit); if(unit instanceof Crawlc c){
drawCrawl(c);
}
if(drawBody) drawOutline(unit);
drawWeaponOutlines(unit); drawWeaponOutlines(unit);
if(engineSize > 0) drawEngine(unit); if(engineSize > 0) drawEngine(unit);
drawBody(unit); if(drawBody) drawBody(unit);
if(drawCell) drawCell(unit); if(drawCell) drawCell(unit);
drawWeapons(unit); drawWeapons(unit);
if(drawItems) drawItems(unit); if(drawItems) drawItems(unit);
@@ -873,6 +893,26 @@ public class UnitType extends UnlockableContent{
Draw.reset(); 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){ public void drawMech(Mechc mech){
Unit unit = (Unit)mech; Unit unit = (Unit)mech;

View File

@@ -409,6 +409,7 @@ public class Generators{
ObjectSet<String> outlined = new ObjectSet<>(); ObjectSet<String> outlined = new ObjectSet<>();
try{ try{
Unit sample = type.constructor.get();
type.load(); type.load();
type.loadIcon(); type.loadIcon();
type.init(); type.init();
@@ -430,14 +431,26 @@ public class Generators{
outliner.get(type.footRegion); outliner.get(type.footRegion);
outliner.get(type.legBaseRegion); outliner.get(type.legBaseRegion);
outliner.get(type.baseJointRegion); 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"); save(image, type.name + "-outline");
//draw mech parts //draw mech parts
if(type.constructor.get() instanceof Mechc){ if(sample instanceof Mechc){
drawCenter(image, get(type.baseRegion)); drawCenter(image, get(type.baseRegion));
drawCenter(image, get(type.legRegion)); drawCenter(image, get(type.legRegion));
drawCenter(image, get(type.legRegion).flipX()); drawCenter(image, get(type.legRegion).flipX());
@@ -456,14 +469,16 @@ public class Generators{
} }
//draw base region on top to mask weapons //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(); int baseColor = Color.valueOf("ffa665").rgba();
Pixmap baseCell = get(type.cellRegion); if(type.drawCell){
Pixmap cell = new Pixmap(type.cellRegion.width, type.cellRegion.height); Pixmap baseCell = get(type.cellRegion);
cell.each((x, y) -> cell.set(x, y, Color.muli(baseCell.getRaw(x, y), baseColor))); 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){ for(Weapon weapon : type.weapons){
weapon.load(); weapon.load();