Bullet mover cleanup
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
package mindustry.entities;
|
package mindustry.entities;
|
||||||
|
|
||||||
import arc.math.geom.*;
|
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
|
|
||||||
/** Applies custom movement to a bullet. */
|
/** Applies custom movement to a bullet. */
|
||||||
public interface Mover{
|
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
|
@Override
|
||||||
public void update(){
|
public void update(){
|
||||||
if(mover != null){
|
if(mover != null){
|
||||||
float v = mover.move(self()) * Time.delta;
|
mover.move(self());
|
||||||
float ang = vel.angle();
|
|
||||||
vel.add(Angles.trnsx(ang, 0f, v), Angles.trnsy(ang, 0f, v)).limit(type.speed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type.update(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.
|
//copy-paste of World#raycastEach, inlined for lambda capture performance.
|
||||||
@Override
|
@Override
|
||||||
public void tileRaycast(int x1, int y1, int x2, int y2){
|
public void tileRaycast(int x1, int y1, int x2, int y2){
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ package mindustry.entities.pattern;
|
|||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
|
|
||||||
public class ShootHelix extends ShootPattern{
|
public class ShootHelix extends ShootPattern{
|
||||||
//TODO: pattern is broken without a proper offset
|
public float scl = 2f, mag = 1.5f, offset = Mathf.PI * 1.25f;
|
||||||
public float scl = 2f, mag = 0.5f, offset = Mathf.PI * 1.25f;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void shoot(int totalShots, BulletHandler handler){
|
public void shoot(int totalShots, BulletHandler handler){
|
||||||
for(int i = 0; i < shots; i++){
|
for(int i = 0; i < shots; i++){
|
||||||
for(int sign : Mathf.signs){
|
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) -> {
|
shoot.shoot(mount.totalShots, (xOffset, yOffset, angle, delay, mover) -> {
|
||||||
if(delay > 0f){
|
if(delay > 0f){
|
||||||
Time.run(delay, () -> setupBullet(unit, mount, xOffset, yOffset, angle, mover));
|
Time.run(delay, () -> bullet(unit, mount, xOffset, yOffset, angle, mover));
|
||||||
}else{
|
}else{
|
||||||
setupBullet(unit, mount, xOffset, yOffset, angle, mover);
|
bullet(unit, mount, xOffset, yOffset, angle, mover);
|
||||||
}
|
}
|
||||||
mount.totalShots ++;
|
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;
|
if(!unit.isAdded()) return;
|
||||||
|
|
||||||
float
|
float
|
||||||
|
|||||||
Reference in New Issue
Block a user