Hi friends,

i got one query and would like to share with you, working on a tower defense type game. A while ago I posted asking about maze logic and was kindly directed towards A-star pathfinding. It is perfect. I understand the concept and it makes sense. Now the problem I am having is how to do the tile-based map?

I'm having a hard time wrapping my head around it. I just want to do a straight square map comprised of squares. I realize a 2D Array would probably be the best way just such as:

int[][] map = new int[100][100]

where would be 100 x 100 tiles. I can then populate the array with numbers ie 0 = walkable, 1 = unwalkable. I can have my A* algorithm return the set of tiles to move to.

My problem is that I don't want my game to be in pixels and I'm having a hard time understanding how to make the game appear tile based and large enough to be playable? ie. 1

tile = 30x30 pixels. If we are looking at it in terms of model and view, I understand the model part, but I am having a hard time translating to the view? How do I create a tile based view so that the user can only place towers on a tile(the mouse click location could be any point inside the tile)?

Also, how would I keep the enemy units moving smoothly
between tiles and not just jumping to the center of each tile?

your answers would be greatly appreciated.

Thanks
Jay

Not sure what exactly the problem is with the tiles? From what I can work out, you've already got a 2D layout, correct? Which is what you -wanted- in the first place, so what's the problem? If you're asking how to make it so that towers can only be placed in tiles, easy -- just code it that way? I'm not wholly sure what you're having trouble with, but if you mean how to have some tiles able to place a tower upon it and some -unable- to have a tower placed on it, then just do the same thing as for walkable.

As for moving smoothly between the tiles, just have the x and y values of the enemies/creeps incrementing or decrementing until they reach the intended square, then resume with that until they reach the end of their path altogether.

SS

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.