Procedural scorch marks / Bugfixes

This commit is contained in:
Anuken
2020-02-09 12:07:36 -05:00
parent 8e976c20a1
commit d45d7f21b6
39 changed files with 1187 additions and 950 deletions

View File

@@ -26,6 +26,9 @@ class AllEntities{
@EntityDef({Unitc.class})
class GenericUnitDef{}
@EntityDef(value = {Firec.class}, pooled = true)
class FireDef{}
@GroupDef(Entityc.class)
void all(){

View File

@@ -55,7 +55,7 @@ public class Effects{
}
public static void decal(TextureRegion region, float x, float y, float rotation, float lifetime, Color color){
if(headless || region == null) return;
if(headless || region == null || !Core.atlas.isFound(region)) return;
Decalc decal = DecalEntity.create();
decal.set(x, y);
@@ -66,12 +66,20 @@ public class Effects{
decal.add();
}
public static void scorch(float x, float y, int size){
if(headless) return;
size = Mathf.clamp(size, 0, 9);
TextureRegion region = Core.atlas.find("scorch-" + size + "-" + Mathf.random(2));
decal(region, x, y, Mathf.random(4) * 90, 3600, Pal.rubble);
}
public static void rubble(float x, float y, int blockSize){
if(headless) return;
TextureRegion region = Core.atlas.find("rubble-" + blockSize + "-" + Mathf.random(0, 1));
if(!Core.atlas.isFound(region)) return;
decal(region, x, y, Mathf.random(0, 4) * 90, 3600, Pal.rubble);
TextureRegion region = Core.atlas.find("rubble-" + blockSize + "-" + (Core.atlas.has("rubble-" + blockSize + "-1") ? Mathf.random(0, 1) : "0"));
decal(region, x, y, Mathf.random(4) * 90, 3600, Pal.rubble);
}
}

View File

@@ -0,0 +1,8 @@
package mindustry.entities.def;
import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
@Component
abstract class FireComp implements Timedc{
}

View File

@@ -34,8 +34,12 @@ abstract class HealthComp implements Entityc{
}
void kill(){
if(dead) return;
health = 0;
dead = true;
killed();
remove();
}
void heal(){
@@ -50,8 +54,7 @@ abstract class HealthComp implements Entityc{
void damage(float amount){
health -= amount;
if(health <= 0 && !dead){
dead = true;
killed();
kill();
}
}

View File

@@ -59,6 +59,10 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc{
}
public void update(){
if(unit.dead()){
clearUnit();
}
if(!dead()){
x(unit.x());
y(unit.y());

View File

@@ -152,6 +152,7 @@ abstract class UnitComp implements Healthc, Velc, Statusc, Teamc, Itemsc, Hitbox
//TODO cleanup
//ScorchDecal.create(getX(), getY());
Effects.scorch(x, y, (int)(hitSize() / 5));
Fx.explosion.at(this);
Effects.shake(2f, 2f, this);
type.deathSound.at(this);

View File

@@ -0,0 +1,33 @@
package mindustry.graphics;
import arc.graphics.*;
import arc.math.*;
import arc.util.noise.*;
/** Generates a scorch pixmap based on parameters. Thread safe, unless multiple scorch generators are running in parallel. */
public class ScorchGenerator{
private static final Simplex sim = new Simplex();
public int size = 80, seed = 0, color = Color.white.rgba();
public double scale = 18, pow = 2, octaves = 4, pers = 0.4, add = 2, nscl = 4.5f;
public Pixmap generate(){
Pixmap pix = new Pixmap(size, size);
sim.setSeed(seed);
pix.each((x, y) -> {
double dst = Mathf.dst(x, y, size/2, size/2) / (size / 2f);
double scaled = Math.abs(dst - 0.5f) * 5f + add;
scaled -= noise(Angles.angle(x, y, size/2, size/2))*nscl;
boolean present = scaled < 1.5f;
if(present) pix.draw(x, y, color);
});
return pix;
}
private double noise(float angle){
return Math.pow(sim.octaveNoise2D(octaves, pers, 1 / scale, Angles.trnsx(angle, size/2f) + size/2f, Angles.trnsy(angle, size/2f) + size/2f), pow);
}
}