Changes to break/place system
This commit is contained in:
@@ -8,7 +8,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -33,7 +32,7 @@ public class AndroidInput extends InputHandler{
|
||||
@Override public float getCursorEndY(){ return Gdx.input.getY(0); }
|
||||
@Override public float getCursorX(){ return mousex; }
|
||||
@Override public float getCursorY(){ return mousey; }
|
||||
@Override public boolean drawPlace(){ return placing || (player.placeMode.pan && player.recipe != null); }
|
||||
@Override public boolean drawPlace(){ return (placing && !brokeBlock) || (player.placeMode.pan && player.recipe != null); }
|
||||
|
||||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||
@@ -108,26 +107,15 @@ public class AndroidInput extends InputHandler{
|
||||
|
||||
if(player.breaktime >= tile.block().breaktime){
|
||||
brokeBlock = true;
|
||||
breakBlock(tile.x, tile.y);
|
||||
breakBlock(tile.x, tile.y, true);
|
||||
player.breaktime = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int tilex, int tiley){
|
||||
if(player.recipe != null && control.hasItems(player.recipe.requirements) && validPlace(tilex, tiley, player.recipe.result)){
|
||||
|
||||
placeBlock(tilex, tiley, player.recipe.result, player.rotation, true);
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
control.removeItem(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
|
||||
if(Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
|
||||
if(player.recipe != null && Gdx.input.isTouched(0) && Mathf.near2d(lmousex, lmousey, Gdx.input.getX(0), Gdx.input.getY(0), Unit.dp.inPixels(50))
|
||||
&& !ui.hasMouse()){
|
||||
warmup += Timers.delta();
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.types.Configurable;
|
||||
@@ -110,7 +109,7 @@ public class DesktopInput extends InputHandler{
|
||||
Tile tile = cursor;
|
||||
player.breaktime += Timers.delta();
|
||||
if(player.breaktime >= tile.getBreakTime()){
|
||||
breakBlock(cursor.x, cursor.y);
|
||||
breakBlock(cursor.x, cursor.y, true);
|
||||
player.breaktime = 0f;
|
||||
}
|
||||
}else{
|
||||
@@ -118,23 +117,6 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
if(player.recipe != null &&
|
||||
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
|
||||
control.hasItems(player.recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, player.recipe.result, player.rotation, true);
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
control.removeItem(stack);
|
||||
}
|
||||
|
||||
if(!control.hasItems(player.recipe.requirements)){
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int tilex(){
|
||||
return (player.recipe != null && player.recipe.result.isMultiblock() &&
|
||||
|
||||
@@ -49,12 +49,12 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return Vector2.dst(player.x, player.y, getBlockX() * tilesize, getBlockY() * tilesize) <= placerange;
|
||||
}
|
||||
|
||||
public void tryPlaceBlock(int x, int y){
|
||||
public void tryPlaceBlock(int x, int y, boolean sound){
|
||||
if(player.recipe != null &&
|
||||
validPlace(x, y, player.recipe.result) && !ui.hasMouse() && cursorNear() &&
|
||||
Vars.control.hasItems(player.recipe.requirements)){
|
||||
|
||||
placeBlock(x, y, player.recipe.result, player.rotation, true);
|
||||
placeBlock(x, y, player.recipe.result, player.rotation, true, sound);
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
Vars.control.removeItem(stack);
|
||||
@@ -66,9 +66,9 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
}
|
||||
|
||||
public void tryDeleteBlock(int x, int y){
|
||||
public void tryDeleteBlock(int x, int y, boolean sound){
|
||||
if(cursorNear() && validBreak(x, y)){
|
||||
breakBlock(x, y);
|
||||
breakBlock(x, y, sound);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
return tile.breakable();
|
||||
}
|
||||
|
||||
public void placeBlock(int x, int y, Block result, int rotation, boolean effects){
|
||||
public void placeBlock(int x, int y, Block result, int rotation, boolean effects, boolean sound){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
//just in case
|
||||
@@ -196,10 +196,10 @@ public abstract class InputHandler extends InputAdapter{
|
||||
if(effects) Effects.effect(Fx.place, x * Vars.tilesize, y * Vars.tilesize);
|
||||
}
|
||||
|
||||
if(effects) Sounds.play("place");
|
||||
if(effects && sound) Sounds.play("place");
|
||||
}
|
||||
|
||||
public void breakBlock(int x, int y){
|
||||
public void breakBlock(int x, int y, boolean sound){
|
||||
Tile tile = world.tile(x, y);
|
||||
|
||||
if(tile == null) return;
|
||||
@@ -225,7 +225,7 @@ public abstract class InputHandler extends InputAdapter{
|
||||
}
|
||||
|
||||
//Effects.shake(3f, 1f, player);
|
||||
Sounds.play("break");
|
||||
if(sound)Sounds.play("break");
|
||||
|
||||
if(!tile.block().isMultiblock() && !tile.isLinked()){
|
||||
tile.setBlock(Blocks.air);
|
||||
|
||||
@@ -58,7 +58,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(int tilex, int tiley){
|
||||
control.getInput().tryPlaceBlock(tilex, tiley);
|
||||
control.getInput().tryPlaceBlock(tilex, tiley, true);
|
||||
}
|
||||
},
|
||||
touch{
|
||||
@@ -70,13 +70,19 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.getInput().tryPlaceBlock(x, y);
|
||||
control.getInput().tryPlaceBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
none{
|
||||
{
|
||||
delete = true;
|
||||
shown = true;
|
||||
}
|
||||
},
|
||||
holdDelete{
|
||||
{
|
||||
delete = true;
|
||||
shown = true;
|
||||
shown = false;
|
||||
}
|
||||
|
||||
public void draw(int tilex, int tiley, int endx, int endy){
|
||||
@@ -109,7 +115,7 @@ public enum PlaceMode{
|
||||
}
|
||||
|
||||
public void tapped(int x, int y){
|
||||
control.getInput().tryDeleteBlock(x, y);
|
||||
control.getInput().tryDeleteBlock(x, y, true);
|
||||
}
|
||||
},
|
||||
areaDelete{
|
||||
@@ -173,9 +179,12 @@ public enum PlaceMode{
|
||||
tilex = this.tilex; tiley = this.tiley;
|
||||
endx = this.endx; endy = this.endy;
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for(int cx = tilex; cx <= endx; cx ++){
|
||||
for(int cy = tiley; cy <= endy; cy ++){
|
||||
control.getInput().tryDeleteBlock(cx, cy);
|
||||
control.getInput().tryDeleteBlock(cx, cy, first);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -207,7 +216,7 @@ public enum PlaceMode{
|
||||
this.tiley = tiley;
|
||||
}
|
||||
},
|
||||
hold{ //TODO multiblock support!
|
||||
hold{
|
||||
int maxlen = 10;
|
||||
int tilex;
|
||||
int tiley;
|
||||
@@ -293,11 +302,13 @@ public enum PlaceMode{
|
||||
|
||||
player.rotation = this.rotation;
|
||||
|
||||
boolean first = true;
|
||||
for(int x = 0; x <= Math.abs(this.endx - this.tilex); x ++){
|
||||
for(int y = 0; y <= Math.abs(this.endy - this.tiley); y ++){
|
||||
control.getInput().tryPlaceBlock(
|
||||
tilex + x * Mathf.sign(endx - tilex),
|
||||
tiley + y * Mathf.sign(endy - tiley));
|
||||
tiley + y * Mathf.sign(endy - tiley), first);
|
||||
first = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user