WIP point laser turret
This commit is contained in:
@@ -3,6 +3,7 @@ package mindustry.world.blocks.defense.turrets;
|
||||
import arc.math.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.*;
|
||||
import arc.util.io.*;
|
||||
import mindustry.content.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
import mindustry.gen.*;
|
||||
@@ -12,6 +13,8 @@ import mindustry.world.meta.*;
|
||||
/** A turret that fires a continuous beam bullet with no reload or coolant necessary. The bullet only disappears when the turret stops shooting. */
|
||||
public class ContinuousTurret extends Turret{
|
||||
public BulletType shootType = Bullets.placeholder;
|
||||
/** Speed at which the turret can change its bullet "aim" distance. This is only used for point laser bullets. */
|
||||
public float aimChangeSpeed = Float.POSITIVE_INFINITY;
|
||||
|
||||
public ContinuousTurret(String name){
|
||||
super(name);
|
||||
@@ -33,6 +36,7 @@ public class ContinuousTurret extends Turret{
|
||||
//TODO LaserTurret shared code
|
||||
public class ContinuousTurretBuild extends TurretBuild{
|
||||
public Seq<BulletEntry> bullets = new Seq<>();
|
||||
public float lastLength = size * 4f;
|
||||
|
||||
@Override
|
||||
protected void updateCooling(){
|
||||
@@ -85,6 +89,18 @@ public class ContinuousTurret extends Turret{
|
||||
entry.bullet.rotation(angle);
|
||||
entry.bullet.set(bulletX, bulletY);
|
||||
|
||||
//target length of laser
|
||||
float shootLength = Math.min(dst(targetPos), range);
|
||||
//current length of laser
|
||||
float curLength = dst(entry.bullet.aimX, entry.bullet.aimY);
|
||||
//resulting length of the bullet (smoothed)
|
||||
float resultLength = Mathf.approachDelta(curLength, shootLength, aimChangeSpeed);
|
||||
//actual aim end point based on length
|
||||
Tmp.v1.trns(rotation, lastLength = resultLength).add(x, y);
|
||||
|
||||
entry.bullet.aimX = Tmp.v1.x;
|
||||
entry.bullet.aimY = Tmp.v1.y;
|
||||
|
||||
if(isShooting() && hasAmmo()){
|
||||
entry.bullet.time = entry.bullet.lifetime * entry.bullet.type.optimalLifeFract * shootWarmup;
|
||||
entry.bullet.keepAlive = true;
|
||||
@@ -122,6 +138,11 @@ public class ContinuousTurret extends Turret{
|
||||
protected void handleBullet(@Nullable Bullet bullet, float offsetX, float offsetY, float angleOffset){
|
||||
if(bullet != null){
|
||||
bullets.add(new BulletEntry(bullet, offsetX, offsetY, angleOffset, 0f));
|
||||
|
||||
//make sure the length updates to the last set value
|
||||
Tmp.v1.trns(rotation, shootY + lastLength).add(x, y);
|
||||
bullet.aimX = Tmp.v1.x;
|
||||
bullet.aimY = Tmp.v1.y;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,5 +150,26 @@ public class ContinuousTurret extends Turret{
|
||||
public boolean shouldActiveSound(){
|
||||
return bullets.any();
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte version(){
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(Writes write){
|
||||
super.write(write);
|
||||
|
||||
write.f(lastLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Reads read, byte revision){
|
||||
super.read(read, revision);
|
||||
|
||||
if(revision >= 3){
|
||||
lastLength = read.f();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user