Bugfixes / Pathfinding 'improvements'

This commit is contained in:
Anuken
2019-02-23 20:16:32 -05:00
parent 976b39414f
commit b6c5f202e4
7 changed files with 46 additions and 28 deletions

View File

@@ -2,30 +2,38 @@ package io.anuke.mindustry.entities.effect;
import io.anuke.arc.Core;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.math.Mathf;
public class RubbleDecal extends Decal{
private int size;
private static TextureRegion[][] regions = new TextureRegion[16][0];
private TextureRegion region;
/**
* Creates a rubble effect at a position. Provide a block size to use.
*/
public static void create(float x, float y, int size){
if(regions[size].length == 0){
int i = 0;
for(; i < 2; i++){
if(!Core.atlas.has("rubble-" + size + "-" + i)){
break;
}
}
regions[size] = new TextureRegion[i + 1];
for(int j = 0; j <= i; j++){
regions[size][j] = Core.atlas.find("rubble-" + size + "-" + j);
}
}
RubbleDecal decal = new RubbleDecal();
decal.size = size;
decal.region = regions[size][Mathf.clamp(Mathf.randomSeed(decal.id, 0, 1), 0, regions[size].length - 1)];
decal.set(x, y);
decal.add();
}
@Override
public void drawDecal(){
String region = "rubble-" + size + "-" + Mathf.randomSeed(id, 0, 1);
if(!Core.atlas.has(region)){
remove();
return;
}
Draw.rect(region, x, y, Mathf.randomSeed(id, 0, 4) * 90);
}
}