Added block cracks
This commit is contained in:
@@ -5,6 +5,7 @@ import io.anuke.arc.graphics.g2d.Draw;
|
||||
import io.anuke.arc.graphics.g2d.TextureRegion;
|
||||
import io.anuke.arc.math.Mathf;
|
||||
import io.anuke.arc.util.Log;
|
||||
import io.anuke.arc.util.noise.RidgedPerlin;
|
||||
import io.anuke.mindustry.ImagePacker.GenRegion;
|
||||
import io.anuke.mindustry.type.*;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
@@ -23,6 +24,51 @@ public class Generators{
|
||||
|
||||
public static void generate(){
|
||||
|
||||
ImagePacker.generate("cracks", () -> {
|
||||
RidgedPerlin r = new RidgedPerlin(1, 2);
|
||||
for(int size = 1; size <= Block.maxCrackSize; size++){
|
||||
int dim = size * 32;
|
||||
int steps = Block.crackRegions;
|
||||
for(int i = 0; i < steps; i++){
|
||||
float fract = i / (float)steps;
|
||||
|
||||
Image image = new Image(dim, dim);
|
||||
for(int x = 0; x < dim; x++){
|
||||
for(int y = 0; y < dim; y++){
|
||||
float dst = Mathf.dst((float)x/dim, (float)y/dim, 0.5f, 0.5f) * 2f;
|
||||
if(dst < 1.2f && r.getValue(x, y, 1f / 40f) - dst*(1f-fract) > 0.16f){
|
||||
image.draw(x, y, Color.WHITE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Image output = new Image(image.width, image.height);
|
||||
int rad = 3;
|
||||
|
||||
//median filter
|
||||
for(int x = 0; x < output.width; x++){
|
||||
for(int y = 0; y < output.height; y++){
|
||||
int whites = 0, clears = 0;
|
||||
for(int cx = -rad; cx < rad; cx++){
|
||||
for(int cy = -rad; cy < rad; cy++){
|
||||
int wx = Mathf.clamp(cx + x, 0, output.width - 1), wy = Mathf.clamp(cy + y, 0, output.height - 1);
|
||||
Color color = image.getColor(wx, wy);
|
||||
if(color.a > 0.5f){
|
||||
whites ++;
|
||||
}else{
|
||||
clears ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
output.draw(x, y, whites >= clears ? Color.WHITE : Color.CLEAR);
|
||||
}
|
||||
}
|
||||
|
||||
output.save("cracks-" + size + "-" + i);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ImagePacker.generate("block-icons", () -> {
|
||||
Image colors = new Image(256, 1);
|
||||
Color outlineColor = new Color(0, 0, 0, 0.3f);
|
||||
@@ -54,8 +100,8 @@ public class Generators{
|
||||
GenRegion region = (GenRegion)regions[regions.length - 1];
|
||||
Image base = ImagePacker.get(region);
|
||||
Image out = last = new Image(region.getWidth(), region.getHeight());
|
||||
for(int x = 0; x < out.width(); x++){
|
||||
for(int y = 0; y < out.height(); y++){
|
||||
for(int x = 0; x < out.width; x++){
|
||||
for(int y = 0; y < out.height; y++){
|
||||
|
||||
Color color = base.getColor(x, y);
|
||||
out.draw(x, y, color);
|
||||
@@ -105,22 +151,22 @@ public class Generators{
|
||||
image.save("../editor/" + block.name + "-icon-editor");
|
||||
|
||||
for(Icon icon : Icon.values()){
|
||||
if(icon.size == 0 || (icon.size == image.width() && icon.size == image.height())) continue;
|
||||
if(icon.size == 0 || (icon.size == image.width && icon.size == image.height)) continue;
|
||||
Image scaled = new Image(icon.size, icon.size);
|
||||
scaled.drawScaled(image);
|
||||
scaled.save(block.name + "-icon-" + icon.name());
|
||||
}
|
||||
|
||||
Color average = new Color();
|
||||
for(int x = 0; x < image.width(); x++){
|
||||
for(int y = 0; y < image.height(); y++){
|
||||
for(int x = 0; x < image.width; x++){
|
||||
for(int y = 0; y < image.height; y++){
|
||||
Color color = image.getColor(x, y);
|
||||
average.r += color.r;
|
||||
average.g += color.g;
|
||||
average.b += color.b;
|
||||
}
|
||||
}
|
||||
average.mul(1f / (image.width() * image.height()));
|
||||
average.mul(1f / (image.width * image.height));
|
||||
if(block instanceof Floor){
|
||||
average.mul(0.8f);
|
||||
}else{
|
||||
@@ -142,7 +188,7 @@ public class Generators{
|
||||
for(Item item : content.items()){
|
||||
Image base = ImagePacker.get("item-" + item.name);
|
||||
for(Item.Icon icon : Item.Icon.values()){
|
||||
if(icon.size == base.width()) continue;
|
||||
if(icon.size == base.width) continue;
|
||||
Image image = new Image(icon.size, icon.size);
|
||||
image.drawScaled(base);
|
||||
image.save("item-" + item.name + "-" + icon.name(), false);
|
||||
@@ -164,7 +210,7 @@ public class Generators{
|
||||
image.drawCenter(mech.region);
|
||||
}
|
||||
|
||||
int off = image.width() / 2 - mech.weapon.region.getWidth() / 2;
|
||||
int off = image.width / 2 - mech.weapon.region.getWidth() / 2;
|
||||
|
||||
image.draw(mech.weapon.region, -(int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, false, false);
|
||||
image.draw(mech.weapon.region, (int)mech.weaponOffsetX + off, (int)mech.weaponOffsetY + off, true, false);
|
||||
@@ -188,8 +234,8 @@ public class Generators{
|
||||
|
||||
for(boolean b : Mathf.booleans){
|
||||
image.draw(type.weapon.region,
|
||||
(int)(Mathf.sign(b) * type.weapon.width / Draw.scl + image.width() / 2 - type.weapon.region.getWidth() / 2),
|
||||
(int)(type.weaponOffsetY / Draw.scl + image.height() / 2f - type.weapon.region.getHeight() / 2f),
|
||||
(int)(Mathf.sign(b) * type.weapon.width / Draw.scl + image.width / 2 - type.weapon.region.getWidth() / 2),
|
||||
(int)(type.weaponOffsetY / Draw.scl + image.height / 2f - type.weapon.region.getHeight() / 2f),
|
||||
b, false);
|
||||
}
|
||||
|
||||
@@ -206,10 +252,10 @@ public class Generators{
|
||||
Image image = new Image(32, 32);
|
||||
Image shadow = ImagePacker.get(item.name + (i + 1));
|
||||
|
||||
int offset = image.width() / tilesize;
|
||||
int offset = image.width / tilesize;
|
||||
|
||||
for(int x = 0; x < image.width(); x++){
|
||||
for(int y = offset; y < image.height(); y++){
|
||||
for(int x = 0; x < image.width; x++){
|
||||
for(int y = offset; y < image.height; y++){
|
||||
Color color = shadow.getColor(x, y - offset);
|
||||
|
||||
//draw semi transparent background
|
||||
@@ -246,11 +292,11 @@ public class Generators{
|
||||
try{
|
||||
Image image = ImagePacker.get(floor.generateIcons()[0]);
|
||||
Image edge = ImagePacker.get("edge-stencil-" + floor.edgeStyle);
|
||||
Image result = new Image(edge.width(), edge.height());
|
||||
Image result = new Image(edge.width, edge.height);
|
||||
|
||||
for(int x = 0; x < edge.width(); x++){
|
||||
for(int y = 0; y < edge.height(); y++){
|
||||
result.draw(x, y, edge.getColor(x, y).mul(image.getColor(x % image.width(), y % image.height())));
|
||||
for(int x = 0; x < edge.width; x++){
|
||||
for(int y = 0; y < edge.height; y++){
|
||||
result.draw(x, y, edge.getColor(x, y).mul(image.getColor(x % image.width, y % image.height)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user