Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Pacman game smooth movement collision against a 2D Tile Map


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Gasimzada   Members   -  Reputation: 206

Like
0Likes
Like

Posted 09 May 2014 - 08:43 AM

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.


Sponsor:

#2 NotYourAverageUser   Members   -  Reputation: 500

Like
0Likes
Like

Posted 09 May 2014 - 11:08 AM

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.



#3 Gasimzada   Members   -  Reputation: 206

Like
0Likes
Like

Posted 09 May 2014 - 01:18 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS