From a67b7a6e77d8c855de530c065db6b4cad4d69ca3 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 19 Aug 2021 09:21:25 -0400 Subject: [PATCH] Liquid puddle draw override --- core/src/mindustry/content/Liquids.java | 20 ++------ .../mindustry/entities/comp/PuddleComp.java | 23 +-------- core/src/mindustry/type/CellLiquid.java | 50 +++++++++++++++++++ core/src/mindustry/type/Liquid.java | 37 ++++++++++++++ 4 files changed, 91 insertions(+), 39 deletions(-) create mode 100644 core/src/mindustry/type/CellLiquid.java diff --git a/core/src/mindustry/content/Liquids.java b/core/src/mindustry/content/Liquids.java index 7e648456b5..5ab7820b70 100644 --- a/core/src/mindustry/content/Liquids.java +++ b/core/src/mindustry/content/Liquids.java @@ -1,15 +1,9 @@ package mindustry.content; import arc.graphics.*; -import arc.graphics.g2d.*; -import arc.math.*; import mindustry.ctype.*; -import mindustry.entities.*; -import mindustry.graphics.*; import mindustry.type.*; -import static arc.graphics.g2d.Draw.*; - public class Liquids implements ContentList{ public static Liquid water, slag, oil, cryofluid, neoplasm; @@ -45,22 +39,14 @@ public class Liquids implements ContentList{ lightColor = Color.valueOf("0097f5").a(0.2f); }}; - neoplasm = new Liquid("neoplasm", Color.valueOf("e05438")){{ + neoplasm = new CellLiquid("neoplasm", Color.valueOf("e05438")){{ heatCapacity = 0.4f; temperature = 0.54f; viscosity = 0.65f; flammability = 0.1f; - Color from = Color.valueOf("f98f4a"), to = Color.valueOf("9e172c"); - - //TODO could probably be improved... - particleSpacing = 70f; - particleEffect = new Effect(40f, e -> { - e.lifetime = Mathf.randomSeed(e.id + 2, 80f, 200f) * 3.2f; - color(from, to, Mathf.randomSeed(e.id, 1f)); - - Fill.circle(e.x, e.y, e.fslope() * Mathf.randomSeed(e.id + 1, 0.6f, 2.5f)); - }).layer(Layer.debris - 0.5f); + colorFrom = Color.valueOf("f98f4a"); + colorTo = Color.valueOf("9e172c"); }}; } } diff --git a/core/src/mindustry/entities/comp/PuddleComp.java b/core/src/mindustry/entities/comp/PuddleComp.java index 34dd4541c8..af703fffaf 100644 --- a/core/src/mindustry/entities/comp/PuddleComp.java +++ b/core/src/mindustry/entities/comp/PuddleComp.java @@ -1,7 +1,6 @@ package mindustry.entities.comp; import arc.func.*; -import arc.graphics.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; @@ -9,7 +8,6 @@ import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.entities.*; -import mindustry.game.*; import mindustry.gen.*; import mindustry.graphics.*; import mindustry.type.*; @@ -116,26 +114,7 @@ abstract class PuddleComp implements Posc, Puddlec, Drawc{ public void draw(){ Draw.z(Layer.debris - 1); - seeds = id; - boolean onLiquid = tile.floor().isLiquid; - float f = Mathf.clamp(amount / (maxLiquid / 1.5f)); - float smag = onLiquid ? 0.8f : 0f; - float sscl = 25f; - - Draw.color(Tmp.c1.set(liquid.color).shiftValue(-0.05f)); - Fill.circle(x + Mathf.sin(Time.time + seeds * 532, sscl, smag), y + Mathf.sin(Time.time + seeds * 53, sscl, smag), f * 8f); - Angles.randLenVectors(id(), 3, f * 6f, (ex, ey) -> { - Fill.circle(x + ex + Mathf.sin(Time.time + seeds * 532, sscl, smag), - y + ey + Mathf.sin(Time.time + seeds * 53, sscl, smag), f * 5f); - seeds++; - }); - Draw.color(); - - if(liquid.lightColor.a > 0.001f && f > 0){ - Color color = liquid.lightColor; - float opacity = color.a * f; - Drawf.light(Team.derelict, tile.drawx(), tile.drawy(), 30f * f, color, opacity * 0.8f); - } + liquid.drawPuddle(self()); } @Replace diff --git a/core/src/mindustry/type/CellLiquid.java b/core/src/mindustry/type/CellLiquid.java new file mode 100644 index 0000000000..715b23bed5 --- /dev/null +++ b/core/src/mindustry/type/CellLiquid.java @@ -0,0 +1,50 @@ +package mindustry.type; + +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; +import arc.util.*; +import mindustry.gen.*; +import mindustry.graphics.*; + +import static mindustry.entities.Puddles.*; + +public class CellLiquid extends Liquid{ + public Color colorFrom = Color.white.cpy(), colorTo = Color.white.cpy(); + + public CellLiquid(String name, Color color){ + super(name, color); + } + + public CellLiquid(String name){ + super(name); + } + + @Override + public void drawPuddle(Puddle puddle){ + super.drawPuddle(puddle); + + Draw.z(Layer.debris - 0.5f); + + int id = puddle.id; + float amount = puddle.amount, x = puddle.x, y = puddle.y; + float f = Mathf.clamp(amount / (maxLiquid / 1.5f)); + float smag = puddle.tile.floor().isLiquid ? 0.8f : 0f, sscl = 25f; + float length = Math.max(f, 0.3f) * 9f; + + rand.setSeed(id); + for(int i = 0; i < 8; i++){ + Tmp.v1.trns(rand.random(360f), rand.random(length)); + float vx = x + Tmp.v1.x, vy = y + Tmp.v1.y; + + Draw.color(colorFrom, colorTo, rand.random(1f)); + + Fill.circle( + vx + Mathf.sin(Time.time + i * 532, sscl, smag), + vy + Mathf.sin(Time.time + i * 53, sscl, smag), + f * 3.8f * rand.random(0.2f, 1f) * Mathf.absin(Time.time + ((i + id) % 60) * 54, 75f * rand.random(1f, 2f), 1f)); + } + + Draw.color(); + } +} diff --git a/core/src/mindustry/type/Liquid.java b/core/src/mindustry/type/Liquid.java index bc283b27b9..d1a0a89780 100644 --- a/core/src/mindustry/type/Liquid.java +++ b/core/src/mindustry/type/Liquid.java @@ -1,13 +1,22 @@ package mindustry.type; import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.math.*; import arc.util.*; import mindustry.content.*; import mindustry.ctype.*; import mindustry.entities.*; +import mindustry.game.*; +import mindustry.gen.*; +import mindustry.graphics.*; import mindustry.world.meta.*; +import static mindustry.entities.Puddles.*; + public class Liquid extends UnlockableContent{ + protected static final Rand rand = new Rand(); + /** Color used in pipes and on the ground. */ public Color color; /** Color used in bars. */ @@ -49,6 +58,34 @@ public class Liquid extends UnlockableContent{ return barColor == null ? color : barColor; } + /** Draws a puddle of this liquid on the floor. */ + public void drawPuddle(Puddle puddle){ + float amount = puddle.amount, x = puddle.x, y = puddle.y; + float f = Mathf.clamp(amount / (maxLiquid / 1.5f)); + float smag = puddle.tile.floor().isLiquid ? 0.8f : 0f, sscl = 25f; + + Draw.color(Tmp.c1.set(color).shiftValue(-0.05f)); + Fill.circle(x + Mathf.sin(Time.time + id * 532, sscl, smag), y + Mathf.sin(Time.time + id * 53, sscl, smag), f * 8f); + + float length = f * 6f; + rand.setSeed(id); + for(int i = 0; i < 3; i++){ + Tmp.v1.trns(rand.random(360f), rand.random(length)); + float vx = x + Tmp.v1.x, vy = y + Tmp.v1.y; + + Fill.circle( + vx + Mathf.sin(Time.time + i * 532, sscl, smag), + vy + Mathf.sin(Time.time + i * 53, sscl, smag), + f * 5f); + } + + Draw.color(); + + if(lightColor.a > 0.001f && f > 0){ + Drawf.light(Team.derelict, x, y, 30f * f, lightColor, color.a * f * 0.8f); + } + } + @Override public void setStats(){ stats.addPercent(Stat.explosiveness, explosiveness);