Liquid puddle draw override

This commit is contained in:
Anuken
2021-08-19 09:21:25 -04:00
parent 53eba2fb6a
commit a67b7a6e77
4 changed files with 91 additions and 39 deletions

View File

@ -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");
}};
}
}

View File

@ -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

View File

@ -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();
}
}

View File

@ -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);