Jump to content
  • Advertisement
Sign in to follow this  
Gasimzada

Pacman game smooth movement collision against a 2D Tile Map

This topic is 1675 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!