From 7a8bd82f8e088fa9374d9d1027c43d3e85892a6c Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 16 Feb 2020 13:16:18 -0500 Subject: [PATCH] Improved controls / Re-added engine sprite --- .../annotations/entity/EntityProcess.java | 6 +++- .../src/main/resources/classids.properties | 18 +++++------ core/src/mindustry/content/UnitTypes.java | 8 +++-- .../mindustry/entities/bullet/BulletType.java | 4 +-- .../entities/bullet/FlakBulletType.java | 15 +++++----- .../mindustry/entities/def/BulletComp.java | 3 +- .../mindustry/entities/def/FlyingComp.java | 25 +++++++++++++--- core/src/mindustry/entities/def/UnitComp.java | 1 + core/src/mindustry/input/DesktopInput.java | 21 +++++++++---- core/src/mindustry/type/UnitType.java | 30 +++++++++++++++---- 10 files changed, 93 insertions(+), 38 deletions(-) diff --git a/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java b/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java index a6d545df15..4b1c7c0334 100644 --- a/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java +++ b/annotations/src/main/java/mindustry/annotations/entity/EntityProcess.java @@ -487,8 +487,12 @@ public class EntityProcess extends BaseProcessor{ } } + OrderedMap res = new OrderedMap<>(); + res.putAll(map); + res.orderedKeys().sort(); + //write assigned IDs - PropertiesUtils.store(map, idProps.writer(false), "Maps entity names to IDs. Autogenerated."); + PropertiesUtils.store(res, idProps.writer(false), "Maps entity names to IDs. Autogenerated."); //build mapping class for sync IDs TypeSpec.Builder idBuilder = TypeSpec.classBuilder("EntityMapping").addModifiers(Modifier.PUBLIC) diff --git a/annotations/src/main/resources/classids.properties b/annotations/src/main/resources/classids.properties index 738ac53014..94cf6c6685 100644 --- a/annotations/src/main/resources/classids.properties +++ b/annotations/src/main/resources/classids.properties @@ -1,15 +1,15 @@ #Maps entity names to IDs. Autogenerated. -mindustry.entities.def.PuddleComp=6 -mindustry.entities.def.BulletComp=1 dagger=0 -phantom=11 -mindustry.entities.def.StandardEffectComp=7 -vanguard=9 -mindustry.entities.def.PlayerComp=5 draug=10 +mindustry.entities.def.BulletComp=1 mindustry.entities.def.DecalComp=2 -mindustry.entities.def.TileComp=8 -spirit=12 mindustry.entities.def.FireComp=3 -mindustry.entities.def.GroundEffectComp=4 \ No newline at end of file +mindustry.entities.def.GroundEffectComp=4 +mindustry.entities.def.PlayerComp=5 +mindustry.entities.def.PuddleComp=6 +mindustry.entities.def.StandardEffectComp=7 +mindustry.entities.def.TileComp=8 +phantom=11 +spirit=12 +vanguard=9 \ No newline at end of file diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 8101f081d3..128ce17266 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -59,8 +59,9 @@ public class UnitTypes implements ContentList{ draug = new UnitType("draug"){{ flying = true; drag = 0.05f; - speed = 1.5f; + speed = 2f; range = 50f; + accel = 0.2f; health = 80; mineSpeed = 0.9f; engineSize = 1.8f; @@ -71,7 +72,8 @@ public class UnitTypes implements ContentList{ spirit = new UnitType("spirit"){{ flying = true; drag = 0.05f; - speed = 1.5f; + accel = 0.2f; + speed = 2f; range = 50f; health = 100; engineSize = 1.8f; @@ -92,6 +94,8 @@ public class UnitTypes implements ContentList{ flying = true; drag = 0.05f; mass = 2f; + speed = 2f; + accel = 0.1f; speed = 1.5f; range = 70f; itemCapacity = 70; diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index e8028ce8c2..55bec8e773 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -56,8 +56,8 @@ public abstract class BulletType extends Content{ public boolean collidesTiles = true; /** Whether this bullet type collides with tiles that are of the same team. */ public boolean collidesTeam = false; - /** Whether this bullet type collides with air units. */ - public boolean collidesAir = true; + /** Whether this bullet type collides with air/ground units. */ + public boolean collidesAir = true, collidesGround = true; /** Whether this bullet types collides with anything at all. */ public boolean collides = true; /** Whether velocity is inherited from the shooter. */ diff --git a/core/src/mindustry/entities/bullet/FlakBulletType.java b/core/src/mindustry/entities/bullet/FlakBulletType.java index c933485d31..0104185290 100644 --- a/core/src/mindustry/entities/bullet/FlakBulletType.java +++ b/core/src/mindustry/entities/bullet/FlakBulletType.java @@ -1,14 +1,12 @@ package mindustry.entities.bullet; -import arc.math.geom.Rect; -import arc.util.Time; -import mindustry.content.Fx; -import mindustry.entities.Units; +import arc.util.*; +import mindustry.content.*; +import mindustry.entities.*; import mindustry.gen.*; public class FlakBulletType extends BasicBulletType{ - protected static Rect rect = new Rect(); - protected float explodeRange = 30f; + public float explodeRange = 30f; public FlakBulletType(float speed, float damage){ super(speed, damage, "shell"); @@ -17,6 +15,7 @@ public class FlakBulletType extends BasicBulletType{ hitEffect = Fx.flakExplosionBig; bulletWidth = 8f; bulletHeight = 10f; + collidesGround = false; } public FlakBulletType(){ @@ -29,8 +28,8 @@ public class FlakBulletType extends BasicBulletType{ if(b.data() instanceof Integer) return; if(b.timer(2, 6)){ - Units.nearbyEnemies(b.team(), rect.setSize(explodeRange * 2f).setCenter(b.x(), b.y()), unit -> { - if(b.data() instanceof Float) return; + Units.nearbyEnemies(b.team(), Tmp.r1.setSize(explodeRange * 2f).setCenter(b.x(), b.y()), unit -> { + if(b.data() instanceof Float || (unit.isFlying() && !collidesAir) || (unit.isGrounded() && !collidesGround)) return; if(unit.dst(b) < explodeRange){ b.data(0); diff --git a/core/src/mindustry/entities/def/BulletComp.java b/core/src/mindustry/entities/def/BulletComp.java index 8cf83d4c7d..3c2e4a346c 100644 --- a/core/src/mindustry/entities/def/BulletComp.java +++ b/core/src/mindustry/entities/def/BulletComp.java @@ -59,7 +59,8 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Replace @Override public boolean collides(Hitboxc other){ - return type.collides && (other instanceof Teamc && ((Teamc)other).team() != team()) && !(other instanceof Flyingc && ((Flyingc)other).isFlying() && !type.collidesAir); + return type.collides && (other instanceof Teamc && ((Teamc)other).team() != team()) + && !(other instanceof Flyingc && ((((Flyingc)other).isFlying() && !type.collidesAir) || (((Flyingc)other).isGrounded() && !type.collidesGround))); } @MethodPriority(100) diff --git a/core/src/mindustry/entities/def/FlyingComp.java b/core/src/mindustry/entities/def/FlyingComp.java index 8659006a61..b4cdfc87ed 100644 --- a/core/src/mindustry/entities/def/FlyingComp.java +++ b/core/src/mindustry/entities/def/FlyingComp.java @@ -12,7 +12,7 @@ import static mindustry.Vars.net; @Component abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{ - @Import float x, y; + @Import float x, y, drag; @Import Vec2 vel; float elevation; @@ -31,11 +31,24 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{ return isGrounded(); } + void wobble(){ + x += Mathf.sin(Time.time() + id() * 99, 25f, 0.05f) * Time.delta() * elevation; + y += Mathf.cos(Time.time() + id() * 99, 25f, 0.05f) * Time.delta() * elevation; + } + void moveAt(Vec2 vector){ + moveAt(vector, 1f); + } + + void moveAt(Vec2 vector, float acceleration){ Vec2 t = Tmp.v3.set(vector).scl(floorSpeedMultiplier()); //target vector - float mag = Tmp.v3.len(); - vel.x = Mathf.approach(vel.x, t.x, mag); - vel.y = Mathf.approach(vel.y, t.y, mag); + Tmp.v1.set(t).sub(vel).limit(acceleration * vector.len()); //delta vector + vel.add(Tmp.v1); + + //float mag = Tmp.v3.len() * acceleration; + //vel.lerp(t, Tmp.v3.len() * acceleration); + //vel.x = Mathf.approach(vel.x, t.x, mag); + //vel.y = Mathf.approach(vel.y, t.y, mag); } float floorSpeedMultiplier(){ @@ -47,6 +60,10 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{ public void update(){ Floor floor = floorOn(); + if(isFlying() && !net.client()){ + wobble(); + } + if(isGrounded() && floor.isLiquid){ if((splashTimer += Mathf.dst(deltaX(), deltaY())) >= 7f){ floor.walkEffect.at(x, y, 0, floor.color); diff --git a/core/src/mindustry/entities/def/UnitComp.java b/core/src/mindustry/entities/def/UnitComp.java index 651ddf2dd6..e3e48350c5 100644 --- a/core/src/mindustry/entities/def/UnitComp.java +++ b/core/src/mindustry/entities/def/UnitComp.java @@ -144,6 +144,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox @Override public void draw(){ + type.drawEngine(this); type.drawBody(this); type.drawWeapons(this); if(type.drawCell) type.drawCell(this); diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 88d9608321..50516c0dc3 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -28,6 +28,7 @@ import static mindustry.Vars.*; import static mindustry.input.PlaceMode.*; public class DesktopInput extends InputHandler{ + private Vec2 movement = new Vec2(); /** Current cursor type. */ private Cursor cursorType = SystemCursor.arrow; /** Position where the player started dragging a line. */ @@ -501,15 +502,23 @@ public class DesktopInput extends InputHandler{ float xa = Core.input.axis(Binding.move_x); float ya = Core.input.axis(Binding.move_y); - Vec2 movement = Tmp.v1.set(speed * xa, speed * ya).limit(speed); + movement.set(xa, ya).nor().scl(speed); + float mouseAngle = Angles.mouseAngle(unit.x(), unit.y()); + boolean aimCursor = omni && isShooting && unit.type().hasWeapons(); + + if(aimCursor){ + unit.lookAt(mouseAngle); + }else{ + if(!unit.vel().isZero(0.01f)) unit.lookAt(unit.vel().angle()); + } if(omni){ - unit.moveAt(movement); - unit.lookAt(Angles.mouseAngle(unit.x(), unit.y())); + unit.moveAt(movement, unit.type().accel); }else{ - if(!unit.vel().isZero(0.01f)) unit.rotation(unit.vel().angle()); - unit.moveAt(Tmp.v2.trns(unit.rotation(), movement.len())); - if(!movement.isZero()) unit.vel().rotateTo(movement.angle(), unit.type().rotateSpeed * Time.delta()); + unit.moveAt(Tmp.v2.trns(unit.rotation(), movement.len()), unit.type().accel); + if(!movement.isZero()){ + unit.vel().rotateTo(movement.angle(), unit.type().rotateSpeed * Time.delta()); + } } unit.aim(Core.input.mouseWorld()); diff --git a/core/src/mindustry/type/UnitType.java b/core/src/mindustry/type/UnitType.java index c9d5542524..9694fbef01 100644 --- a/core/src/mindustry/type/UnitType.java +++ b/core/src/mindustry/type/UnitType.java @@ -27,8 +27,8 @@ public class UnitType extends UnlockableContent{ public @NonNull Prov defaultController = AIController::new; public @NonNull Prov constructor; public boolean flying; - public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 10f, baseRotateSpeed = 10f; - public float drag = 0.3f, mass = 1f, accel = 0.1f; + public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 6f, baseRotateSpeed = 10f; + public float drag = 0.3f, mass = 1f, accel = 0.9f; public float health = 200f, range = -1; public boolean targetAir = false, targetGround = false; public boolean faceTarget = true, isCounted = true; @@ -37,7 +37,7 @@ public class UnitType extends UnlockableContent{ public int drillTier = -1; public float buildSpeed = 1f, mineSpeed = 1f; - public Color engineColor = Pal.boostTo; + public Color engineColor = Pal.engine; public float engineOffset = 5f, engineSize = 2.5f; public float hitsize = 6f; @@ -46,8 +46,6 @@ public class UnitType extends UnlockableContent{ public Color lightColor = Pal.powerLight; public boolean drawCell = true, drawItems = true; - //public ObjectSet mineables = new ObjectSet<>(); - public ObjectSet immunities = new ObjectSet<>(); public Sound deathSound = Sounds.bang; @@ -75,6 +73,10 @@ public class UnitType extends UnlockableContent{ return unit; } + public boolean hasWeapons(){ + return weapons.size > 0; + } + @Override public void displayInfo(Table table){ ContentDisplay.displayUnit(table, this); @@ -156,6 +158,24 @@ public class UnitType extends UnlockableContent{ } } + public void drawEngine(Unitc unit){ + if(!unit.isFlying()) return; + + Draw.color(engineColor); + Fill.circle( + unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset), + unit.y() + Angles.trnsy(unit.rotation() + 180, engineOffset), + (engineSize + Mathf.absin(Time.time(), 2f, engineSize / 4f) * unit.elevation()) + ); + Draw.color(Color.white); + Fill.circle( + unit.x() + Angles.trnsx(unit.rotation() + 180, engineOffset - 1f), + unit.y() + Angles.trnsy(unit.rotation() + 180, engineOffset - 1f), + (engineSize + Mathf.absin(Time.time(), 2f, engineSize / 4f)) / 2f * unit.elevation() + ); + Draw.color(); + } + public void drawWeapons(Unitc unit){ applyColor(unit);