Session 9: Coach notes

Goal of this session

At the end of the Basic checkpoint a ninja can:

  • Make the boss move back and forth with direction switching.
  • Make player bullets hit the boss and make boss_hp shrink.
  • Draw an HP bar that follows the current HP.

What is not expected after session 9: the boss shooting back, three phases. Those are Stretch/Expert material.


Preparation (30 min before the session)

  • Explain state machines briefly: a variable (boss_phase) determines the behaviour. Use an everyday analogy: a traffic light that goes from green to orange to red.
  • BOSS_MAX_HP has to be consistent throughout the code. If ninjas change it, they have to change the HP bar calculation too.
  • Check the starter: player_bullets and boss_bullets are empty lists, boss_hp = 100, BOSS_MAX_HP = 100, boss_shoot_timer = 0.

Schedule (3 hours)

TimeActivity
0:00 to 0:10Welcome, looking back at session 8
0:10 to 0:20Projector: explaining the HP bar and the state machine
0:20 to 1:30Working on your own: steps 1 and 2
1:30 to 2:15Stretch (boss shoots back)
2:15 to 2:45Expert (three phases) + buffer
2:45 to 3:00Showcase + cliffhanger for session 10

Common questions

“The boss stops at the edge but doesn’t turn around” boss_speed = -boss_speed has to come after the edge check. If it comes before the movement, the boss turns around before it reaches the edge and it can get stuck at the edge (oscillating). Have them check the order.

“The HP bar shows a negative width at HP < 0” Add a clamp: breedte = max(0, int(300 * boss_hp / BOSS_MAX_HP)). Alternative: stop the game loop as soon as boss_hp <= 0 and show the win screen.

“Boss bullets go straight through the player” Check that player_rect is set correctly (not at position 0,0 because of an initialisation error). Also check whether b.colliderect(player_rect) comes before or after drawing the bullet: it doesn’t matter for correctness, but it is confusing if the bullet has already been drawn and then gets “rewound”.

“Phase 3 doesn’t spawn double bullets” Check that boss_phase is set correctly before the shoot code. If the phase logic comes after the shoot timer, the shoot code uses the previous phase. Always put the phase update at the top of the game loop.


Hints for Stretch and Expert

Stretch: boss shoots: boss_shoot_interval = 60 means every second at 60 FPS. Lower it for more difficulty. Point ninjas to the pattern: raise the timer → check → reset and spawn.

Expert: three phases: The trick with boss_speed = boss_speed_abs * (1 if boss_speed > 0 else -1) keeps the direction while the speed changes. This is a good moment to discuss the ternary operator in Python.


Cliffhanger script

Read this out to the group:

“Today you beat a boss in three phases. Next time there is no boss, no obstacles, no rules: you decide EVERYTHING. Your own game, from scratch. What are you going to build?”