|
I select tiles by having a world origin at 0,0 and then setting an offset of the tile size in pixels. Each map has a width and a height of x and y tiles and are connected. A user clicks on a given location in the world and based on the position of the world origin (it moves instead of the player), and mouse click relative to the map origin I can figure out which tile it is. I move the world origin as the user moves through the world and the user is simply in the center of the screen. User position is described by the position of the worldOrigin. If you divided the current position by map width and map height you can get which map you're on. If you divide that by tile size you can get the x and y coordinate for the given map. Needless to say, I use a lot of 2d arrays.
To find out which block a player is attacking just find their current map, their current tile position and the direction they're facing. When the user destroys the block's durability, flag that location in the 2d array as an empty sprite and it won't be drawn anymore when you iterate through and draw the tiles. Each time the player hits the block, check the block's hp. If it's less than zero you know to set the sprite to null or whatever and the problem is done.
|