Eruptor legs

This commit is contained in:
Anuken
2020-06-07 11:15:25 -04:00
parent fb9670d0ad
commit 9574f742e1
10 changed files with 619 additions and 557 deletions

View File

@@ -14,7 +14,7 @@ import mindustry.type.*;
public class UnitTypes implements ContentList{
//ground
public static @EntityDef({Unitc.class, Mechc.class}) UnitType titan, dagger, crawler, fortress, eruptor, chaosArray, eradicator;
public static @EntityDef({Unitc.class, Mechc.class}) UnitType titan, dagger, crawler, fortress, chaosArray, eradicator;
//ground + builder
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class}) UnitType tau;
@@ -23,7 +23,7 @@ public class UnitTypes implements ContentList{
public static @EntityDef({Unitc.class, Mechc.class, Builderc.class, Minerc.class, Commanderc.class}) UnitType oculon;
//legs
public static @EntityDef({Unitc.class, Legsc.class}) UnitType cix;
public static @EntityDef({Unitc.class, Legsc.class}) UnitType cix, eruptor;
//air
public static @EntityDef({Unitc.class}) UnitType wraith, reaper, ghoul, revenant, lich;
@@ -233,6 +233,11 @@ public class UnitTypes implements ContentList{
targetAir = false;
health = 600;
immunities = ObjectSet.with(StatusEffects.burning, StatusEffects.melting);
legCount = 4;
legLength = 9f;
legTrns = 2f;
legMoveSpace = 1.4f;
weapons.add(new Weapon("eruption"){{
shootY = 3f;
reload = 10f;
@@ -303,7 +308,6 @@ public class UnitTypes implements ContentList{
drag = 0.016f;
flying = true;
range = 140f;
//rotateShooting = false;
hitsize = 18f;
lowAltitude = true;

View File

@@ -18,15 +18,22 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
transient Leg[] legs = {};
transient float totalLength;
transient int lastGroup;
transient float baseRotation;
@Override
public void update(){
//keep elevation halfway
elevation = 0.5f;
elevation = 0.4f;
if(Mathf.dst(deltaX(), deltaY()) > 0.001f){
baseRotation = Mathf.slerpDelta(baseRotation, Mathf.angle(deltaX(), deltaY()), 0.1f);
}
Log.info(baseRotation);
float rot = baseRotation;
int count = type.legCount;
float legLength = type.legLength;
float rotation = vel().angle();
//set up initial leg positions
if(legs.length != type.legCount){
@@ -37,8 +44,8 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
for(int i = 0; i < legs.length; i++){
Leg l = new Leg();
l.joint.trns(i * spacing + rotation, legLength/2f).add(x, y);
l.base.trns(i * spacing + rotation, legLength).add(x, y);
l.joint.trns(i * spacing + rot, legLength/2f + type.legBaseOffset).add(x, y);
l.base.trns(i * spacing + rot, legLength + type.legBaseOffset).add(x, y);
legs[i] = l;
}
@@ -46,7 +53,7 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
float moveSpeed = type.legSpeed;
int div = Math.max(legs.length / 2, 2);
float moveSpace = legLength / 1.6f / (div / 2f);
float moveSpace = legLength / 1.6f / (div / 2f) * type.legMoveSpace;
totalLength += Mathf.dst(deltaX(), deltaY());
@@ -78,16 +85,19 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
float movespace = 360f / legs.length / 4f;
float trns = vel().len() * 12.5f * div/1.5f * type.legTrns;
Tmp.v4.trns(rotation, trns);
//rotation + offset vector
Tmp.v4.trns(rot, trns);
for(int i = 0; i < legs.length; i++){
float dstRot = rotation + 360f / legs.length * i + (360f / legs.length / 2f);
float rot2 = Angles.moveToward(dstRot, rotation + (Angles.angleDist(dstRot, rotation) < 90f ? 180f : 0), movespace);
float dstRot = legAngle(rot, i);
float rot2 = Angles.moveToward(dstRot, rot + (Angles.angleDist(dstRot, rot) < 90f ? 180f : 0), movespace);
Leg l = legs[i];
Tmp.v1.trns(dstRot, legLength).add(x, y).add(Tmp.v4);
Tmp.v2.trns(rot2, legLength / 2f).add(x, y).add(Tmp.v4);
//leg destination
Tmp.v1.trns(dstRot, legLength + type.legBaseOffset).add(x, y).add(Tmp.v4);
//join destination
Tmp.v2.trns(rot2, legLength / 2f + type.legBaseOffset).add(x, y).add(Tmp.v4);
if(i % div == group){
l.base.lerpDelta(Tmp.v1, moveSpeed);
@@ -98,8 +108,24 @@ abstract class LegsComp implements Posc, Rotc, Hitboxc, Flyingc, Unitc{
}
}
/** @return outwards facing angle of leg at the specified index. */
float legAngle(float rotation, int index){
return rotation + 360f / legs.length * index + (360f / legs.length / 2f);
}
@Override
public void add(){
elevation = 0.5f;
elevation = 0.4f;
}
/*
@Replace
public boolean isGrounded(){
return true;
}
@Replace
public boolean isFlying(){
return false;
}*/
}

View File

@@ -43,7 +43,7 @@ public class UnitType extends UnlockableContent{
public int commandLimit = 24;
public int legCount = 4;
public float legLength = 24f, legSpeed = 0.1f, legTrns = 1f;
public float legLength = 24f, legSpeed = 0.1f, legTrns = 1f, legBaseOffset = 0f, legMoveSpace = 1f;
public int itemCapacity = 30;
public int drillTier = -1;
@@ -331,30 +331,41 @@ public class UnitType extends UnlockableContent{
}
public void drawLegs(Legsc unit){
Draw.z(Layer.groundUnit - 0.02f);
Leg[] legs = unit.legs();
float ssize = footRegion.getWidth() * Draw.scl * 1.5f;
float rotation = unit.baseRotation();
for(Leg leg : legs){
Drawf.shadow(leg.base.x, leg.base.y, ssize);
}
//TODO should be below/above legs
if(baseRegion.found()){
Draw.rect(baseRegion, unit.x(), unit.y(), rotation);
}
int index = 0;
//TODO figure out layering
for(Leg leg : legs){
float angle = unit.legAngle(rotation, index);
boolean flip = index++ >= legs.length/2f;
int flips = Mathf.sign(flip);
Vec2 position = legOffset.trns(angle, legBaseOffset).add(unit);
Draw.color();
Lines.stroke(legRegion.getHeight() * Draw.scl * flips);
Lines.line(legRegion, unit.x(), unit.y(), leg.joint.x, leg.joint.y, CapStyle.none, 0);
Lines.line(legRegion, position.x, position.y, leg.joint.x, leg.joint.y, CapStyle.none, 0);
Lines.stroke(legBaseRegion.getHeight() * Draw.scl * flips);
Lines.line(legBaseRegion, leg.joint.x, leg.joint.y, leg.base.x, leg.base.y, CapStyle.none, 0);
float angle1 = unit.angleTo(leg.joint), angle2 = unit.angleTo(leg.base);
float angle2 = position.angleTo(leg.base);
Draw.rect(jointRegion, leg.joint.x, leg.joint.y);
Draw.rect(footRegion, leg.base.x, leg.base.y, angle2);