Jump to content

Pacman game


non_tech_guy
 Share

Recommended Posts

Hi,

 

I read a really good article about the ghost movent in the original Pacman arcade game and thought building a Pacman game would be a great way to learn to use the awesome Phaser framework. 

 

The article can be found here - http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior

 

My question is....

Is there a way to know which side of your object has collided with the walls in your game? In my case when the ghosts collide with the walls in the game they need to make decisions on which direction to move next. 

 

Thx.

Link to comment
Share on other sites

In the collide callback, check the ghost.body.touching object to see which side is touching:

game.physics.arcade.collide(ghosts, walls, function(ghost, wall) {  if (ghost.body.touching.left) {    // ghost is touching the wall to its left  }  if (ghost.body.touching.right) {    // ghost is touching the wall to its right  }  if (ghost.body.touching.up) {    // ghost is touching the wall above  }  if (ghost.body.touching.down) {    // ghost is touching the wall below  }});

However, I think Physics may not be the best approach to a Pac-Man game, as the game is based on a grid layout. There are much more efficient and far less problematic ways to approach grid-based games and I can almost guarantee you're going to run into problems with physics in such a game, such as the ghosts getting stuck on walls and colliding with things which they shouldn't be colliding with. It'll take a bit more effort to write a manual grid-based movement and collision routine but it'll be worth it. 

Link to comment
Share on other sites

To be clear, Arcade Physics was designed with platform games, classic shoot-em-ups and other such games where freedom of movement is one of the primary concerns. It allows for developers to drop in a fairly lightweight and simple physics simulation so that stuff like gravity, velocity and basic collision detection as a result of these 'forces' can be implemented quickly. The simulation however is both fairly crude and yet also overkill in a lot of situations - and while at a glance it seems like it'd be fine for puzzle games, grid games and so on, the fact that it operates in a somewhat realistic physical way causes it to be very inappropriate for such games. Just like in the real world, chaos reigns supreme in any physical system; small deviations quickly grow, resulting in large effects over time, and cause increasingly large and seemingly illogical problems.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...