120 lines
3.7 KiB
Java
120 lines
3.7 KiB
Java
package mindustry.entities.def;
|
|
|
|
import arc.graphics.*;
|
|
import arc.graphics.g2d.*;
|
|
import arc.math.*;
|
|
import arc.math.geom.*;
|
|
import arc.util.*;
|
|
import mindustry.*;
|
|
import mindustry.annotations.Annotations.*;
|
|
import mindustry.content.*;
|
|
import mindustry.entities.*;
|
|
import mindustry.gen.*;
|
|
import mindustry.type.*;
|
|
import mindustry.world.*;
|
|
|
|
import static mindustry.Vars.world;
|
|
import static mindustry.entities.Puddles.maxLiquid;
|
|
|
|
@EntityDef(value = {Puddlec.class}, pooled = true)
|
|
@Component
|
|
abstract class PuddleComp implements Posc, DrawLayerFloorOverc{
|
|
private static final int maxGeneration = 2;
|
|
private static final Color tmp = new Color();
|
|
private static final Rect rect = new Rect();
|
|
private static final Rect rect2 = new Rect();
|
|
private static int seeds;
|
|
|
|
transient float x, y;
|
|
|
|
float amount, lastRipple, accepting, updateTime;
|
|
int generation;
|
|
Tile tile;
|
|
Liquid liquid;
|
|
|
|
public float getFlammability(){
|
|
return liquid.flammability * amount;
|
|
}
|
|
|
|
@Override
|
|
public void update(){
|
|
//update code
|
|
float addSpeed = accepting > 0 ? 3f : 0f;
|
|
|
|
amount -= Time.delta() * (1f - liquid.viscosity) / (5f + addSpeed);
|
|
|
|
amount += accepting;
|
|
accepting = 0f;
|
|
|
|
if(amount >= maxLiquid / 1.5f && generation < maxGeneration){
|
|
float deposited = Math.min((amount - maxLiquid / 1.5f) / 4f, 0.3f) * Time.delta();
|
|
for(Point2 point : Geometry.d4){
|
|
Tile other = world.tile(tile.x + point.x, tile.y + point.y);
|
|
if(other != null && other.block() == Blocks.air){
|
|
Puddles.deposit(other, tile, liquid, deposited, generation + 1);
|
|
amount -= deposited / 2f; //tweak to speed up/slow down Puddlec propagation
|
|
}
|
|
}
|
|
}
|
|
|
|
amount = Mathf.clamp(amount, 0, maxLiquid);
|
|
|
|
if(amount <= 0f){
|
|
remove();
|
|
}
|
|
|
|
//effects-only code
|
|
if(amount >= maxLiquid / 2f && updateTime <= 0f){
|
|
Units.nearby(rect.setSize(Mathf.clamp(amount / (maxLiquid / 1.5f)) * 10f).setCenter(x, y), unit -> {
|
|
if(unit.isGrounded()){
|
|
unit.hitbox(rect2);
|
|
if(rect.overlaps(rect2)){
|
|
unit.apply(liquid.effect, 60 * 2);
|
|
|
|
if(unit.vel().len() > 0.1){
|
|
Fx.ripple.at(unit.x(), unit.y(), liquid.color);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
if(liquid.temperature > 0.7f && (tile.link().entity != null) && Mathf.chance(0.3 * Time.delta())){
|
|
Fires.create(tile);
|
|
}
|
|
|
|
updateTime = 20f;
|
|
}
|
|
|
|
updateTime -= Time.delta();
|
|
}
|
|
|
|
@Override
|
|
public void drawFloorOver(){
|
|
seeds = id();
|
|
boolean onLiquid = tile.floor().isLiquid;
|
|
float f = Mathf.clamp(amount / (maxLiquid / 1.5f));
|
|
float smag = onLiquid ? 0.8f : 0f;
|
|
float sscl = 20f;
|
|
|
|
Draw.color(tmp.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;
|
|
Vars.renderer.lights.add(tile.drawx(), tile.drawy(), 30f * f, color, opacity * 0.8f);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void remove(){
|
|
Puddles.remove(tile);
|
|
}
|
|
}
|