Bullet mover cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user