Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 6:58 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Selecting tiles in game
PostPosted: Sat Mar 24, 2012 11:05 pm 
Offline

Joined: Sat Jul 30, 2011 11:33 am
Posts: 60
Hey i wanted to give a shot at cloning minecraft with java in 2d so here i am got a world got a player but now how do i destroy blocks?

i thought of this if i cycle through the tiles of the map and give them polygons and when you click with the mouse it creates a polygon at the mouse position and when they intersect the tile gets removed but i have no clue how i can define with polygon and with tile is selected you know?
so how could i define with tile i am selecting/clicking?

Thanks!
Jan Vos


Top
 Profile  
 
PostPosted: Sun Mar 25, 2012 11:17 am 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
Are you using an entity framework? You could try to iterate through each tile and create an entity that the player collides with, and then destroy the entity when it collides with an 'attack' entity that your player entity spawns when you click a button. You'd have to render each one individually and just render the background with the tiledmap below everything. You could do something like tile properties where type = dirt, or stone, etc but just have the actual tile be the 'background' tile and have your entities render the blocks above the background.

I'm not sure if it would work really, but that's where I'd start.


Top
 Profile  
 
PostPosted: Sun Mar 25, 2012 11:51 am 
Offline

Joined: Sat Jul 30, 2011 11:33 am
Posts: 60
thanks for your help !

but my main problem is how would the game kows wich block to delete like when the attacker entity collides with a stone block how would i definethat only that stone block gets deletd and not every stone block ?? sorry for spelling typing this from my iphone


Top
 Profile  
 
PostPosted: Mon Mar 26, 2012 12:03 am 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
I'm using MarteEngine as an entity framework, so what I would do is go into my StoneBlock class (that extends Entity) and check if it collides with an entity of the type "pickaxe" or whatever, and then destroy(); it there (or you could just make it have hitpoints and have the collision do damage so it doesn't die instantly).


Top
 Profile  
 
PostPosted: Mon Apr 30, 2012 2:15 am 
Offline

Joined: Mon Apr 30, 2012 2:06 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group