Added block cracks

This commit is contained in:
Anuken
2019-04-16 12:15:06 -04:00
parent 5b8084e1fa
commit b9db5ad662
23 changed files with 7376 additions and 6677 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 501 B

After

Width:  |  Height:  |  Size: 500 B

File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 KiB

After

Width:  |  Height:  |  Size: 280 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

File diff suppressed because it is too large Load Diff
Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 KiB

After

Width:  |  Height:  |  Size: 134 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 235 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 522 KiB

After

Width:  |  Height:  |  Size: 385 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 337 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 KiB

After

Width:  |  Height:  |  Size: 346 KiB

@@ -5,13 +5,10 @@ import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Events;
import io.anuke.arc.collection.Array;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.math.Mathf;
import io.anuke.arc.math.geom.Point2;
import io.anuke.arc.math.geom.Vector2;
import io.anuke.arc.util.Interval;
import io.anuke.arc.util.Time;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.entities.Effects;
import io.anuke.mindustry.entities.EntityGroup;
import io.anuke.mindustry.entities.bullet.Bullet;
import io.anuke.mindustry.entities.impl.BaseEntity;
@@ -21,7 +18,6 @@ import io.anuke.mindustry.game.EventType.BlockDestroyEvent;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.world.*;
import io.anuke.mindustry.world.blocks.defense.Wall;
import io.anuke.mindustry.world.modules.*;
import java.io.*;
@@ -265,10 +261,10 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
@Override
public void update(){
//TODO better smoke effect, this one is awful
if(health != 0 && health < block.health && !(block instanceof Wall) &&
/*if(health != 0 && health < block.health && !(block instanceof Wall) &&
Mathf.chance(0.009f * Time.delta() * (1f - health / block.health))){
Effects.effect(Fx.smoke, x + Mathf.range(4), y + Mathf.range(4));
}
}*/
timeScaleDuration -= Time.delta();
if(timeScaleDuration <= 0f || !block.canOverdrive){
@@ -234,6 +234,9 @@ public class BlockRenderer{
if(req.layer == Layer.block){
block.draw(req.tile);
if(req.tile.entity != null && req.tile.entity.damaged()){
block.drawCracks(req.tile);
}
if(block.synthetic() && req.tile.getTeam() != player.getTeam()){
block.drawTeam(req.tile);
}
@@ -34,6 +34,8 @@ import java.util.Arrays;
import static io.anuke.mindustry.Vars.*;
public class Block extends BlockStorage{
public static final int crackRegions = 8, maxCrackSize = 5;
/** whether this block has a tile entity that updates */
public boolean update;
/** whether this block has health and can be destroyed */
@@ -113,6 +115,8 @@ public class Block extends BlockStorage{
protected TextureRegion[] variantRegions, editorVariantRegions;
protected TextureRegion region, editorIcon;
protected static TextureRegion[][] cracks;
/** Dump timer ID.*/
protected final int timerDump = timers++;
/** How often to try dumping items in ticks, e.g. 5 = 12 times/sec*/
@@ -202,6 +206,15 @@ public class Block extends BlockStorage{
public void drawLayer2(Tile tile){
}
public void drawCracks(Tile tile){
if(!tile.entity.damaged()) return;
int id = tile.pos();
TextureRegion region = cracks[size - 1][Mathf.clamp((int)((1f - tile.entity.healthf()) * crackRegions), 0, crackRegions-1)];
Draw.colorl(0.1f, 0.1f + (1f - tile.entity.healthf())* 0.7f);
Draw.rect(region, tile.drawx(), tile.drawy(), (id%4)*90);
Draw.color();
}
/** Draw the block overlay that is shown when a cursor is over the block. */
public void drawSelect(Tile tile){
}
@@ -333,6 +346,15 @@ public class Block extends BlockStorage{
for(int i = 0; i < cacheRegions.length; i++){
cacheRegions[i] = Core.atlas.find(cacheRegionStrings.get(i));
}
if(cracks == null){
cracks = new TextureRegion[maxCrackSize][crackRegions];
for(int size = 1; size <= maxCrackSize; size++){
for(int i = 0; i < crackRegions; i++){
cracks[size - 1][i] = Core.atlas.find("cracks-" + size + "-" + i);
}
}
}
}
/** Adds a region by name to be loaded, with the final name "{name}-suffix". Returns an ID to looks this region up by in {@link #reg(int)}. */
@@ -88,6 +88,9 @@ public class Drill extends Block{
topRegion = Core.atlas.find(name + "-top");
}
@Override
public void drawCracks(Tile tile){}
@Override
public void draw(Tile tile){
float s = 0.3f;
@@ -96,6 +99,7 @@ public class Drill extends Block{
DrillEntity entity = tile.entity();
Draw.rect(region, tile.drawx(), tile.drawy());
super.drawCracks(tile);
if(drawRim){
Draw.color(heatColor);
@@ -36,11 +36,15 @@ public class Fracker extends SolidPump{
topRegion = Core.atlas.find(name + "-top");
}
@Override
public void drawCracks(Tile tile){}
@Override
public void draw(Tile tile){
FrackerEntity entity = tile.entity();
Draw.rect(region, tile.drawx(), tile.drawy());
super.drawCracks(tile);
Draw.color(result.color);
Draw.alpha(tile.entity.liquids.get(result) / liquidCapacity);
+1 -3
View File
@@ -24,14 +24,12 @@ def antialias = { File file ->
}
def color = new Color()
def color2 = new Color()
def sum = new Color()
def suma = new Color()
for(int x = 0; x < image.getWidth(); x++){
for(int y = 0; y < image.getHeight(); y++){
int A =
getRGB(x - 1, y + 1),
int A = getRGB(x - 1, y + 1),
B = getRGB(x, y + 1),
C = getRGB(x + 1, y + 1),
D = getRGB(x - 1, y),
+63 -17
View File
@@ -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)));
}
}
+9 -13
View File
@@ -19,6 +19,8 @@ class Image{
private Graphics2D graphics;
private Color color = new Color();
public final int width, height;
Image(TextureRegion region){
this(ImagePacker.buf(region));
}
@@ -27,6 +29,8 @@ class Image{
this.image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_ARGB);
this.graphics = image.createGraphics();
this.graphics.drawImage(src, 0, 0, null);
this.width = image.getWidth();
this.height = image.getHeight();
toDispose.add(this);
}
@@ -35,16 +39,8 @@ class Image{
this(new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB));
}
int width(){
return image.getWidth();
}
int height(){
return image.getHeight();
}
boolean isEmpty(int x, int y){
if(!Structs.inBounds(x, y, width(), height())){
if(!Structs.inBounds(x, y, width, height)){
return true;
}
Color color = getColor(x, y);
@@ -52,7 +48,7 @@ class Image{
}
Color getColor(int x, int y){
if(!Structs.inBounds(x, y, width(), height())) return color.set(0, 0, 0, 0);
if(!Structs.inBounds(x, y, width, height)) return color.set(0, 0, 0, 0);
int i = image.getRGB(x, y);
Color.argb8888ToColor(color, i);
return color;
@@ -70,16 +66,16 @@ class Image{
/** Draws a region at the center. */
void drawCenter(TextureRegion region){
draw(region, (width() - region.getWidth()) / 2, (height() - region.getHeight()) / 2, false, false);
draw(region, (width - region.getWidth()) / 2, (height - region.getHeight()) / 2, false, false);
}
/** Draws a region at the center. */
void drawCenter(TextureRegion region, boolean flipx, boolean flipy){
draw(region, (width() - region.getWidth()) / 2, (height() - region.getHeight()) / 2, flipx, flipy);
draw(region, (width - region.getWidth()) / 2, (height - region.getHeight()) / 2, flipx, flipy);
}
void drawScaled(Image image){
graphics.drawImage(image.image.getScaledInstance(width(), height(), java.awt.Image.SCALE_AREA_AVERAGING), 0, 0, width(), height(), null);
graphics.drawImage(image.image.getScaledInstance(width, height, java.awt.Image.SCALE_AREA_AVERAGING), 0, 0, width, height, null);
}
/** Draws an image at the top left corner. */