Let bullets have speed = 0

This commit is contained in:
Anuken
2021-06-04 08:53:39 -04:00
parent 6ceb1d5058
commit 1bbb52877f
7 changed files with 23 additions and 13 deletions

View File

@@ -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}]}

View File

@@ -445,7 +445,7 @@ public class BulletType extends Content implements Cloneable{
bullet.owner = owner; bullet.owner = owner;
bullet.team = team; bullet.team = team;
bullet.time = 0f; bullet.time = 0f;
bullet.vel.trns(angle, speed * velocityScl); bullet.initVel(angle, speed * velocityScl);
if(backMove){ if(backMove){
bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta); bullet.set(x - bullet.vel.x * Time.delta, y - bullet.vel.y * Time.delta);
}else{ }else{
@@ -462,7 +462,7 @@ public class BulletType extends Content implements Cloneable{
} }
bullet.add(); 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; return bullet;
} }

View File

@@ -23,7 +23,8 @@ public class ContinuousLaserBulletType extends BulletType{
public boolean largeHit = true; public boolean largeHit = true;
public ContinuousLaserBulletType(float damage){ public ContinuousLaserBulletType(float damage){
super(0.001f, damage); this.damage = damage;
this.speed = 0f;
hitEffect = Fx.hitBeam; hitEffect = Fx.hitBeam;
despawnEffect = Fx.none; despawnEffect = Fx.none;

View File

@@ -21,7 +21,8 @@ public class LaserBulletType extends BulletType{
public boolean largeHit = false; public boolean largeHit = false;
public LaserBulletType(float damage){ public LaserBulletType(float damage){
super(0.01f, damage); this.damage = damage;
this.speed = 0f;
hitEffect = Fx.hitLaserBlast; hitEffect = Fx.hitLaserBlast;
hitColor = colors[2]; hitColor = colors[2];

View File

@@ -12,8 +12,8 @@ public class LightningBulletType extends BulletType{
public int lightningLength = 25, lightningLengthRand = 0; public int lightningLength = 25, lightningLengthRand = 0;
public LightningBulletType(){ public LightningBulletType(){
super(0.0001f, 1f); damage = 1f;
speed = 0f;
lifetime = 1; lifetime = 1;
despawnEffect = Fx.none; despawnEffect = Fx.none;
hitEffect = Fx.hitLancer; hitEffect = Fx.hitLancer;

View File

@@ -16,6 +16,7 @@ public class RailBulletType extends BulletType{
public float updateEffectSeg = 20f; public float updateEffectSeg = 20f;
public RailBulletType(){ public RailBulletType(){
speed = 0f;
pierceBuilding = true; pierceBuilding = true;
pierce = true; pierce = true;
reflectable = false; reflectable = false;
@@ -23,7 +24,6 @@ public class RailBulletType extends BulletType{
despawnEffect = Fx.none; despawnEffect = Fx.none;
collides = false; collides = false;
lifetime = 1f; lifetime = 1f;
speed = 0.01f;
} }
@Override @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); Damage.collideLine(b, b.team, b.type.hitEffect, b.x, b.y, b.rotation(), length, false, false);
float resultLen = b.fdata; 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){ for(float i = 0; i <= resultLen; i += updateEffectSeg){
updateEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation()); updateEffect.at(b.x + nor.x * i, b.y + nor.y * i, b.rotation());
} }

View File

@@ -2,7 +2,6 @@ package mindustry.entities.comp;
import arc.func.*; import arc.func.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.*; import arc.struct.*;
import arc.util.*; import arc.util.*;
@@ -22,11 +21,16 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
@Import Team team; @Import Team team;
@Import Entityc owner; @Import Entityc owner;
@Import float x, y, damage; @Import float x, y, damage;
@Import Vec2 vel;
IntSeq collided = new IntSeq(6); IntSeq collided = new IntSeq(6);
Object data; Object data;
BulletType type; BulletType type;
float fdata; float fdata;
@ReadOnly
private float rotation;
transient boolean absorbed, hit; transient boolean absorbed, hit;
transient @Nullable Trail trail; transient @Nullable Trail trail;
@@ -149,17 +153,20 @@ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Draw
type.drawLight(self()); type.drawLight(self());
} }
public void initVel(float angle, float amount){
vel.trns(angle, amount);
rotation = angle;
}
/** Sets the bullet's rotation in degrees. */ /** Sets the bullet's rotation in degrees. */
@Override @Override
public void rotation(float angle){ public void rotation(float angle){
vel().setAngle(angle); vel.setAngle(rotation = angle);
} }
/** @return the bullet's rotation. */ /** @return the bullet's rotation. */
@Override @Override
public float rotation(){ public float rotation(){
float angle = Mathf.atan2(vel().x, vel().y) * Mathf.radiansToDegrees; return vel.isZero(0.001f) ? rotation : vel.angle();
if(angle < 0) angle += 360;
return angle;
} }
} }