Session 8: Coach notes
Goal of this session
At the end of the Basic checkpoint a ninja can:
- Scroll the background seamlessly with the double-blit technique.
- Move obstacles from right to left and remove them when they are off the screen.
- Subtract lives on a collision and stop the game at 0 lives.
What is not expected after session 8: stars, difficulty scaling, game over screen. Those are Stretch/Expert material.
Preparation (30 min before the session)
- The background image in the starter has to be exactly
WIDTHpixels wide (800px by default) so the double blit works seamlessly. speedis a float. Point out to ninjas thatpygame.Rectonly accepts integers. The starter already usesint(scroll_x); check that ninjas don’t remove it.- Spawn timer: the starter uses
pygame.USEREVENT + 1. Explain briefly howpygame.time.set_timerworks: it sends an event automatically every N milliseconds.
Schedule (3 hours)
| Time | Activity |
|---|---|
| 0:00 to 0:10 | Welcome, looking back at session 7 |
| 0:10 to 0:20 | Projector: explaining the scrolling background |
| 0:20 to 1:30 | Working on your own: steps 1 and 2 |
| 1:30 to 2:15 | Stretch (stars) |
| 2:15 to 2:45 | Expert (scaling the speed) + buffer |
| 2:45 to 3:00 | Showcase + cliffhanger |
Common questions
“The background flickers”
int(scroll_x) is missing when blitting. pygame.Surface.blit expects integers; if you pass a float, pygame makes an int of it internally, but this can cause frame consistency problems. Check both blit calls.
“Obstacles aren’t removed”
Check that obstacles.remove(obs) is inside the colliderect check, not outside it. Common mistake: the if is at the wrong indentation.
“Speed keeps going up but obstacles don’t spawn more often”
pygame.time.set_timer has to be called again every frame when the interval changes. Add this to the game loop, not once at initialisation. Alternative: use a frame counter instead of a timer.
“The game over screen disappears straight away”
pygame.time.wait(3000) works outside the game loop. But if running = False is already set before the extra blit and wait, it doesn’t work. Make sure the game over blit and wait come after the while running loop, or use a separate game_over flag.
Hints for Stretch and Expert
Stretch: stars:
Stars are pygame.Rect objects too. Point out to ninjas that star.center gives a tuple (x, y), handy for pygame.draw.circle.
Expert: scaling the speed:
speed = BASE_SPEED + score * 0.1 is simple but effective. Explain why we use max(500, ...) for the spawn interval: without a minimum the interval would become negative or zero at a high score.
Dojo Defender today
Session 7 of Dojo Defender = ninjas choose and build their own feature. This happens in the second half of the session (after Sky Highway).
Preparation
- Starter ZIP:
dojo-defender-s8-starter.zipincode/sessions/08-sky-highway/dojo-defender-starter/— this is the complete DD S6 solution (with boss). - Print the planning templates from the Dojo Defender worksheet.
- Agree with the coaches who guides which ninjas during the Dojo Defender part.
Time
| Time | Activity |
|---|---|
| 1:15 to 1:30 | Dojo Defender intro |
| 1:30 to 1:45 | Choosing a feature + planning |
| 1:45 to 2:30 | Building on your own |
| 2:30 to 2:50 | Showcase |
Possible features (for coaches)
- Power-ups (easy): enemies drop power-ups (spread shot, shield, speed boost) with a 20% chance.
- High score (easy): keep the highest score in
highscore.txt, show it on the menu and on game over. - Difficulty (easy): adjust the spawn interval, enemy speed or number of lives.
- New enemy (hard): an enemy that leaves a trail of particles.
- Own idea (all levels): the ninja comes up with a feature themselves.
Watch out: ninjas often want too much at once. Help them pick the smallest version that works.
Cliffhanger script
Read this out to the group:
“Today your ship flew along an endless highway. Next time someone shows up who FIGHTS BACK: a boss with three phases, an HP bar, and bullets coming at you. Can you beat it?”