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

Fruit

Basics

The fruit is a fairly simple concept.  It's just an object that appears at a certain time during the level.  If Pacman collides with it then he gets points.  If Pacman does not collide with it within a certain time period, then the fruit disappears.  The fruit appears twice during each level.  The fruit may be different for each successive level and worth more and more points capping out at some value.  In the Ms. Pacman games, the fruit hopped around the maze along a certain path and would enter the maze via one portal and leave via the other portal. For now we'll just have the fruit stationary.  


The location of the fruit depends on the maze.  For this maze the fruit appears directly below the ghost home.  As you can see in the picture, the fruit is the green circle.   The nodes that it appears between are located at (9, 20) and (18, 20).  


When Pacman eats a fruit, it appears in the lower right corner of the screen as well.

Constants

To define the fruit, we need to add these to constants to the constants.py file.  We'll make our fruit green and give it a value of 8.  The value doesn't matter, the last one we used was 7, so 8 is next.  They just have to be unique.

Fruit Class

We are going to create a new file called fruit.py and create this class inside that file. This is so far very simple. When we create a fruit object we just place that fruit object between two nodes. But how and when do we create this fruit object you may ask? Well read on!

  

Our Fruit object will inherit Entity just like Pacman and the ghosts do. The fruit isn't navigating the maze like them though. But, maybe they will.


A fruit has a lifespan of 5 seconds.  That means if Pacman doesn't eat the fruit within that time limit, the fruit will disappear.  So we need to keep track of how much time has passed since the fruit was created.  The update method keeps track of that.

Between nodes

Add this so we can set any entity between 2 nodes.  It is assumed that the entity already has it's node defined.  You just need to supply a direction where the second node should be.  Then we just find the position between those 2 nodes.  We can use this for Pacman as well since he starts between 2 nodes.

Pacman between nodes

We'll use that method to place Pacman between the two nodes.  

GameController

Finally we make the necessary changes in the GameController class in the run.py file.  We import the Fruit class, give it an initial value of None.  Because our fruit object can have a value of None, we check to make sure it is not None before we try to update it.


We'll have a new method similar to the pellet and ghost methods where we place most of the fruit related events.  Here we can check to see if Pacman has eaten 50 or 140 pellets.  When either of those occurs, we create a Fruit object.  Then we need to check to see when and if we can make the fruit object None again.   

Downloads

3-Fruit (zip)Download

Copyright © 2024 Pacmancode - All Rights Reserved.


Powered by GoDaddy Website Builder