Added shell ejection effects / Added burst turret
This commit is contained in:
@@ -6,6 +6,7 @@ import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.LaserTurret;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.Turret;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.turrets.BurstTurret;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.turrets.DoubleTurret;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.turrets.LiquidTurret;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.turrets.PowerTurret;
|
||||
@@ -15,13 +16,24 @@ public class WeaponBlocks{
|
||||
|
||||
doubleturret = new DoubleTurret("doubleturret"){{
|
||||
ammoTypes = new AmmoType[]{AmmoTypes.basicIron};
|
||||
reload = 40f;
|
||||
reload = 25f;
|
||||
restitution = 0.03f;
|
||||
shootEffect = BulletFx.shootSmall;
|
||||
smokeEffect = BulletFx.shootSmallSmoke;
|
||||
}},
|
||||
|
||||
gatlingturret = new Turret("gatlingturret"){
|
||||
|
||||
},
|
||||
gatlingturret = new BurstTurret("gatlingturret") {{
|
||||
ammoTypes = new AmmoType[]{AmmoTypes.basicIron};
|
||||
ammoPerShot = 1;
|
||||
shots = 3;
|
||||
reload = 60f;
|
||||
restitution = 0.03f;
|
||||
recoil = 1.5f;
|
||||
burstSpacing = 6f;
|
||||
shootEffect = BulletFx.shootSmall;
|
||||
smokeEffect = BulletFx.shootSmallSmoke;
|
||||
ammoUseEffect = BulletFx.shellEjectSmall;
|
||||
}},
|
||||
|
||||
flameturret = new Turret("flameturret"){
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import io.anuke.ucore.graphics.Draw;
|
||||
public class TurretBullets {
|
||||
public static final BulletType
|
||||
|
||||
basicIron = new BulletType(2f, 0) {
|
||||
basicIron = new BulletType(3f, 0) {
|
||||
@Override
|
||||
public void draw(Bullet b) {
|
||||
Draw.color(Color.valueOf("f6e096"));
|
||||
Draw.color(Color.valueOf("f3d47f"));
|
||||
Draw.rect("bullet", b.x, b.y, b.angle() - 90);
|
||||
Draw.color();
|
||||
}
|
||||
|
||||
@@ -23,14 +23,30 @@ public class BulletFx {
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
smokeParticleSmall = new Effect(20, e -> {
|
||||
shootSmallSmoke = new Effect(20f, e -> {
|
||||
Draw.color(Color.GRAY);
|
||||
Fill.circle(e.x, e.y, e.fract()*1.5f);
|
||||
|
||||
Angles.randLenVectors(e.id, 5, e.powfract()*6f, e.rotation, 20f, (x, y) -> {
|
||||
Fill.circle(e.x + x, e.y + y, e.fract()*1.5f);
|
||||
});
|
||||
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
shellEjectSmall = new Effect(30f, e -> {
|
||||
Draw.color(Color.LIGHT_GRAY);
|
||||
Draw.alpha(e.fract());
|
||||
float rot = e.rotation + 90f;
|
||||
for(int i : Mathf.signs){
|
||||
float len = (2f + e.powfract()*6f) * i;
|
||||
float lr = rot + e.ifract()*30f*i;
|
||||
Draw.rect("white", e.x + Angles.trnsx(lr, len), e.y + Angles.trnsy(lr, len), 1f, 2f, rot + e.ifract()*50f*i);
|
||||
}
|
||||
Draw.color();
|
||||
}),
|
||||
|
||||
hit = new Effect(14, e -> {
|
||||
Draw.color(Color.WHITE, lighterOrange, e.ifract());
|
||||
Draw.color(Color.WHITE, lightOrange, e.ifract());
|
||||
Lines.stroke(0.5f + e.fract());
|
||||
|
||||
Angles.randLenVectors(e.id, 5, e.ifract()*15f, e.rotation, 50f, (x, y) -> {
|
||||
|
||||
@@ -33,6 +33,8 @@ public class Turret extends Block{
|
||||
protected AmmoType[] ammoTypes;
|
||||
protected ObjectMap<Item, AmmoType> ammoMap = new ObjectMap<>();
|
||||
|
||||
protected int ammoPerShot = 1;
|
||||
protected float ammoEjectBack = 1f;
|
||||
protected float range = 50f;
|
||||
protected float reload = 10f;
|
||||
protected float inaccuracy = 0f;
|
||||
@@ -47,6 +49,8 @@ public class Turret extends Block{
|
||||
protected String base = null; //name of the region to draw under turret, usually null
|
||||
|
||||
protected Effect shootEffect = Fx.none;
|
||||
protected Effect smokeEffect = Fx.none;
|
||||
protected Effect ammoUseEffect = Fx.none;
|
||||
protected String shootsound = "shoot";
|
||||
|
||||
public Turret(String name) {
|
||||
@@ -200,9 +204,10 @@ public class Turret extends Block{
|
||||
public AmmoType useAmmo(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
AmmoEntry entry = entity.ammo.peek();
|
||||
entry.amount --;
|
||||
entry.amount -= ammoPerShot;
|
||||
if(entry.amount == 0) entity.ammo.pop();
|
||||
entity.totalAmmo --;
|
||||
entity.totalAmmo -= ammoPerShot;
|
||||
ejectEffects(tile);
|
||||
return entry.type;
|
||||
}
|
||||
|
||||
@@ -215,14 +220,14 @@ public class Turret extends Block{
|
||||
/**Returns whether the turret has ammo.*/
|
||||
public boolean hasAmmo(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
return entity.ammo.size > 0 && entity.ammo.peek().amount > 0;
|
||||
return entity.ammo.size > 0 && entity.ammo.peek().amount >= ammoPerShot;
|
||||
}
|
||||
|
||||
protected void updateShooting(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
if(entity.reload >= reload) {
|
||||
AmmoType type = useAmmo(tile);
|
||||
AmmoType type = peekAmmo(tile);
|
||||
|
||||
shoot(tile, type);
|
||||
|
||||
@@ -237,11 +242,11 @@ public class Turret extends Block{
|
||||
|
||||
entity.recoil = recoil;
|
||||
|
||||
useAmmo(tile);
|
||||
|
||||
tr.trns(entity.rotation, size * tilesize / 2);
|
||||
|
||||
for (int i = 0; i < shots; i++) {
|
||||
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
|
||||
}
|
||||
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
|
||||
|
||||
Effects.effect(shootEffect, tile.drawx() + tr.x,
|
||||
tile.drawy() + tr.y, entity.rotation);
|
||||
@@ -255,6 +260,26 @@ public class Turret extends Block{
|
||||
new Bullet(type, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y, angle).add();
|
||||
}
|
||||
|
||||
protected void effects(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
Effects.effect(shootEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
Effects.effect(smokeEffect, tile.drawx() + tr.x, tile.drawy() + tr.y, entity.rotation);
|
||||
|
||||
if (shootShake > 0) {
|
||||
Effects.shake(shootShake, shootShake, tile.entity);
|
||||
}
|
||||
|
||||
entity.recoil = recoil;
|
||||
}
|
||||
|
||||
protected void ejectEffects(Tile tile){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
Effects.effect(ammoUseEffect, tile.drawx() - Angles.trnsx(entity.rotation, ammoEjectBack),
|
||||
tile.drawy() - Angles.trnsy(entity.rotation, ammoEjectBack), entity.rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getEntity(){
|
||||
return new TurretEntity();
|
||||
@@ -277,6 +302,7 @@ public class Turret extends Block{
|
||||
public float reload;
|
||||
public float rotation = 90;
|
||||
public float recoil = 0f;
|
||||
public int shots;
|
||||
public Unit target;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.Turret;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
public class BurstTurret extends Turret {
|
||||
protected float burstSpacing = 5;
|
||||
|
||||
public BurstTurret(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shoot(Tile tile, AmmoType ammo){
|
||||
TurretEntity entity = tile.entity();
|
||||
|
||||
for (int i = 0; i < shots; i++) {
|
||||
Timers.run(burstSpacing * i, () -> {
|
||||
if(!(tile.entity instanceof TurretEntity) ||
|
||||
!hasAmmo(tile)) return;
|
||||
|
||||
tr.trns(entity.rotation, size * tilesize / 2);
|
||||
useAmmo(tile);
|
||||
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
|
||||
effects(tile);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense.turrets;
|
||||
|
||||
import io.anuke.mindustry.graphics.fx.BulletFx;
|
||||
import io.anuke.mindustry.resource.AmmoType;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.defense.Turret;
|
||||
import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
@@ -20,24 +18,14 @@ public class DoubleTurret extends Turret {
|
||||
@Override
|
||||
protected void shoot(Tile tile, AmmoType ammo){
|
||||
TurretEntity entity = tile.entity();
|
||||
entity.shots ++;
|
||||
|
||||
entity.recoil = recoil;
|
||||
int i = Mathf.signs[entity.shots % 2];
|
||||
|
||||
for (int i : Mathf.signs) {
|
||||
for(int j = 0; j < 3; j ++){
|
||||
tr.trns(entity.rotation - 90, shotWidth * i, size * tilesize / 2 + j);
|
||||
Effects.effect(BulletFx.smokeParticleSmall, tile.drawx() + tr.x + Mathf.range(1f), tile.drawy() + tr.y + Mathf.range(1f));
|
||||
}
|
||||
tr.trns(entity.rotation - 90, shotWidth * i, size * tilesize / 2);
|
||||
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
|
||||
|
||||
tr.trns(entity.rotation - 90, shotWidth * i, size * tilesize / 2);
|
||||
bullet(tile, ammo.bullet, entity.rotation + Mathf.range(inaccuracy));
|
||||
|
||||
Effects.effect(shootEffect, tile.drawx() + tr.x,
|
||||
tile.drawy() + tr.y, entity.rotation);
|
||||
}
|
||||
|
||||
if (shootShake > 0) {
|
||||
Effects.shake(shootShake, shootShake, tile.entity);
|
||||
}
|
||||
useAmmo(tile);
|
||||
effects(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user