From 6e5aec080a074b53e8defef5f9a400d30477da18 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 24 Jun 2018 21:05:00 -0400 Subject: [PATCH] Implemented artillery turret, carbide artillery shells --- .../content/blocks/TurretBlocks.java | 8 ++-- .../content/bullets/ArtilleryBullets.java | 12 +++--- .../anuke/mindustry/content/fx/BulletFx.java | 8 +++- .../src/io/anuke/mindustry/entities/Unit.java | 2 +- .../entities/bullet/ArtilleryBulletType.java | 36 ++++++++++++++++ .../entities/bullet/BasicBulletType.java | 11 ++++- .../mindustry/entities/bullet/Bullet.java | 2 +- .../mindustry/entities/bullet/BulletType.java | 2 + .../mindustry/entities/units/GroundUnit.java | 2 +- .../defense/turrets/ArtilleryTurret.java | 41 +++++++++++++++++++ .../world/blocks/defense/turrets/Turret.java | 1 + 11 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 core/src/io/anuke/mindustry/entities/bullet/ArtilleryBulletType.java create mode 100644 core/src/io/anuke/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java diff --git a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java index 4b3d9f4766..e5817ebe39 100644 --- a/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java +++ b/core/src/io/anuke/mindustry/content/blocks/TurretBlocks.java @@ -37,10 +37,12 @@ public class TurretBlocks extends BlockList implements ContentList { ammoUseEffect = ShootFx.shellEjectSmall; }};*/ - hail = new ItemTurret("hail") {{ + hail = new ArtilleryTurret("hail") {{ ammoTypes = new AmmoType[]{AmmoTypes.artilleryCarbide, AmmoTypes.artilleryHoming, AmmoTypes.artilleryIncindiary}; - reload = 40f; + reload = 100f; + recoil = 2f; range = 200f; + inaccuracy = 5f; }}; scorch = new LiquidTurret("scorch") {{ @@ -136,7 +138,7 @@ public class TurretBlocks extends BlockList implements ContentList { }; }}; - ripple = new ItemTurret("ripple") {{ + ripple = new ArtilleryTurret("ripple") {{ ammoTypes = new AmmoType[]{AmmoTypes.artilleryCarbide, AmmoTypes.artilleryHoming, AmmoTypes.artilleryIncindiary, AmmoTypes.artilleryPlastic, AmmoTypes.artilleryThorium}; size = 3; }}; diff --git a/core/src/io/anuke/mindustry/content/bullets/ArtilleryBullets.java b/core/src/io/anuke/mindustry/content/bullets/ArtilleryBullets.java index 3d9ade06f7..26407685b8 100644 --- a/core/src/io/anuke/mindustry/content/bullets/ArtilleryBullets.java +++ b/core/src/io/anuke/mindustry/content/bullets/ArtilleryBullets.java @@ -1,6 +1,7 @@ package io.anuke.mindustry.content.bullets; import io.anuke.mindustry.content.fx.BulletFx; +import io.anuke.mindustry.entities.bullet.ArtilleryBulletType; import io.anuke.mindustry.entities.bullet.BasicBulletType; import io.anuke.mindustry.entities.bullet.BulletType; import io.anuke.mindustry.type.ContentList; @@ -11,14 +12,15 @@ public class ArtilleryBullets extends BulletList implements ContentList{ @Override public void load() { - carbide = new BasicBulletType(3f, 0, "shell") { + carbide = new ArtilleryBulletType(3f, 4, "shell") { { hiteffect = BulletFx.flakExplosion; knockback = 0.8f; - lifetime = 90f; - drag = 0.01f; - bulletWidth = bulletHeight = 9f; - bulletShrink = 0.1f; + lifetime = 50f; + bulletWidth = bulletHeight = 11f; + collidesTiles = false; + splashDamageRadius = 25f; + splashDamage = 33f; } }; diff --git a/core/src/io/anuke/mindustry/content/fx/BulletFx.java b/core/src/io/anuke/mindustry/content/fx/BulletFx.java index 08b50674de..fc805cd932 100644 --- a/core/src/io/anuke/mindustry/content/fx/BulletFx.java +++ b/core/src/io/anuke/mindustry/content/fx/BulletFx.java @@ -11,7 +11,7 @@ import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Mathf; public class BulletFx extends FxList implements ContentList { - public static Effect hitBulletSmall, hitBulletBig, hitFlameSmall, hitLiquid, hitLancer, despawn, flakExplosion; + public static Effect hitBulletSmall, hitBulletBig, hitFlameSmall, hitLiquid, hitLancer, despawn, flakExplosion, artilleryTrail; @Override public void load() { @@ -109,6 +109,12 @@ public class BulletFx extends FxList implements ContentList { Draw.reset(); }); + + artilleryTrail = new Effect(50, e -> { + Draw.color(Palette.bulletYellowBack); + Fill.circle(e.x, e.y, e.rotation * e.fout()); + Draw.reset(); + }); } } diff --git a/core/src/io/anuke/mindustry/entities/Unit.java b/core/src/io/anuke/mindustry/entities/Unit.java index f570b160f9..27abe68f0c 100644 --- a/core/src/io/anuke/mindustry/entities/Unit.java +++ b/core/src/io/anuke/mindustry/entities/Unit.java @@ -298,7 +298,7 @@ public abstract class Unit extends DestructibleEntity implements SaveTrait, Targ } public float getViewDistance(){ - return 130f; + return 135f; } public abstract TextureRegion getIconRegion(); diff --git a/core/src/io/anuke/mindustry/entities/bullet/ArtilleryBulletType.java b/core/src/io/anuke/mindustry/entities/bullet/ArtilleryBulletType.java new file mode 100644 index 0000000000..bd8dc54241 --- /dev/null +++ b/core/src/io/anuke/mindustry/entities/bullet/ArtilleryBulletType.java @@ -0,0 +1,36 @@ +package io.anuke.mindustry.entities.bullet; + +import io.anuke.mindustry.content.fx.BulletFx; +import io.anuke.ucore.core.Effects; +import io.anuke.ucore.graphics.Draw; + +//TODO scale velocity depending on fslope() +public class ArtilleryBulletType extends BasicBulletType { + + public ArtilleryBulletType(float speed, float damage, String bulletSprite) { + super(speed, damage, bulletSprite); + collidesTiles = false; + collides = false; + } + + @Override + public void update(Bullet b) { + if(b.timer.get(0, 3 + b.fslope()*2f)){ + Effects.effect(BulletFx.artilleryTrail, b.x, b.y, b.fslope() * 4f); + } + } + + @Override + public void draw(Bullet b) { + float baseScale = 0.7f; + float scale = (baseScale + b.fslope()*(1f-baseScale)); + + float height = bulletHeight * ((1f - bulletShrink) + bulletShrink * b.fout()); + + Draw.color(backColor); + Draw.rect(backRegion, b.x, b.y, bulletWidth * scale, height * scale, b.angle() - 90); + Draw.color(frontColor); + Draw.rect(frontRegion, b.x, b.y, bulletWidth * scale, height * scale, b.angle() - 90); + Draw.color(); + } +} diff --git a/core/src/io/anuke/mindustry/entities/bullet/BasicBulletType.java b/core/src/io/anuke/mindustry/entities/bullet/BasicBulletType.java index db13a01b4c..2a97abad2a 100644 --- a/core/src/io/anuke/mindustry/entities/bullet/BasicBulletType.java +++ b/core/src/io/anuke/mindustry/entities/bullet/BasicBulletType.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.entities.bullet; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import io.anuke.mindustry.entities.Damage; import io.anuke.mindustry.graphics.Palette; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.util.Angles; @@ -18,6 +19,10 @@ public class BasicBulletType extends BulletType { public float fragVelocityMin = 0.2f, fragVelocityMax = 1f; public BulletType fragBullet = null; + /**Use a negative value to disable splash damage.*/ + public float splashDamageRadius = -1f; + public float splashDamage = 6f; + public TextureRegion backRegion; public TextureRegion frontRegion; @@ -54,11 +59,15 @@ public class BasicBulletType extends BulletType { Bullet.create(fragBullet, b, x + Angles.trnsx(a, len), y + Angles.trnsy(a, len), a, Mathf.random(fragVelocityMin, fragVelocityMax)); } } + + if(splashDamageRadius > 0){ + Damage.damage(x, y, splashDamageRadius, splashDamage); + } } @Override public void despawned(Bullet b) { - if(fragBullet != null){ + if(fragBullet != null || splashDamageRadius > 0){ hit(b); } } diff --git a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java index 5a227e4de0..a60beb6aea 100644 --- a/core/src/io/anuke/mindustry/entities/bullet/Bullet.java +++ b/core/src/io/anuke/mindustry/entities/bullet/Bullet.java @@ -166,7 +166,7 @@ public class Bullet extends BulletEntity implements TeamTrait, SyncT @Override public boolean collides(SolidTrait other){ - return super.collides(other); + return type.collides && super.collides(other); } @Override diff --git a/core/src/io/anuke/mindustry/entities/bullet/BulletType.java b/core/src/io/anuke/mindustry/entities/bullet/BulletType.java index 291d1bc613..69c7b5b8a6 100644 --- a/core/src/io/anuke/mindustry/entities/bullet/BulletType.java +++ b/core/src/io/anuke/mindustry/entities/bullet/BulletType.java @@ -27,6 +27,8 @@ public abstract class BulletType extends BaseBulletType implements Conte public boolean syncable; /**Whether this bullet type collides with tiles.*/ public boolean collidesTiles = true; + /**Whether this bullet types collides with anything at all.*/ + public boolean collides = true; public BulletType(float speed, float damage){ this.id = lastid ++; diff --git a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java index afbcda8b85..dc2a333027 100644 --- a/core/src/io/anuke/mindustry/entities/units/GroundUnit.java +++ b/core/src/io/anuke/mindustry/entities/units/GroundUnit.java @@ -170,7 +170,7 @@ public abstract class GroundUnit extends BaseUnit { TileEntity core = getClosestEnemyCore(); float dst = core == null ? 0 :distanceTo(core); - if(core != null && dst < inventory.getAmmo().getRange()){ + if(core != null && inventory.hasAmmo() && dst < inventory.getAmmo().getRange()){ target = core; }else { retarget(() -> targetClosest()); diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java new file mode 100644 index 0000000000..f7047618cc --- /dev/null +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/ArtilleryTurret.java @@ -0,0 +1,41 @@ +package io.anuke.mindustry.world.blocks.defense.turrets; + +import com.badlogic.gdx.math.Vector2; +import io.anuke.mindustry.entities.Predict; +import io.anuke.mindustry.entities.bullet.Bullet; +import io.anuke.mindustry.type.AmmoType; +import io.anuke.mindustry.world.Tile; +import io.anuke.ucore.util.Mathf; + +import static io.anuke.mindustry.Vars.tilesize; + +/**Artillery turrets have special shooting calculations done to hit targets.*/ +public class ArtilleryTurret extends ItemTurret { + + public ArtilleryTurret(String name) { + super(name); + } + + @Override + protected void shoot(Tile tile, AmmoType ammo){ + TurretEntity entity = tile.entity(); + + entity.recoil = recoil; + entity.heat = 1f; + + AmmoType type = peekAmmo(tile); + useAmmo(tile); + + tr.trns(entity.rotation, size * tilesize / 2); + + Vector2 predict = Predict.intercept(tile, entity.target, type.bullet.speed); + + float dst = entity.distanceTo(predict.x, predict.y); + float maxTraveled = type.bullet.lifetime * type.bullet.speed; + + Bullet.create(ammo.bullet, tile.entity, tile.getTeam(), tile.drawx() + tr.x, tile.drawy() + tr.y, + entity.rotation + Mathf.range(inaccuracy + type.inaccuracy), dst/maxTraveled); + + effects(tile); + } +} diff --git a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java index f6d17b3aaf..ff97d4fd34 100644 --- a/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java +++ b/core/src/io/anuke/mindustry/world/blocks/defense/turrets/Turret.java @@ -77,6 +77,7 @@ public abstract class Turret extends Block{ @Override public void init() { + super.init(); viewRange = range; }