Merged some turret classes

This commit is contained in:
Anuken
2020-05-29 09:59:08 -04:00
parent a7f86b2ba6
commit a89d2025e3
14 changed files with 128 additions and 184 deletions

View File

@@ -14,6 +14,7 @@ public class ArtilleryBulletType extends BasicBulletType{
collidesTiles = false;
collides = false;
collidesAir = false;
scaleVelocity = true;
hitShake = 1f;
hitSound = Sounds.explosion;
}

View File

@@ -61,6 +61,8 @@ public abstract class BulletType extends Content{
public boolean collides = true;
/** Whether velocity is inherited from the shooter. */
public boolean keepVelocity = true;
/** Whether to scale velocity to disappear at the target position. Used for artillery. */
public boolean scaleVelocity;
//additional effects

View File

@@ -110,7 +110,7 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
shootY = mountY + Angles.trnsy(weaponRotation, weapon.shootX * i, weapon.shootY);
float shootAngle = weapon.rotate ? weaponRotation + 90 : Angles.angle(shootX, shootY, mount.aimX, mount.aimY) + (this.rotation - angleTo(mount.aimX, mount.aimY));
shoot(weapon, shootX, shootY, shootAngle, -i);
shoot(weapon, shootX, shootY, mount.aimX, mount.aimY, shootAngle, -i);
}
if(mount.weapon.mirror) mount.side = !mount.side;
@@ -120,23 +120,24 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
}
}
private void shoot(Weapon weapon, float x, float y, float rotation, int side){
private void shoot(Weapon weapon, float x, float y, float aimX, float aimY, float rotation, int side){
float baseX = this.x, baseY = this.y;
weapon.shootSound.at(x, y, Mathf.random(0.8f, 1.0f));
BulletType ammo = weapon.bullet;
float lifeScl = ammo.scaleVelocity ? Mathf.clamp(Mathf.dst(x, y, aimX, aimY) / ammo.range()) : 1f;
sequenceNum = 0;
if(weapon.shotDelay > 0.01f){
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> {
Time.run(sequenceNum * weapon.shotDelay, () -> bullet(weapon, x + this.x - baseX, y + this.y - baseY, f + Mathf.range(weapon.inaccuracy)));
Time.run(sequenceNum * weapon.shotDelay, () -> bullet(weapon, x + this.x - baseX, y + this.y - baseY, f + Mathf.range(weapon.inaccuracy), lifeScl));
sequenceNum++;
});
}else{
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> bullet(weapon, x, y, f + Mathf.range(weapon.inaccuracy)));
Angles.shotgun(weapon.shots, weapon.spacing, rotation, f -> bullet(weapon, x, y, f + Mathf.range(weapon.inaccuracy), lifeScl));
}
BulletType ammo = weapon.bullet;
Tmp.v1.trns(rotation + 180f, ammo.recoil);
if(this instanceof Velc){
@@ -153,8 +154,8 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
ammo.smokeEffect.at(x + Tmp.v1.x, y + Tmp.v1.y, rotation, parentize ? this : null);
}
private void bullet(Weapon weapon, float x, float y, float angle){
private void bullet(Weapon weapon, float x, float y, float angle, float lifescl){
Tmp.v1.trns(angle, 3f);
weapon.bullet.create(this, team(), x + Tmp.v1.x, y + Tmp.v1.y, angle, (1f - weapon.velocityRnd) + Mathf.random(weapon.velocityRnd));
weapon.bullet.create(this, team(), x + Tmp.v1.x, y + Tmp.v1.y, angle, (1f - weapon.velocityRnd) + Mathf.random(weapon.velocityRnd), lifescl);
}
}