New breaking animation and colors
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package io.anuke.mindustry.content.fx;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Colors;
|
||||
import io.anuke.ucore.core.Effects.Effect;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
@@ -17,15 +16,16 @@ public class Fx{
|
||||
none = new Effect(0, 0f, e->{}),
|
||||
|
||||
placeBlock = new Effect(16, e -> {
|
||||
Draw.color("accent");
|
||||
Lines.stroke(3f - e.fin() * 2f);
|
||||
Lines.square(e.x, e.y, tilesize / 2f * (float)(e.data) + e.fin() * 3f);
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
breakBlock = new Effect(12, e -> {
|
||||
Lines.stroke(2f);
|
||||
Draw.color(Color.WHITE, Colors.get("break"), e.fin());
|
||||
Lines.spikes(e.x, e.y, e.fin() * 6f, 2, 5, 90);
|
||||
Draw.color("break");
|
||||
Lines.stroke(3f - e.fin() * 2f);
|
||||
Lines.square(e.x, e.y, tilesize / 2f * (float)(e.data) + e.fin() * 3f);
|
||||
Draw.reset();
|
||||
}),
|
||||
|
||||
|
||||
@@ -31,8 +31,10 @@ public class NetCommon extends Module {
|
||||
});
|
||||
|
||||
Net.handle(BlockTapPacket.class, (packet) -> {
|
||||
Player player = playerGroup.getByID(packet.player);
|
||||
|
||||
Tile tile = world.tile(packet.position);
|
||||
threads.run(() -> tile.block().tapped(tile));
|
||||
threads.run(() -> tile.block().tapped(tile, player));
|
||||
});
|
||||
|
||||
Net.handle(BlockConfigPacket.class, (packet) -> {
|
||||
|
||||
@@ -210,8 +210,6 @@ public class Renderer extends RendererModule{
|
||||
blocks.drawBlocks(Layer.placement);
|
||||
Graphics.shader();
|
||||
|
||||
Entities.drawWith(playerGroup, p -> true, Player::drawBuildRequests);
|
||||
|
||||
blocks.drawBlocks(Layer.overlay);
|
||||
|
||||
drawAllTeams(false);
|
||||
@@ -219,6 +217,8 @@ public class Renderer extends RendererModule{
|
||||
blocks.skipLayer(Layer.turret);
|
||||
blocks.drawBlocks(Layer.laser);
|
||||
|
||||
Entities.drawWith(playerGroup, p -> true, Player::drawBuildRequests);
|
||||
|
||||
drawAllTeams(true);
|
||||
|
||||
Entities.draw(bulletGroup);
|
||||
|
||||
@@ -106,9 +106,8 @@ public class UI extends SceneModule{
|
||||
Colors.put("interact", Color.ORANGE);
|
||||
Colors.put("accent", Color.valueOf("f4ba6e"));
|
||||
Colors.put("place", Color.valueOf("6335f8"));
|
||||
Colors.put("placeInvalid", Color.RED);
|
||||
Colors.put("break", Color.valueOf("fb6363"));
|
||||
Colors.put("placeRotate", Color.ORANGE);
|
||||
Colors.put("break", Color.CORAL);
|
||||
Colors.put("breakStart", Color.YELLOW);
|
||||
Colors.put("breakInvalid", Color.SCARLET);
|
||||
Colors.put("range", Colors.get("accent"));
|
||||
|
||||
@@ -36,6 +36,11 @@ public interface BlockBuilder {
|
||||
|
||||
/**Add another build requests to the tail of the queue.*/
|
||||
default void addBuildRequest(BuildRequest place){
|
||||
for(BuildRequest request : getPlaceQueue()){
|
||||
if(request.x == place.x && request.y == place.y){
|
||||
return;
|
||||
}
|
||||
}
|
||||
getPlaceQueue().addLast(place);
|
||||
}
|
||||
|
||||
@@ -76,9 +81,10 @@ public interface BlockBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
current.removeProgress += progress;
|
||||
current.progress += progress;
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(tile.drawx(), tile.drawy()), 0.4f);
|
||||
|
||||
if(current.removeProgress >= 1f){
|
||||
if(current.progress >= 1f){
|
||||
Build.breakBlock(unit.team, current.x, current.y, true, true);
|
||||
}
|
||||
}else{
|
||||
@@ -107,6 +113,7 @@ public interface BlockBuilder {
|
||||
|
||||
entity.addProgress(core.items, 1f / entity.recipe.cost);
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
|
||||
getCurrentRequest().progress = entity.progress();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +122,7 @@ public interface BlockBuilder {
|
||||
default void drawBuilding(Unit unit){
|
||||
Tile tile = world.tile(getCurrentRequest().x, getCurrentRequest().y);
|
||||
|
||||
Draw.color(unit.distanceTo(tile) > placeDistance ? "placeInvalid" : "accent");
|
||||
Draw.color(unit.distanceTo(tile) > placeDistance || getCurrentRequest().remove ? "break" : "accent");
|
||||
float focusLen = 3.8f + Mathf.absin(Timers.time(), 1.1f, 0.6f);
|
||||
float px = unit.x + Angles.trnsx(unit.rotation, focusLen);
|
||||
float py = unit.y + Angles.trnsy(unit.rotation, focusLen);
|
||||
@@ -146,7 +153,7 @@ public interface BlockBuilder {
|
||||
Lines.line(px, py, x1, y1);
|
||||
Lines.line(px, py, x3, y3);
|
||||
|
||||
Fill.circle(px, py, 1.5f + Mathf.absin(Timers.time(), 1f, 1.8f));
|
||||
Fill.circle(px, py, 1.6f + Mathf.absin(Timers.time(), 0.8f, 1.5f));
|
||||
|
||||
Draw.color();
|
||||
}
|
||||
@@ -157,7 +164,7 @@ public interface BlockBuilder {
|
||||
public final Recipe recipe;
|
||||
public final boolean remove;
|
||||
|
||||
float removeProgress;
|
||||
float progress;
|
||||
float[] removeAccumulator;
|
||||
|
||||
/**This creates a build request.*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Pools;
|
||||
@@ -23,6 +24,7 @@ import io.anuke.mindustry.world.blocks.types.Floor;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.entities.SolidEntity;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.graphics.Fill;
|
||||
import io.anuke.ucore.graphics.Lines;
|
||||
import io.anuke.ucore.util.*;
|
||||
|
||||
@@ -243,18 +245,37 @@ public class Player extends Unit implements BlockBuilder {
|
||||
public void drawBuildRequests(){
|
||||
for (BuildRequest request : getPlaceQueue()) {
|
||||
if(request.remove){
|
||||
Draw.color("placeInvalid");
|
||||
Draw.color("break");
|
||||
Draw.alpha(0.4f);
|
||||
Lines.stroke(1f);
|
||||
|
||||
float progress = request.progress;
|
||||
Tile tile = world.tile(request.x, request.y);
|
||||
float size = tile.block().size * tilesize/2f;
|
||||
float ss = -(progress*2f-1f);
|
||||
|
||||
for(int i = 0; i < 4; i ++){
|
||||
GridPoint2 p = Geometry.d8edge(i);
|
||||
|
||||
Fill.tri(tile.drawx() + size*p.x, tile.drawy() + size * p.y,
|
||||
tile.drawx() + size*p.x*ss, tile.drawy() + size * p.y,
|
||||
tile.drawx() + size*p.x, tile.drawy() + size * p.y*ss);
|
||||
}
|
||||
|
||||
Draw.alpha(1f);
|
||||
|
||||
Lines.poly(tile.drawx(), tile.drawy(),
|
||||
4, tile.block().size * tilesize /2f + Mathf.absin(Timers.time(), 3f, 1f));
|
||||
4, tile.block().size * tilesize /2f * (1f-progress) + Mathf.absin(Timers.time(), 3f, 1f));
|
||||
}else{
|
||||
Draw.color("accent");
|
||||
Lines.stroke((1f-request.progress));
|
||||
Lines.poly(request.x * tilesize + request.recipe.result.getPlaceOffset().x,
|
||||
request.y * tilesize + request.recipe.result.getPlaceOffset().y,
|
||||
4, request.recipe.result.size * tilesize /2f + Mathf.absin(Timers.time(), 3f, 1f));
|
||||
}
|
||||
}
|
||||
|
||||
Draw.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -84,7 +84,7 @@ public class AndroidInput extends InputHandler{
|
||||
}
|
||||
|
||||
if(linked != null) {
|
||||
linked.block().tapped(linked);
|
||||
linked.block().tapped(linked, player);
|
||||
if(Net.active()) NetEvents.handleBlockTap(linked);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
}
|
||||
|
||||
target.block().tapped(target);
|
||||
target.block().tapped(target, player);
|
||||
if(Net.active()) NetEvents.handleBlockTap(target);
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,9 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
public void breakBlock(int x, int y){
|
||||
|
||||
//todo multiplayer support
|
||||
player.addBuildRequest(new BuildRequest(x, y));
|
||||
Tile tile = world.tile(x, y).target();
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public enum PlaceMode{
|
||||
|
||||
float si = MathUtils.sin(Timers.time() / 6f) + 1.5f;
|
||||
|
||||
Draw.color(valid ? Colors.get("place") : Colors.get("placeInvalid"));
|
||||
Draw.color(valid ? Colors.get("place") : Colors.get("break"));
|
||||
Lines.stroke(2f);
|
||||
Lines.crect(x + offset.x, y + offset.y, tilesize * input.recipe.result.size + si,
|
||||
tilesize * input.recipe.result.size + si);
|
||||
@@ -189,7 +189,6 @@ public enum PlaceMode{
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
input.tryDeleteBlock(cx, cy);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +280,7 @@ public enum PlaceMode{
|
||||
int wx = tilex + px * Mathf.sign(endx - tilex),
|
||||
wy = tiley + py * Mathf.sign(endy - tiley);
|
||||
if(!Build.validPlace(input.player.team, wx, wy, block, rotation)){
|
||||
Draw.color("placeInvalid");
|
||||
Draw.color("break");
|
||||
}else{
|
||||
Draw.color("accent");
|
||||
}
|
||||
|
||||
@@ -417,7 +417,8 @@ public class Packets {
|
||||
}
|
||||
|
||||
public static class BlockTapPacket implements Packet{
|
||||
public int position;
|
||||
public int position, player;
|
||||
//todo implement
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.entities.effect.DamageArea;
|
||||
@@ -148,7 +149,7 @@ public class Block extends BaseBlock {
|
||||
|
||||
}
|
||||
|
||||
public void tapped(Tile tile){}
|
||||
public void tapped(Tile tile, Player player){}
|
||||
public void buildTable(Tile tile, Table table) {}
|
||||
public void configure(Tile tile, byte data){}
|
||||
|
||||
|
||||
@@ -30,17 +30,16 @@ public class Build {
|
||||
//todo add break results to core inventory
|
||||
|
||||
if(sound) Effects.sound("break", x * tilesize, y * tilesize);
|
||||
if(effect) Effects.effect(Fx.breakBlock, tile.drawx(), tile.drawy(), 0f, (float)block.size);
|
||||
|
||||
if(!tile.block().isMultiblock() && !tile.isLinked()){
|
||||
tile.setBlock(Blocks.air);
|
||||
if(effect) Effects.effect(Fx.breakBlock, tile.worldx(), tile.worldy());
|
||||
}else{
|
||||
Tile target = tile.isLinked() ? tile.getLinked() : tile;
|
||||
Array<Tile> removals = target.getLinkedTiles(tempTiles);
|
||||
for(Tile toremove : removals){
|
||||
//note that setting a new block automatically unlinks it
|
||||
toremove.setBlock(Blocks.air);
|
||||
if(effect) Effects.effect(Fx.breakBlock, toremove.worldx(), toremove.worldy());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.Colors;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import io.anuke.mindustry.content.fx.ExplosionFx;
|
||||
import io.anuke.mindustry.content.fx.Fx;
|
||||
import io.anuke.mindustry.entities.BlockBuilder.BuildRequest;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Rubble;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
@@ -31,6 +33,14 @@ public class BuildBlock extends Block {
|
||||
layer = Layer.placement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tapped(Tile tile, Player player) {
|
||||
BuildEntity entity = tile.entity();
|
||||
|
||||
player.clearBuilding();
|
||||
player.addBuildRequest(new BuildRequest(tile.x, tile.y, tile.getRotation(), entity.recipe));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBars(){
|
||||
bars.replace(new BlockBar(BarType.health, true, tile -> (float)tile.<BuildEntity>entity().progress));
|
||||
@@ -133,6 +143,10 @@ public class BuildBlock extends Block {
|
||||
updated = true;
|
||||
}
|
||||
|
||||
public float progress(){
|
||||
return (float)progress;
|
||||
}
|
||||
|
||||
public void set(Recipe recipe){
|
||||
updated = true;
|
||||
this.recipe = recipe;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.world.blocks.types.defense;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Units;
|
||||
import io.anuke.mindustry.content.fx.BlockFx;
|
||||
@@ -47,7 +48,7 @@ public class Door extends Wall{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tapped(Tile tile){
|
||||
public void tapped(Tile tile, Player player){
|
||||
DoorEntity entity = tile.entity();
|
||||
|
||||
if(anyEntities(tile) && entity.open){
|
||||
|
||||
Reference in New Issue
Block a user