Paul's Python CoursePPC

Project 4 of 9, for Caitlin

Arcade Catch Game

Mackerel Night, a Pygame game for a new cabinet in the Arcade: rules you can test without a window, drawing kept apart, played by real people and handed to Caitlin.

About 20 hours, in 10 steps.

Sign up free to open itLog in

Act 9 needs a free account, so your work is saved as you go. Act 1 is open to everyone.

The brief

  • CaitlinI've got a new cabinet for the Arcade, with a proper joystick and a coin slot I've taped over.
  • CaitlinMackerel fall off a pier, you catch them in a bucket, and boots cost you a life.
  • YahyaYou should make the mackerel faster every level, like twice as fast.
  • CaitlinLet's make them land first, then we'll talk about twice as fast.
  • PaulPut the rules in one file and the drawing in another, and then the rules can be tested.

Caitlin's rules, written down at last:

  1. Mackerel and old boots fall from the top of the screen. The player slides a bucket along the pier at the bottom.
  2. A mackerel in the bucket scores 1. A boot in the bucket costs a life. Anything missed falls in the sea and costs nothing.
  3. Three lives. When they're gone, the game is over.
  4. Every ten mackerel is a level, up to level 9; each level, things fall faster and more often.
  5. The best five scores, three initials each, stay on the cabinet overnight.

The project, on your own computer, has three parts:

  • pier.py: the rules, with no pygame anywhere in it. Game(seed=None, spawn=True), with move(direction), drop(kind, x), update() for one frame, fall_speed(), and state(), a dictionary of everything there is to draw: bucket_x, items (each {"kind", "x", "y"}), score, lives, level and over. The sizes and speeds are constants at the top of the file, and the details are in its docstring.
  • scores.py: add_score(path, initials, score) and top_scores(path, count=5), kept in a JSON file.
  • main.py: the pygame loop. It reads the keys, calls update() once a frame, and draws from state() and nothing else. python main.py --frames 30 plays thirty frames and stops.

The tests in tests/ check the rules and the high scores without opening a window.

What it prints
>>> game = Game(spawn=False)
>>> game.drop("mackerel", game.state()["bucket_x"])
>>> for frame in range(150):
...     game.update()
...
>>> game.state()
{'bucket_x': 208, 'items': [], 'score': 1, 'lives': 3, 'level': 1, 'over': False}

What you learn

What's in it

  1. Sixty times a second
  2. Make it in text
  3. Caitlin's cabinet
  4. Milestone 1: the plan and the rules of the game
  5. Milestone 2: the logic, tested
  6. Drawing a frame in pygame
  7. Milestone 3: the game on screen
  8. Milestone 4: playtested in the Arcade and handed to Caitlin
  9. Ship it