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.wav and sounds/explosion.wav.
  • Test whether pygame.mixer works on the dojo laptop (sometimes the audio driver is missing).
  • Dojo Defender: today ninjas add sound effects to their project.

Schedule (3 hours)

TimeActivity
0:00 to 0:10Looking back + intro to sound
0:10 to 0:30Step 1 to 2: moving the ball + bouncing
0:30 to 1:15Step 3: breaking bricks
1:15 to 1:50Step 4: lives, sound, win/game over
1:50 to 2:20Dojo Defender: adding sound
2:20 to 2:50Buffer / stretch / expert
2:50 to 3:00Showcase + cliffhanger

Common questions

“I can’t hear any sound” Two causes:

  1. pygame.mixer.init() isn’t at the top. Check the order in the code.
  2. The script is started from a different folder. Python then looks for sounds/hit.wav in the folder you’re in, not next to main.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; the try/except stops 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.zip and dojo-defender-s5-solution.en.zip ready
  • Check that enemy_zigzag.png and enemy_charger.png are in the starter
  • Worksheet: Dojo Defender Session 4