Followers 0

Pacman game smooth movement collision against a 2D Tile Map

2 posts in this topic

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?

0

Share on other sites

looks like you are not taking into the pacman's radius.  If you offset him by his radius in the opposite direction of his previous movement he will collide with the wall and not penetrate it.

0

Share on other sites

Do I offset that while generating the new position or while checking the collision?

0

Create an account

Register a new account