Pac-Man Style Maze
by Jordan Spence · in Torque Game Builder · 01/25/2007 (7:14 pm) · 4 replies
Im looking to make a pac-man clone, but I want to allow pac-man to move around more. So pac-man will have 2 to 3 rows to move around in instead of just 1. How can i make the maze and keep him clamped to a certain tile row/column so he doesn't get in between tile rows/columns?
#2
01/26/2007 (7:12 am)
Will that keep pac-man on a certain row or column? Because if you dont clamp him to a tile he won't line up correctly with the tilemap.
#3
01/26/2007 (12:18 pm)
Will "that" keep him clamped? No. You have to handle that part yourself. Constrain your pacman to moving along the center lines of each tile. This would have to be a fundamental design feature of the movement system you come up with.
#4
If so, I've done the following:
I posted my 't2dTileLayer.getTileWorldPosition()' code recently ... and here's what I do when I move my character along a tilemap to make sure they 'snap' to a tile:
Just do a quick search for the code, should be in one of my recent forum or 'blog' posts on the site (check my profile)
When the player moves, I do not set there velocity, but rather I tell them where to go -- I also enabled the 'onPositionTarget' callback, so that the player does not stop moving -- just like pac-man, you could not get him to stop in the middle of a hallway, but you could get him to stop by slamming him into a wall (like a corner or t-junction)
What I did was put a 'nextDirection' and 'nextTile' field on my mobile objects (ghosts, player, specials [banana, strawberry, cherry, etc]) -- in the onPositionTarget() callback, I simply move to the next tile in that position using simple tile math:
Which, if the player is moving left, and you pass in "4 4" ... returns "3 4" ... so I simply call "moveTo" again, using "3 4" as the tile position, and grab it's world position using the t2dTileLayer.getTileWorldPosition (which, btw, is a completely TorqueScript implementation -- C++ implementation to follow soon)
Hope this helps.
02/21/2007 (12:44 pm)
@Jordan -- are you still struggling with this issue?If so, I've done the following:
I posted my 't2dTileLayer.getTileWorldPosition()' code recently ... and here's what I do when I move my character along a tilemap to make sure they 'snap' to a tile:
%player.moveTo(tileLayer.getTileWorldPosition("3 4"));Just do a quick search for the code, should be in one of my recent forum or 'blog' posts on the site (check my profile)
When the player moves, I do not set there velocity, but rather I tell them where to go -- I also enabled the 'onPositionTarget' callback, so that the player does not stop moving -- just like pac-man, you could not get him to stop in the middle of a hallway, but you could get him to stop by slamming him into a wall (like a corner or t-junction)
What I did was put a 'nextDirection' and 'nextTile' field on my mobile objects (ghosts, player, specials [banana, strawberry, cherry, etc]) -- in the onPositionTarget() callback, I simply move to the next tile in that position using simple tile math:
function getNextTile(%tile, %direction)
{
%x = getWord(%tile, 0);
%y = getWord(%tile, 1);
switch$(%direction)
{
case "up": %x--;
case "down": %x++;
case "left": %y--;
case "right": %y++
}
return %x SPC %y;
}Which, if the player is moving left, and you pass in "4 4" ... returns "3 4" ... so I simply call "moveTo" again, using "3 4" as the tile position, and grab it's world position using the t2dTileLayer.getTileWorldPosition (which, btw, is a completely TorqueScript implementation -- C++ implementation to follow soon)
Hope this helps.
Torque Owner Ben R Vesco