Session 5: Coach notes
Goal of this session
After the Basic checkpoint a ninja can:
- Make the ball move vertically and bounce off all four edges and the paddle.
- Play a sound on a collision.
- Take off a life when the ball reaches the bottom.
Preparation
- Starter ZIP ready. It contains
sounds/hit.wavandsounds/explosion.wav. - Test whether
pygame.mixerworks on the dojo laptop (sometimes the audio driver is missing). - Dojo Defender: today ninjas add sound effects to their project.
Schedule (3 hours)
| Time | Activity |
|---|---|
| 0:00 to 0:10 | Looking back + intro to sound |
| 0:10 to 0:30 | Step 1 to 2: moving the ball + bouncing |
| 0:30 to 1:15 | Step 3: breaking bricks |
| 1:15 to 1:50 | Step 4: lives, sound, win/game over |
| 1:50 to 2:20 | Dojo Defender: adding sound |
| 2:20 to 2:50 | Buffer / stretch / expert |
| 2:50 to 3:00 | Showcase + cliffhanger |
Common questions
“I can’t hear any sound” Two causes:
pygame.mixer.init()isn’t at the top. Check the order in the code.- The script is started from a different folder. Python then looks for
sounds/hit.wavin the folder you’re in, not next tomain.py. The starter uses_DIR = os.path.dirname(os.path.abspath(__file__))to solve this. Point the ninja at this. On some laptops the audio driver is missing; thetry/exceptstops the script from crashing then.
“The ball goes straight through the bricks”
The break after removing a brick is missing; without break Python checks several bricks in the same frame and ball_dy can get reversed twice.
“The ball speeds up out of control”
ball_dy = -ball_dy is called several times per frame (paddle AND bottom at the same time). Add a cooldown or a position check.
Hints for Stretch and Expert
Stretch: breaking bricks:
The break is essential. Explain: if you leave it out, the loop checks all the bricks and reverses ball_dy several times in the same frame.
Expert: speed: Use a factor based on the number of bricks left, not a fixed increase per collision. That way the acceleration is predictable.
Cliffhanger script
“Next time: gravity. Your character falls down, unless you make it jump in time. Platforms, stars and a jump with sound.”
Dojo Defender today
Next to Breakout, ninjas work on Dojo Defender Session 4 today: menu + three enemy types.
Goals:
- Implement a state machine (MENU, PLAYING, GAME_OVER)
- Write a reset function
- Three enemy types: drone, zigzag, charger
- A wave system with rising difficulty
Time split: see the table above — 1:50 to 2:20 is for Dojo Defender.
Preparation:
- Have
dojo-defender-s5-starter.en.zipanddojo-defender-s5-solution.en.zipready - Check that
enemy_zigzag.pngandenemy_charger.pngare in the starter - Worksheet: Dojo Defender Session 4