Dojo Defender Session 4: Coach notes
Goal of this session
After this session a ninja can:
- Apply a state machine (MENU → PLAYING → GAME_OVER)
- Write a reset function that puts all the global variables back
- Implement different enemy AI (drone, zigzag, charger)
- Build a wave system that raises the difficulty
Preparation (30 min before the session)
- Starter ZIPs ready on USB and on the site:
dojo-defender-s5-starter.en.zipanddojo-defender-s5-solution.en.zip. - Run the starter once on the dojo room laptop.
- Check whether
enemy_zigzag.pngandenemy_charger.pngare in theimages/folder of the starter. - Explain the state machine on the board: draw three blocks (MENU, PLAYING, GAME_OVER) with arrows between them.
Schedule (3 hours)
This session is an integral part of the normal session 5 (Breakout). Use the time like this:
| Time | Activity |
|---|---|
| 0:00 to 1:15 | Session 5: Breakout (Step 1-4) |
| 1:15 to 1:30 | Dojo Defender intro: drawing the state machine on the board |
| 1:30 to 2:00 | Step 1-2: menu + game over + reset (Basic) |
| 2:00 to 2:30 | Step 3: three enemy types (Stretch) |
| 2:30 to 2:50 | Step 4: enhanced waves (Expert) |
| 2:50 to 3:00 | Showcase + cliffhanger |
Common questions
“My game-over screen is black”
You probably aren’t drawing anything in the elif state == "GAME_OVER" branch. Make sure screen.fill() and the drawing of the GAME OVER text are in that branch. Use the same background as PLAYING.
“The reset doesn’t work completely”
The reset_game() function often forgets one variable. The most forgotten ones: shoot_cooldown, explosion_active, explosion_frame, spawn_counter. Have the ninja check that EVERYTHING is put back.
“The zigzag flies off the screen”
The zigzag can keep “sticking” to the edge if enemy.dx isn’t reversed. Check whether the check enemy.rect.left <= 0 or enemy.rect.right >= WIDTH comes before the movement — no, it has to come after the movement, or the check has to be correct. The order is: move x, then check whether it’s out, then turn around. Watch out: if the speed is too high it can still shoot through the edge.
“The charger is too fast / too slow”
Adjust the * 0.8 factor. With * 1.0 the charger goes down as fast as it goes sideways. Experiment. Tip: slow the charger down a bit more for beginners, make it faster as the wave gets higher.
“SPACE also shoots in the menu”
The SPACE key has to check state first. Have ninjas rewrite the KEYDOWN logic like in step 1. If the order is wrong (check shooting first, then the menu) the player accidentally shoots in the menu.
“My game doesn’t stop after game over”
state = "GAME_OVER" has to be set when lives <= 0. Check whether this happens in all the places where the player takes damage (asteroid hits the ship, enemy hits the ship, enemy reaches the bottom).
Hints for Stretch and Expert
Stretch: three enemy types
The easiest mistake: not setting enemy.type in the spawn function. Then enemy.type is undefined and the movement logic does nothing. Have ninjas add a print(enemy.type) to debug.
Expert: enhanced waves
The wave system is the cherry on the cake. Only if Step 3 works. Have ninjas first make a spawn_enemy() function that calls the other three. After that they can add the wave logic.
Challenge for fast ninjas: “What happens if the charger steers towards the left/edge? And what if you let the charger’s speed go up with the wave?”
Cliffhanger script
“You’ve given Dojo Defender a menu, three enemy types and a wave system that gets harder and harder. Next time: POWER-UPS. Shields that protect you, speed-boosts and spread-shots that fire three bullets at once. Hold on tight.”