From 4b5d3ba4d88ade263d9030afa6b774bbe44825e4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 16 Oct 2019 16:33:09 -0400 Subject: [PATCH] Added laser bullet type --- .../io/anuke/mindustry/content/Bullets.java | 48 ++----------- core/src/io/anuke/mindustry/content/Fx.java | 6 +- .../src/io/anuke/mindustry/content/Mechs.java | 9 ++- .../entities/bullet/LaserBulletType.java | 69 +++++++++++++++++++ 4 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 core/src/io/anuke/mindustry/entities/bullet/LaserBulletType.java diff --git a/core/src/io/anuke/mindustry/content/Bullets.java b/core/src/io/anuke/mindustry/content/Bullets.java index 7ee440e158..2fe1427343 100644 --- a/core/src/io/anuke/mindustry/content/Bullets.java +++ b/core/src/io/anuke/mindustry/content/Bullets.java @@ -492,47 +492,13 @@ public class Bullets implements ContentList{ } }; - lancerLaser = new BulletType(0.001f, 140){ - Color[] colors = {Pal.lancerLaser.cpy().mul(1f, 1f, 1f, 0.4f), Pal.lancerLaser, Color.white}; - float[] tscales = {1f, 0.7f, 0.5f, 0.2f}; - float[] lenscales = {1f, 1.1f, 1.13f, 1.14f}; - float length = 160f; - - { - hitEffect = Fx.hitLancer; - despawnEffect = Fx.none; - hitSize = 4; - lifetime = 16f; - pierce = true; - keepVelocity = false; - } - - @Override - public float range(){ - return length; - } - - @Override - public void init(Bullet b){ - Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length); - } - - @Override - public void draw(Bullet b){ - float f = Mathf.curve(b.fin(), 0f, 0.2f); - float baseLen = length * f; - - Lines.lineAngle(b.x, b.y, b.rot(), baseLen); - for(int s = 0; s < 3; s++){ - Draw.color(colors[s]); - for(int i = 0; i < tscales.length; i++){ - Lines.stroke(7f * b.fout() * (s == 0 ? 1.5f : s == 1 ? 1f : 0.3f) * tscales[i]); - Lines.lineAngle(b.x, b.y, b.rot(), baseLen * lenscales[i]); - } - } - Draw.reset(); - } - }; + lancerLaser = new LaserBulletType(140){{ + colors = new Color[]{Pal.lancerLaser.cpy().mul(1f, 1f, 1f, 0.4f), Pal.lancerLaser, Color.white}; + hitEffect = Fx.hitLancer; + despawnEffect = Fx.none; + hitSize = 4; + lifetime = 16f; + }}; meltdownLaser = new BulletType(0.001f, 70){ Color tmpColor = new Color(); diff --git a/core/src/io/anuke/mindustry/content/Fx.java b/core/src/io/anuke/mindustry/content/Fx.java index 5f58afe9ee..95206e1204 100644 --- a/core/src/io/anuke/mindustry/content/Fx.java +++ b/core/src/io/anuke/mindustry/content/Fx.java @@ -855,9 +855,9 @@ public class Fx implements ContentList{ }); lancerLaserShootSmoke = new Effect(26f, e -> { - Draw.color(Pal.lancerLaser); + Draw.color(Color.white); - Angles.randLenVectors(e.id, 7, 80f, e.rotation, 0f, (x, y) -> { + Angles.randLenVectors(e.id, 7, 70f, e.rotation, 0f, (x, y) -> { Lines.lineAngle(e.x + x, e.y + y, Mathf.angle(x, y), e.fout() * 9f); }); @@ -874,7 +874,7 @@ public class Fx implements ContentList{ Draw.reset(); }); - lancerLaserChargeBegin = new Effect(71f, e -> { + lancerLaserChargeBegin = new Effect(60f, e -> { Draw.color(Pal.lancerLaser); Fill.circle(e.x, e.y, e.fin() * 3f); diff --git a/core/src/io/anuke/mindustry/content/Mechs.java b/core/src/io/anuke/mindustry/content/Mechs.java index ea64ad319c..2f0683204a 100644 --- a/core/src/io/anuke/mindustry/content/Mechs.java +++ b/core/src/io/anuke/mindustry/content/Mechs.java @@ -73,7 +73,7 @@ public class Mechs implements ContentList{ mass = 0.9f; health = 150f; buildPower = 0.9f; - weaponOffsetX = -1; + weaponOffsetX = 1; weaponOffsetY = -1; engineColor = Color.valueOf("d3ddff"); @@ -82,9 +82,14 @@ public class Mechs implements ContentList{ length = 1f; reload = 60f; roundrobin = true; - ejectEffect = Fx.none; bullet = Bullets.lancerLaser; shootSound = Sounds.spark; + + bullet = new LaserBulletType(20f){{ + recoil = 1f; + sideAngle = 45f; + colors = new Color[]{Pal.heal.cpy().mul(1, 1, 1, 0.4f), Pal.heal, Color.white}; + }}; }}; } diff --git a/core/src/io/anuke/mindustry/entities/bullet/LaserBulletType.java b/core/src/io/anuke/mindustry/entities/bullet/LaserBulletType.java new file mode 100644 index 0000000000..864b877bc1 --- /dev/null +++ b/core/src/io/anuke/mindustry/entities/bullet/LaserBulletType.java @@ -0,0 +1,69 @@ +package io.anuke.mindustry.entities.bullet; + +import io.anuke.arc.graphics.*; +import io.anuke.arc.graphics.g2d.*; +import io.anuke.arc.math.*; +import io.anuke.arc.util.*; +import io.anuke.mindustry.content.*; +import io.anuke.mindustry.entities.*; +import io.anuke.mindustry.entities.type.*; +import io.anuke.mindustry.graphics.*; + +public class LaserBulletType extends BulletType{ + protected Color[] colors = {Pal.lancerLaser.cpy().mul(1f, 1f, 1f, 0.4f), Pal.lancerLaser, Color.white}; + protected float length = 160f; + protected float width = 15f; + protected float lengthFalloff = 0.5f; + protected float sideLength = 29f, sideWidth = 0.7f; + protected float sideAngle = 90f; + + public LaserBulletType(float damage){ + super(0.01f, damage); + + keepVelocity = false; + hitEffect = Fx.hitLancer; + despawnEffect = Fx.none; + shootEffect = Fx.hitLancer; + smokeEffect = Fx.lancerLaserShootSmoke; + hitSize = 4; + lifetime = 16f; + pierce = true; + } + + @Override + public float range(){ + return length; + } + + @Override + public void init(Bullet b){ + Damage.collideLine(b, b.getTeam(), hitEffect, b.x, b.y, b.rot(), length); + } + + @Override + public void draw(Bullet b){ + float f = Mathf.curve(b.fin(), 0f, 0.2f); + float baseLen = length * f; + float cwidth = width; + float compound = 1f; + + Lines.lineAngle(b.x, b.y, b.rot(), baseLen); + Lines.precise(true); + for(Color color : colors){ + Draw.color(color); + Lines.stroke((cwidth *= lengthFalloff) * b.fout()); + Lines.lineAngle(b.x, b.y, b.rot(), baseLen, CapStyle.none); + Tmp.v1.trns(b.rot(), baseLen); + Drawf.tri(b.x + Tmp.v1.x, b.y + Tmp.v1.y, Lines.getStroke() * 1.22f, cwidth * 2f + width / 2f, b.rot()); + + Fill.circle(b.x, b.y, 1f * cwidth * b.fout()); + for(int i : Mathf.signs){ + Drawf.tri(b.x, b.y, sideWidth * b.fout() * cwidth, sideLength * compound, b.rot() + sideAngle * i); + } + + compound *= lengthFalloff; + } + Lines.precise(false); + Draw.reset(); + } +}