Added block cracks
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user