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

Start Positions

Basics

If you play the game now you'll notice that Pacman and all of the ghosts start the game in the upper left corner.  The ghosts will start by going to their respective corners of the maze and then begin the whole SCATTER/CHASE phases.  If Pacman eats a power pellet and then touches one of the ghosts, that ghost will quickly return to the ghost home.


What we want to do in this section is to define the starting positions of the ghosts and Pacman.  Refer to the image on the right.

  1. Blinky starts directly above the ghost home.  In other words, the entrance to the ghost home.
  2. Pinky starts directly below Blinky inside of the ghost home, where the ghost spawn node is.
  3. Inky starts to the left of Pinky inside of the ghost home. 
  4. Clyde starts to the right of Pinky inside of the ghost home. 
  5. Pacman starts below the ghost home.  Pacman is the only one that doesn't actually start directly on a node, but rather between 2 nodes.


Pacman Start

So the reason that Pacman and the ghosts all start on the upper left corner node is because that's the node we're passing in when we create their objects.  All we really have to do is pass in the correct nodes.  We just have to know where they are.  It's helpful to refer to the maze1.txt file and the homedata array in the NodeGroup class.


We already have a method in the NodeGroup class that will return the correct node if we pass in its coordinates.  So, it's just a matter of knowing the coordinates for a particular maze.  We'll explore better ways in a bit, but for now these are the coordinates for all of the starting positions. (Remember that all nodes are in (x, y) or (column, row) format:


  • Pacman:  Starts between nodes at (12,26) and (15, 26)
  • Blinky:  Starts on node at (2, 0) of the homedata array.  Remember for all of the ghosts we have to add the offset values of (11.5, 14).  So Blinky's node is really at (2, 0) + (11.5, 14) = (13.5, 14)
  • Pinky:  Starts on node at (2, 3) of the homedata array.  Remember for all of the ghosts we have to add the offset values of (11.5, 14).  So Pinky's node is really at (2, 3) + (11.5, 14) = (13.5, 17)
  • Inky:  Starts on node at (0, 3) of the homedata array.  Remember for all of the ghosts we have to add the offset values of (11.5, 14).  So Inky's node is really at (0, 3) + (11.5, 14) = (11.5, 17)
  • Clyde:  Starts on node at (4, 3) of the homedata array.  Remember for all of the ghosts we have to add the offset values of (11.5, 14).  So Clyde's node is really at (4, 3) + (11.5, 14) = (15.5, 17)


Add these to the startGame method as shown below.  For now we'll just start Pacman directly on the node at (15, 26) to make things easier.  For the ghosts we need to create a new method where we can pass in the node data later after creating the ghosts.  


Entity Method

We'll add this method to the Entity class.  Whenever we define a starting node, we'll need to set it to node and target and then call the setPosition method.  

Pacman starting direction

You can run the game now and you'll notice that everyone starts on the nodes we want them to start on .  However, Pacman just sits there on his node until the player moves him.  Normally in a Pacman game, Pacman has some initial direction and moves in that direction on his own.  In the original game, that direction is LEFT.  So we'll simply add this line to the Pacman class to say that his initial direction is LEFT.  Now when you run the game Pacman will start moving left.

Downloads

2-Start_Positions (zip)Download

Copyright © 2024 Pacmancode - All Rights Reserved.


Powered by GoDaddy Website Builder