PDA

View Full Version : TD Grid Placement Help



Saidon
June 26th, 2007, 06:01 PM
Hi, I'm trying to make a tower defense game not unlike the one at www.handdrawngames.com (Desktop Tower Defense). All was going well until I had to figure out how to build the towers so that they "lock" to a grid. My towers are 40px by 40px and I want to build them on a grid that is made up of 20px by 20px squares so that they can be built with more variety.

A quick break down of where I need help:

1. How to select the tower I want to build and then place it by clicking on the grid

2. How to have the towers lock to a grid half the size of the towers themselves



Any advice would be greatly appreciated, I've been googling this for hours and wasn't able to figure it out.

Sirisian
June 26th, 2007, 09:09 PM
Locking to a grid is really easy actually
pos = Math.floor((mousePos+towerSize/2)/gridSize)*GridSize

nathan99
June 26th, 2007, 09:52 PM
made a class a while back
http://www.kirupa.com/forum/showpost.php?p=2091137&postcount=47

Saidon
June 27th, 2007, 10:28 AM
Thanks guys, that's exactly what I was looking for.