Dojo Defender Session 6: Coach notes
Goal of this session
After this session a ninja can:
- Build a state machine for a boss (PHASE_1/2/3/EXPLODING)
- Draw an HP bar with a dynamic fill level and colour
- Make homing bullets with vector maths (dx / dist * speed)
- Implement screen shake via a random drawing offset
- Show phase transitions with visual effects (flashing)
Preparation (30 min before the session)
- Starter ZIPs ready on USB and on the site:
dojo-defender-s7-starter.en.zipanddojo-defender-s7-solution.en.zip. - Run the starter once on the dojo room laptop.
- Check whether
boss.pngandboss_minion.pngare in theimages/folder of the starter. - Explain the state machine on the board: draw a circle diagram with 4 states (PHASE_1 → PHASE_2 → PHASE_3 → EXPLODING) and arrows between them.
- Explain the unit vector: “dx / dist” gives a direction with length 1. Handy for bullets in every direction.
Schedule (3 hours)
This session is an integral part of the normal session 7 (Bug Zapper). Use the time like this:
| Time | Activity |
|---|---|
| 0:00 to 1:15 | Session 7: Bug Zapper (Step 1-4) |
| 1:15 to 1:30 | Dojo Defender intro: state machine on the board |
| 1:30 to 2:00 | Step 1: boss variables (Basic) |
| 2:00 to 2:20 | Step 2: spawning the boss + HP bar (Stretch) |
| 2:20 to 2:50 | Step 3: boss AI + 3 phases (Expert) |
| 2:50 to 3:00 | Step 4: defeating the boss + showcase |
Common questions
“The boss doesn’t appear at wave 5”
Check whether check_boss_wave() is called after wave += 1. Also: the check wave >= 5 and wave % 5 == 0 has to be right. Wave 5, 10, 15, etc.
“The boss doesn’t shoot”
fire_boss_bullet() is only called if the timer counts and resets. Check whether boss_shoot_timer is raised and reset.
“Minions spawn all the time”
The spawn_boss_minion() function has a timer of 180 frames (~3 seconds at 60fps). Ninjas can change this.
“The screen also shakes after the boss”
screen_shake_x and screen_shake_y have to be set back to 0 when the boss is gone. Add an else branch: screen_shake_x = 0.
“The HP bar is empty”
boss_hp / boss_hp_max can be 0 if boss_hp isn’t initialised correctly. Check whether start_boss() really sets boss_hp = boss_hp_max.
“Bullets don’t hit the boss”
The boss collision check has to come after the enemy loop but before the next bullet iteration. Ninjas sometimes forget to add if boss_active:.
Hints for Stretch and Expert
Stretch: spawning the boss + HP bar
The HP bar is a separate drawing command that doesn’t fit in GameObject.draw(). Ninjas have to use pygame.draw.rect() directly for the bar. Have them first draw an empty bar, then the fill, then the outline.
Expert: boss AI The state machine is the hardest concept. Draw on the board:
- PHASE_1: slow, 1 bullet per 60 frames
- PHASE_2: faster, 1 bullet per 40 frames + minions
- PHASE_3: fast, 2 bullets per 20 frames + minions + screen shake
The phase transition happens at HP boundaries (66% and 33%). Have ninjas work out the boundaries: 50 * 0.66 ≈ 33, 50 * 0.33 ≈ 16.
Screen shake:
Adding a random offset to the drawing coordinates is simple, but it has to happen everywhere: stars, particles, enemies, the boss itself. The simplest way: draw_stars(screen, screen_shake_x, screen_shake_y) and pass the offset as parameters.
Cliffhanger script
“Today you built a final boss with 3 phases, homing bullets and screen shake. Next time: the polished version. A menu screen, sound effects, high scores — and after that you get to make it your own thing.”