Game Programming
Senior 2 · ICT
Game Programming
Lesson 2 of 4
22 min
Professional game studios write a design document before anyone writes code. Planning takes minutes; fixing a badly planned game can take hours. In project work and in exams you may be asked to present your plan as a design table: a table that lists every part of the game, what it does and what makes it happen.
Idea: coffee cherries fall from the trees on a hillside farm. The player moves a basket to catch the red (ripe) cherries and avoid the green (unripe) ones.
Goal: score as many points as possible before losing 3 lives.
Controls: the left and right arrow keys move the basket.
| Element | Type | What it does | Triggered by | Block categories |
|---|---|---|---|---|
| Basket | Sprite | Moves left and right along the bottom of the stage | Arrow keys | Events, Control, Sensing, Motion |
| Red cherry | Sprite | Falls from a random place at the top; +1 score if caught | Green flag, then a loop | Motion, Operators, Sensing, Variables |
| Green cherry | Sprite | Falls like the red one; −1 life if caught | Green flag, then a loop | Motion, Operators, Sensing, Variables |
| Coffee farm | Backdrop | Shown while the game is being played | Green flag | Looks |
| Game Over | Backdrop | Shown when the game ends | lives reaches 0 | Looks, Control |
| score | Variable | Counts ripe cherries caught; starts at 0 | Catching a red cherry | Variables |
| lives | Variable | Starts at 3; the game ends at 0 | Catching a green cherry | Variables |
| speed | Variable | Steps a cherry falls on each move; starts at 3 | Every 10 points | Variables, Operators |
| WHEN (trigger) | THEN (result) |
|---|---|
| The green flag is clicked | score = 0, lives = 3, speed = 3; show the coffee-farm backdrop |
| A red cherry touches the basket | score goes up by 1; the cherry jumps back to the top at a random x |
| A green cherry touches the basket | lives goes down by 1; the cherry jumps back to the top |
| Any cherry reaches the bottom edge | It jumps back to the top (no penalty) |
| score reaches 10, 20, 30, … | speed goes up by 1 |
| lives reaches 0 | Switch to the Game Over backdrop and stop everything |
| Test | Expected result |
|---|---|
| Hold the right arrow | The basket moves right and stops at the edge of the stage |
| Catch one red cherry | score changes from 0 to 1, and only once |
| Catch three green cherries | lives goes 3, 2, 1, 0; Game Over appears; everything stops |
| Reach 10 points | speed changes from 3 to 4 and the cherries fall visibly faster |
Worked example
Mutesi's plan for a space game has a rocket sprite moved by the arrow keys, falling rocks, a score that goes up by 1 for every second she survives, and a rule that the rocks get faster every 15 seconds. What is missing? There is no lose condition: nothing says what happens when a rock hits the rocket, so the game can never end. She should add, for example, "WHEN a rock touches the rocket THEN lives goes down by 1" and "WHEN lives reaches 0 THEN show Game Over and stop everything", plus a new variable, lives, starting at 3.
Tip
The WHEN–THEN test: every rule in your plan needs a trigger (WHEN) and a result (THEN). A rule with no trigger can never run, and a rule with no result does nothing. Every variable in the design table also needs a starting value.
Complete this design-table row. Element: timer. What it does: starts at 60 and counts down by 1 each second; the game ends at 0. What is its type, and which block categories will it need?
Solution: It is a variable. It needs Variables (set timer to 60, change timer by −1), Control (a loop with wait 1 second, and stop all), and Events (the green flag to start it).
Write WHEN–THEN rules for: "the player loses a life when the ball falls past the bat".
Solution: WHEN the ball touches the bottom edge of the stage THEN lives goes down by 1 and the ball returns to the centre. Add a second rule: WHEN lives reaches 0 THEN show Game Over and stop everything.
In Coffee Harvest, speed starts at 3 and rises by 1 each time the score reaches another multiple of 10. What is the speed at a score of 35?
Solution: The score has passed 10, 20 and 30, which is 3 increases, so speed = 3 + 3 = 6.
During testing, Habimana catches one red cherry and the score jumps from 0 to 7. Which rule is faulty, and what is the likely cause?
Solution: The red-cherry scoring rule. The cherry keeps touching the basket for several checks, and each check adds 1. The THEN part must send the cherry back to the top straight after adding the point, so that it can only score once.
Summary
Sources and credits
Written by Ganzaa.