From 4265d40024dbb05fd843e1012dac24f77106a2a9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 7 Feb 2020 13:02:24 -0500 Subject: [PATCH] Movement --- core/src/mindustry/content/UnitTypes.java | 2 +- core/src/mindustry/entities/def/LegsComp.java | 9 +++++++++ core/src/mindustry/entities/def/PlayerComp.java | 4 ++++ core/src/mindustry/entities/def/UnitComp.java | 10 ++++++++++ core/src/mindustry/input/DesktopInput.java | 5 +++-- core/src/mindustry/type/UnitDef.java | 4 ++-- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 8c9925586d..36aa6d9bed 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -22,7 +22,7 @@ public class UnitTypes implements ContentList{ dagger = new UnitDef("dagger"){{ speed = 0.2f; - drag = 0.4f; + drag = 0.2f; hitsize = 8f; mass = 1.75f; health = 130; diff --git a/core/src/mindustry/entities/def/LegsComp.java b/core/src/mindustry/entities/def/LegsComp.java index 4b5e57d886..843d437c64 100644 --- a/core/src/mindustry/entities/def/LegsComp.java +++ b/core/src/mindustry/entities/def/LegsComp.java @@ -1,5 +1,6 @@ package mindustry.entities.def; +import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.gen.*; @@ -9,6 +10,14 @@ abstract class LegsComp implements Posc, Flyingc, Hitboxc, DrawLayerGroundUnderc float baseRotation, walkTime; + @Override + public void update(){ + if(vel().len() > 0.5f){ + baseRotation = vel().angle(); + walkTime += Time.delta()*vel().len()/1f; + } + } + @Override public void drawGroundUnder(){ type().drawLegs(this); diff --git a/core/src/mindustry/entities/def/PlayerComp.java b/core/src/mindustry/entities/def/PlayerComp.java index bfcb36e0fd..d32eb50c8e 100644 --- a/core/src/mindustry/entities/def/PlayerComp.java +++ b/core/src/mindustry/entities/def/PlayerComp.java @@ -96,6 +96,10 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{ public void unit(Unitc unit){ if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead."); + if(this.unit != Nulls.unit){ + //un-control the old unit + this.unit.controller(this.unit.type().createController()); + } this.unit = unit; if(unit != Nulls.unit){ unit.team(team); diff --git a/core/src/mindustry/entities/def/UnitComp.java b/core/src/mindustry/entities/def/UnitComp.java index c8ae1ac26e..f20a23a01b 100644 --- a/core/src/mindustry/entities/def/UnitComp.java +++ b/core/src/mindustry/entities/def/UnitComp.java @@ -1,6 +1,8 @@ package mindustry.entities.def; import arc.*; +import arc.math.*; +import arc.math.geom.*; import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; @@ -71,6 +73,14 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox return type; } + public void lookAt(float angle){ + rotation = Angles.moveToward(rotation, angle, type.rotateSpeed); + } + + public void lookAt(Position pos){ + lookAt(angleTo(pos)); + } + @Override public void update(){ //apply knockback based on spawns diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 88b681b2ee..f457e4f24b 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -153,7 +153,7 @@ public class DesktopInput extends InputHandler{ } //TODO remove: debug unit possession - if(player.dead() && Core.input.keyTap(Binding.select)){ + if(Core.input.keyTap(Binding.select)){ Unitc unit = Units.closest(state.rules.defaultTeam, Core.input.mouseWorld().x, Core.input.mouseWorld().y, 40f, u -> true); if(unit != null){ unit.hitbox(Tmp.r1); @@ -501,7 +501,8 @@ public class DesktopInput extends InputHandler{ float xa = Core.input.axis(Binding.move_x); float ya = Core.input.axis(Binding.move_y); - unit.vel().add(speed * xa, speed * ya); + unit.vel().add(Tmp.v1.set(speed * xa, speed * ya).limit(speed)); + unit.lookAt(Angles.mouseAngle(unit.x(), unit.y())); /* Tile tile = unit.tileOn(); boolean canMove = !Core.scene.hasKeyboard() || ui.minimapfrag.shown(); diff --git a/core/src/mindustry/type/UnitDef.java b/core/src/mindustry/type/UnitDef.java index 97cda53b15..847c097575 100644 --- a/core/src/mindustry/type/UnitDef.java +++ b/core/src/mindustry/type/UnitDef.java @@ -28,7 +28,7 @@ public class UnitDef extends UnlockableContent{ public @NonNull Prov defaultController = AIController::new; public @NonNull Prov constructor; public boolean flying; - public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 0.2f, baseRotateSpeed = 0.1f; + public float speed = 1.1f, boostSpeed = 0.75f, rotateSpeed = 10f, baseRotateSpeed = 0.1f; public float drag = 0.3f, mass = 1f, accel = 0.1f; public float health = 200f, range = -1; public boolean targetAir = false, targetGround = false; @@ -198,7 +198,7 @@ public class UnitDef extends UnlockableContent{ public void drawLegs(Legsc unit){ Draw.mixcol(Color.white, unit.hitAlpha()); - float ft = Mathf.sin(unit.walkTime() * unit.vel().len() * 5f, 6f, 2f + unit.hitSize() / 15f); + float ft = Mathf.sin(unit.walkTime(), 6f, 2f + unit.hitSize() / 15f); Floor floor = unit.floorOn();