constants module

The constants module defines different variables that are to be used consistently throughout the rest of the framework. When developing the assignment you are more than allowed to change some of the values in this file. For example, you could change the constants.FOOD_RADIUS and/or constants.FOOD_SPARSITY constants to help test whether or not you are placing the food in the correct location or not.


Under no circumstances should you change any of constants.STATIONARY, constants.MOVE_NORTH, constants.MOVE_SOUTH, constants.MOVE_EAST, or constants.MOVE_WEST.

These constants are being used as a “bit-masking enum” to control the movement of the view.actors.Actor instances (CitizenPac and the Ghosts). It is very important that you do not change these values, else the game mechanics will produce undefined behavior.

constants.STATIONARY = 1

Represents the stationary state of view.actors.Actor.

constants.MOVE_NORTH = 2

Represents when view.actors.Actor should move North.

constants.MOVE_SOUTH = 4

Represents when view.actors.Actor should move South.

constants.MOVE_EAST = 8

Represents when view.actors.Actor should move East.

constants.MOVE_WEST = 16

Represents when view.actors.Actor should move West.

constants.GAME_SPEED_START = 2.0

The starting speed of the game. Must always be strictly positive (\(> 0\)).

constants.gameSpeed = 2.0

The current speed of the game, initialized as constants.GAME_SPEED_START. To update the value of the game speed, call constants.setGameSpeed().

constants.MAX_SPEED = 10.0

The maximum game speed. Feel free to play with this variable, the larger you increase its value, the more “overdraw” will occur and the harder it will be to actually complete the game. Must be strictly greater than constants.GAME_SPEED_START.

constants.USE_SPEED_BOOST = False

When set to False the speed of all the actors will remain the same throughout the duration of the game. If you set this to True, an entertaining (but much more difficult to win) variant of the game is used where the more food CitizenPac eats, the faster all of the actors move. The game speed will start at constants.GAME_SPEED_START, and increase to constants.MAX_SPEED.


Wrapper method to allow updating the global variable constants.gameSpeed in this module from another module, without necessitating from Constants import *.

This sets the value of constants.gameSpeed to val.

val (float)

The value to set constants.gameSpeed to.

constants.FOOD_RADIUS = 10.0

The radius for the view.actors.Food class.

constants.FOOD_SPARSITY = 5.0

The sparsity factor for dispersing the view.actors.Food grid, used in the model.generateFoodGrid() function.

constants.SPLINE_COORD_SCALE = 4.0

The software that the view.actors.CitizenPacActor and view.actors.GhostActor classes were designed in (Blender) were modeled at a different scale, you can use this to control how big or small the CitizenPac and Ghosts are. This constant must be positive and non-zero.

constants.FOOD_VALUE = 111.0

The value each view.actors.Food consumed is worth in points.

constants.FULL_GAME_MODE = False

Before you begin working on the function model.generateFoodGrid(), you will want to keep this as False so that the game will still run and you can test whether or not the code you have written to move the CitizenPac and Ghosts is working correctly.

This constant has three important consequences:

  1. If set to False, no collisions are processed for anything, including when CitizenPac runs into a Ghost. AKA the game is in “debug mode.”

    • The game will never end until you close the window, since there is no Food to complete eating, and you will never lose lives.
  2. When you set this to True, the food will be created and collisions will now be processed.

  3. Since the game is in “debug mode”, the move direction you compute is going to be printed to the console for you with extra information about what the current move flags are and what direction that should be.

    This is not here for you to hard-code values, we reserve the right to change the values of the directions declared at the top of view.actors.Actor.

constants.NUM_LIVES = 3

The number of “lives” CitizenPac starts with.

constants.NUM_GHOSTS = 3

How many ghosts to add to the map. Directly related to the size of constants.DISPERSION_RADIUS – if you ask for too many Ghosts, then the game will be impossible to play. Since the actors are distributed on a circle, if you ask for more than the circle can fit without overlapping, CitizenPac will start the game colliding with Ghosts!

You can set constants.FULL_GAME_MODE to True if you want to create many actors for some reason.

constants.DISPERSION_RADIUS = 222.222

CitizenPac and the Ghosts are dispersed on a circle centered at the origin. This constant controls how close / far away the actors will start from the origin.

constants.GAME_REFRESH_RATE = 10

If the game is running slowly, INCREASE the value of this constant in order to get. This time is in terms of MILLISECONDS, and the larger the value, the slower the game runs. So if the game runs slowly, increase this constant.