This is my first time working on a Pacman game and I have come to a difficulty that has stopped me from being able to go further in my project. My Objects (Pacman and Ghosts) were moving too fast, so I thought I would add time based movement for them but I can't get the collision working quite right. Here is my TileMap:
// 1 -> Wall, 0 -> Empty, 6 -> Base Gate, 2 -> Base, 7 -> Portal, 5 -> Pacman Start position [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], [1,4,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,4,1], [1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1], [1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1], [1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,1,1,1,1,0,1,1,1,1,1,1,0,1,1,1,1,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1], [1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1], [1,0,1,0,0,0,0,1,1,6,6,1,1,0,0,0,0,1,0,1], [7,0,0,0,0,0,0,1,2,2,2,2,1,0,0,0,0,0,0,7], [1,0,1,0,0,1,0,1,1,1,1,1,1,0,1,0,0,1,0,1], [1,0,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1], [1,0,1,0,1,1,1,1,0,1,1,0,1,1,1,1,0,1,0,1], [1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1], [1,0,1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,1], [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,1], [1,0,1,1,1,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1], [1,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
Here is the update code: http://ideone.com/SRIymz
EDIT: I couldn't embed the code in this editor. After 4 failures, I added a link; sorry about that.
Here is the full source code with the demo: http://projects.gasimzada.net/pacman/dev
I want to make the pacman to be at the center with regard to the other plane. So if the pacman is moving in direction UP and DOWN. I want the pacman to be center in LEFT-RIGHT direction. Also, If I hit a wall, I need it to stay at one tile behind it instead of getting inside the walls. I know it has something to do with the Game.roundPos but cannot figure out how to implement it. Any advice will be appreciated? What other methods can I use to round the position to the next correct tile?
Thank you for your time!
Edited by Gasimzada, 09 May 2014 - 08:48 AM.