PACMANCODE

PACMANCODEPACMANCODEPACMANCODE
  • Home
  • Start
    • Vectors
    • Stacks
    • Blank Screen
    • Basic Movement
  • Level 1
    • Nodes
    • Node Movement (Part 1)
    • Node Movement (Part 2)
    • Node Movement (Part 3)
  • Level 2
    • Maze Basics
    • Pacman Maze
    • Portals
    • Pellets
    • Eating Pellets
  • Level 3
    • Ghosts Intro
    • Ghost Setup
    • Ghost AI
    • Modes
    • Ghost Home
    • Freight Mode
    • Spawn Mode
  • Level 4
    • More Ghosts
    • Start Positions
    • Fruit
    • Pausing
    • Level Advancing
    • Death to Pacman
    • Node Restrictions
  • Level 5
    • Text
    • Sprites
    • Life Icons
    • Graphical Mazes
    • Graphical Mazes Part 2
    • Animate Pacman
    • Animate Ghosts
  • Final
    • Pacman Death
    • Level Flash
    • More Fruit
    • More Mazes
    • The End
  • Contact
  • More
    • Home
    • Start
      • Vectors
      • Stacks
      • Blank Screen
      • Basic Movement
    • Level 1
      • Nodes
      • Node Movement (Part 1)
      • Node Movement (Part 2)
      • Node Movement (Part 3)
    • Level 2
      • Maze Basics
      • Pacman Maze
      • Portals
      • Pellets
      • Eating Pellets
    • Level 3
      • Ghosts Intro
      • Ghost Setup
      • Ghost AI
      • Modes
      • Ghost Home
      • Freight Mode
      • Spawn Mode
    • Level 4
      • More Ghosts
      • Start Positions
      • Fruit
      • Pausing
      • Level Advancing
      • Death to Pacman
      • Node Restrictions
    • Level 5
      • Text
      • Sprites
      • Life Icons
      • Graphical Mazes
      • Graphical Mazes Part 2
      • Animate Pacman
      • Animate Ghosts
    • Final
      • Pacman Death
      • Level Flash
      • More Fruit
      • More Mazes
      • The End
    • Contact

PACMANCODE

PACMANCODEPACMANCODEPACMANCODE
  • Home
  • Start
    • Vectors
    • Stacks
    • Blank Screen
    • Basic Movement
  • Level 1
    • Nodes
    • Node Movement (Part 1)
    • Node Movement (Part 2)
    • Node Movement (Part 3)
  • Level 2
    • Maze Basics
    • Pacman Maze
    • Portals
    • Pellets
    • Eating Pellets
  • Level 3
    • Ghosts Intro
    • Ghost Setup
    • Ghost AI
    • Modes
    • Ghost Home
    • Freight Mode
    • Spawn Mode
  • Level 4
    • More Ghosts
    • Start Positions
    • Fruit
    • Pausing
    • Level Advancing
    • Death to Pacman
    • Node Restrictions
  • Level 5
    • Text
    • Sprites
    • Life Icons
    • Graphical Mazes
    • Graphical Mazes Part 2
    • Animate Pacman
    • Animate Ghosts
  • Final
    • Pacman Death
    • Level Flash
    • More Fruit
    • More Mazes
    • The End
  • Contact

Death To Pacman

Basics

Now things will start to get interesting.  No longer will Pacman be invincible, although if we're testing other aspects of the game you can still make him invincible.  What we'll do here is make Pacman die if he collides with a ghost that is not in FREIGHT or SPAWN mode.  That means a few things.

  1. When Pacman dies, the game will pause for 3 seconds.
  2. When Pacman dies the level needs to reset, except for the pellets.  
  3. We need to give Pacman some lives, say 5.  
  4. If all of those lives are lost, then the game is over.


Once this section is finished then we'll have more or less a complete game.  Just not a very good looking one.  We'll take care of that later, but for now lets kill Pacman.

Lives

We'll start by giving Pacman 5 lives.  That seems like a good number.  

Resetting

When Pacman dies we don't want to start the level over or anything, we just need to reset his position and a few other variables.  We'll also want to reset the ghosts, so let's create a basic reset method in the Entity class.  Good thing we still have a reference to the start node right?  We just place them back there.

Resetting Pacman

For Pacman, however, we'll need to do a bit more to reset him.  So let's override the basic reset method from the Entity class and add a couple more things.  We need to set Pacman's initial direction to LEFT and place him between the 2 nodes discussed previously.

Resetting Ghosts

Similar to Pacman we'll override the Entities reset method and just add a couple things.  We need to reset the points to 200 and the direction back to the goalDirection in case it's something else when Pacman dies.  I guess it can't be anything else at this point, but including it won't hurt.

Finally, in the checkGhostEvents method when we detect that Pacman has collided with a ghost, if the ghost is not in FREIGHT mode we check to see if it is in SPAWN mode.  If it is then we can safely ignore, but if not we need to kill Pacman.


So we reduce his number of lives by 1 then we check to see if he has any more lives left.  If not then we restart the game.  If he has lives left then we just reset the game.  In both cases we'll pause for 3 seconds before calling the respective methods.

We need to make sure that we can't pause the game while Pacman is dying.  Pacman takes a few seconds to die, so right now it would be possible to pause the game while he is dying and then there would be no way to advance to the next level with the way things are.  So we'll add this check to make sure we can only pause the game while Pacman is alive.

Well, that's pretty good so far right?  We pretty much have a full game on our hands now.  We have a starting point and ways to win and lose.  It just doesn't look very good.  I think it's time to add some pizzaz!  

Downloads

6-Death_To_Pacman (zip)Download

Copyright © 2024 Pacmancode - All Rights Reserved.


Powered by GoDaddy Website Builder