From 1bbb52877f5e54f6b1f1450003131024ce4b54f6 Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 4 Jun 2021 08:53:39 -0400 Subject: [PATCH] Let bullets have speed = 0 --- .../main/resources/revisions/BulletComp/1.json | 1 + .../mindustry/entities/bullet/BulletType.java | 4 ++-- .../bullet/ContinuousLaserBulletType.java | 3 ++- .../entities/bullet/LaserBulletType.java | 3 ++- .../entities/bullet/LightningBulletType.java | 4 ++-- .../entities/bullet/RailBulletType.java | 4 ++-- .../src/mindustry/entities/comp/BulletComp.java | 17 ++++++++++++----- 7 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 annotations/src/main/resources/revisions/BulletComp/1.json diff --git a/annotations/src/main/resources/revisions/BulletComp/1.json b/annotations/src/main/resources/revisions/BulletComp/1.json new file mode 100644 index 0000000000..59ace7faf8 --- /dev/null +++ b/annotations/src/main/resources/revisions/BulletComp/1.json @@ -0,0 +1 @@ +{version:1,fields:[{name:collided,type:arc.struct.IntSeq},{name:damage,type:float},{name:data,type:java.lang.Object},{name:fdata,type:float},{name:lifetime,type:float},{name:owner,type:mindustry.gen.Entityc},{name:rotation,type:float},{name:team,type:mindustry.game.Team},{name:time,type:float},{name:type,type:mindustry.entities.bullet.BulletType},{name:x,type:float},{name:y,type:float}]} \ No newline at end of file diff --git a/core/src/mindustry/entities/bullet/BulletType.java b/core/src/mindustry/entities/bullet/BulletType.java index 40a09a37f3..9509424f12 100644 --- a/core/src/mindustry/entities/bullet/BulletType.java +++ b/core/src/mindustry/entities/bullet/BulletType.java @@ -445,7 +445,7 @@ public class BulletType extends Content implements Cloneable{ bullet.owner = owner; bullet.team = team; bullet.time = 0f; - bullet.vel.trns(angle, speed * velocityScl); + bullet.initVel(angle, speed * velocityScl); if(backMove){ bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta); }else{ @@ -462,7 +462,7 @@ public class BulletType extends Content implements Cloneable{ } bullet.add(); - if(keepVelocity && owner instanceof Velc v) bullet.vel.add(v.vel().x, v.vel().y); + if(keepVelocity && owner instanceof Velc v) bullet.vel.add(v.vel()); return bullet; } diff --git a/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java b/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java index f1c57dcee8..27d5043ba5 100644 --- a/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java +++ b/core/src/mindustry/entities/bullet/ContinuousLaserBulletType.java @@ -23,7 +23,8 @@ public class ContinuousLaserBulletType extends BulletType{ public boolean largeHit = true; public ContinuousLaserBulletType(float damage){ - super(0.001f, damage); + this.damage = damage; + this.speed = 0f; hitEffect = Fx.hitBeam; despawnEffect = Fx.none; diff --git a/core/src/mindustry/entities/bullet/LaserBulletType.java b/core/src/mindustry/entities/bullet/LaserBulletType.java index 0961a91e8c..0ddb733712 100644 --- a/core/src/mindustry/entities/bullet/LaserBulletType.java +++ b/core/src/mindustry/entities/bullet/LaserBulletType.java @@ -21,7 +21,8 @@ public class LaserBulletType extends BulletType{ public boolean largeHit = false; public LaserBulletType(float damage){ - super(0.01f, damage); + this.damage = damage; + this.speed = 0f; hitEffect = Fx.hitLaserBlast; hitColor = colors[2]; diff --git a/core/src/mindustry/entities/bullet/LightningBulletType.java b/core/src/mindustry/entities/bullet/LightningBulletType.java index 578f055bae..0f97bbf132 100644 --- a/core/src/mindustry/entities/bullet/LightningBulletType.java +++ b/core/src/mindustry/entities/bullet/LightningBulletType.java @@ -12,8 +12,8 @@ public class LightningBulletType extends BulletType{ public int lightningLength = 25, lightningLengthRand = 0; public LightningBulletType(){ - super(0.0001f, 1f); - + damage = 1f; + speed = 0f; lifetime = 1; despawnEffect = Fx.none; hitEffect = Fx.hitLancer; diff --git a/core/src/mindustry/entities/bullet/RailBulletType.java b/core/src/mindustry/entities/bullet/RailBulletType.java index 5f02386115..f10b221c8f 100644 --- a/core/src/mindustry/entities/bullet/RailBulletType.java +++ b/core/src/mindustry/entities/bullet/RailBulletType.java @@ -16,6 +16,7 @@ public class RailBulletType extends BulletType{ public float updateEffectSeg = 20f; public RailBulletType(){ + speed = 0f; pierceBuilding = true; pierce = true; reflectable = false; @@ -23,7 +24,6 @@ public class RailBulletType extends BulletType{ despawnEffect = Fx.none; collides = false; lifetime = 1f; - speed = 0.01f; } @Override @@ -57,7 +57,7 @@ public class RailBulletType extends BulletType{ Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), length, false, false); float resultLen = b.fdata; - Vec2 nor = Tmp.v1.set(b.vel).nor(); + Vec2 nor = Tmp.v1.trns(b.rotation(), 1f).nor(); for(float i = 0; i <= resultLen; i += updateEffectSeg){ updateEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation()); } diff --git a/core/src/mindustry/entities/comp/BulletComp.java b/core/src/mindustry/entities/comp/BulletComp.java index f9fe116008..c967d4dff4 100644 --- a/core/src/mindustry/entities/comp/BulletComp.java +++ b/core/src/mindustry/entities/comp/BulletComp.java @@ -2,7 +2,6 @@ package mindustry.entities.comp; import arc.func.*; import arc.graphics.g2d.*; -import arc.math.*; import arc.math.geom.*; import arc.struct.*; import arc.util.*; @@ -22,11 +21,16 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw @Import Team team; @Import Entityc owner; @Import float x, y, damage; + @Import Vec2 vel; IntSeq collided = new IntSeq(6); Object data; BulletType type; float fdata; + + @ReadOnly + private float rotation; + transient boolean absorbed, hit; transient @Nullable Trail trail; @@ -149,17 +153,20 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw type.drawLight(self()); } + public void initVel(float angle, float amount){ + vel.trns(angle, amount); + rotation = angle; + } + /** Sets the bullet's rotation in degrees. */ @Override public void rotation(float angle){ - vel().setAngle(angle); + vel.setAngle(rotation = angle); } /** @return the bullet's rotation. */ @Override public float rotation(){ - float angle = Mathf.atan2(vel().x, vel().y) * Mathf.radiansToDegrees; - if(angle < 0) angle += 360; - return angle; + return vel.isZero(0.001f) ? rotation : vel.angle(); } }