Hi,
I have a 2d array containing all my map - made up of tiles. I can dig down but struggling to dig left and right as using left and right keys just moves my
player. I use W key at the moment to dig (remove a tile), but would like to be able to dig in the left right directions also…
private void removeBlock(Vector3 position, boolean bDown, boolean bLeft, boolean bRight)
{
Vector3 screenSpace = toScreenSpace(position);
int x = Math.round(screenSpace.x);
int y = Math.round(screenSpace.y);
if(bDown) y--;
if(bRight) x+=1;
if(bLeft) x-=1;
BlankEntity entity = this.worldMap.getBlock(x, y);
if(entity !=null && !entity.toString().equals("CAVE")
&& !entity.toString().equals("WATER")) {
this.worldMap.removeEntity(x, y);
}
}
The method above is meant to know if you pressed the left, right or down key, these are stored in some booleans I have set up, but they are always false.
if (Gdx.input.isKeyPressed(Input.Keys.W))
{
removeBlock(camera.position, bDown, bLeft, bRight);
}
The code above just calls the removeBlock method. What is the best way about going about removing blocks where the player ‘digs’?
Thanks