From 7bf25cc46eeea8afa33c1a41e1f24961098abc17 Mon Sep 17 00:00:00 2001 From: Anuke Date: Sat, 5 Mar 2022 22:52:20 -0500 Subject: [PATCH] Bullet mover cleanup --- core/src/mindustry/entities/Mover.java | 3 +-- core/src/mindustry/entities/comp/BulletComp.java | 15 ++++++++++++--- .../mindustry/entities/pattern/ShootHelix.java | 6 +++--- core/src/mindustry/type/Weapon.java | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/core/src/mindustry/entities/Mover.java b/core/src/mindustry/entities/Mover.java index 93e127999f..6688710ff1 100644 --- a/core/src/mindustry/entities/Mover.java +++ b/core/src/mindustry/entities/Mover.java @@ -1,9 +1,8 @@ package mindustry.entities; -import arc.math.geom.*; import mindustry.gen.*; /** Applies custom movement to a bullet. */ public interface Mover{ - float move(Bullet bullet); + void move(Bullet bullet); } diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index ac3418fe76..34624f4550 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -123,9 +123,7 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Override public void update(){ if(mover != null){ - float v = mover.move(self()) * Time.delta; - float ang = vel.angle(); - vel.add(Angles.trnsx(ang, 0f, v), Angles.trnsy(ang, 0f, v)).limit(type.speed); + mover.move(self()); } type.update(self()); @@ -140,6 +138,17 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw } } + public void moveRelative(float x, float y){ + float rot = rotation(); + this.x += Angles.trnsx(rot, x * Time.delta, y * Time.delta); + this.y += Angles.trnsy(rot, x * Time.delta, y * Time.delta); + } + + public void turn(float x, float y){ + float ang = vel.angle(); + vel.add(Angles.trnsx(ang, x * Time.delta, y * Time.delta), Angles.trnsy(ang, x * Time.delta, y * Time.delta)).limit(type.speed); + } + //copy-paste of World#raycastEach, inlined for lambda capture performance. @Override public void tileRaycast(int x1, int y1, int x2, int y2){ diff --git a/core/src/mindustry/entities/pattern/ShootHelix.java b/core/src/mindustry/entities/pattern/ShootHelix.java index 2aa10d83ea..126c90532b 100644 --- a/core/src/mindustry/entities/pattern/ShootHelix.java +++ b/core/src/mindustry/entities/pattern/ShootHelix.java @@ -3,14 +3,14 @@ package mindustry.entities.pattern; import arc.math.*; public class ShootHelix extends ShootPattern{ - //TODO: pattern is broken without a proper offset - public float scl = 2f, mag = 0.5f, offset = Mathf.PI * 1.25f; + public float scl = 2f, mag = 1.5f, offset = Mathf.PI * 1.25f; @Override public void shoot(int totalShots, BulletHandler handler){ for(int i = 0; i < shots; i++){ for(int sign : Mathf.signs){ - handler.shoot(0, 0, 0, firstShotDelay + shotDelay * i, b -> Mathf.sin(b.time + offset, scl, mag * sign)); + handler.shoot(0, 0, 0, firstShotDelay + shotDelay * i, + b -> b.moveRelative(0f, Mathf.sin(b.time + offset, 2f, mag * sign))); } } } diff --git a/core/src/mindustry/type/Weapon.java b/core/src/mindustry/type/Weapon.java index a7ab3fd233..c0f46348b5 100644 --- a/core/src/mindustry/type/Weapon.java +++ b/core/src/mindustry/type/Weapon.java @@ -374,15 +374,15 @@ public class Weapon implements Cloneable{ shoot.shoot(mount.totalShots, (xOffset, yOffset, angle, delay, mover) -> { if(delay > 0f){ - Time.run(delay, () -> setupBullet(unit, mount, xOffset, yOffset, angle, mover)); + Time.run(delay, () -> bullet(unit, mount, xOffset, yOffset, angle, mover)); }else{ - setupBullet(unit, mount, xOffset, yOffset, angle, mover); + bullet(unit, mount, xOffset, yOffset, angle, mover); } mount.totalShots ++; }); } - protected void setupBullet(Unit unit, WeaponMount mount, float xOffset, float yOffset, float angleOffset, Mover mover){ + protected void bullet(Unit unit, WeaponMount mount, float xOffset, float yOffset, float angleOffset, Mover mover){ if(!unit.isAdded()) return; float