Dojo Defender Session 5: Coach notes

Goal of this session

After this session a ninja can:

  • Make a parallax star background with three layers
  • Build a particle system with lists of dictionaries
  • Add position-based effects (exhaust fumes, explosions)
  • Apply recursive splitting to asteroids

Preparation (30 min before the session)

  • Starter ZIPs ready on USB and on the site: dojo-defender-s6-starter.en.zip and dojo-defender-s6-solution.en.zip.
  • Run the starter once on the dojo room laptop.
  • Check whether asteroid_med.png and asteroid_small.png are in the images/ folder of the starter. They were added to the shared assets and have to be in the ZIP.
  • Explain parallax on the board: draw three layers of stars with different speeds.
  • Explain the particle life cycle: born → moves → fades → dies.

Schedule (3 hours)

This session is an integral part of the normal session 6 (Platformer). Use the time like this:

TimeActivity
0:00 to 1:15Session 6: Platformer (Step 1-4)
1:15 to 1:30Dojo Defender intro: drawing parallax on the board
1:30 to 2:00Step 1: parallax stars (Basic)
2:00 to 2:30Step 2: particle system (Basic)
2:30 to 2:50Step 3: position effects (Stretch)
2:50 to 3:00Step 4: splitting asteroids (Expert) + showcase

Common questions

“The stars don’t move” update_stars() isn’t called in the game loop. Have the ninja check that the function is called every frame, in the menu too.

“The stars draw over the text” draw_stars(screen) has to come before the other drawing commands, but after screen.fill(). The order is: fill → stars → particles → game objects → UI text.

“The particles are too big / too small” Adjust the size_range in spawn_particles(). Tip: make them smaller than you think. 2-5 pixels is already big for a particle.

“Particles keep floating after a restart” reset_game() is missing particles.clear(). All the lists have to be emptied in reset.

“The asteroid only splits once” The split_asteroid() function removes the original asteroid and adds two new ones. Those new ones have asteroid_size = 'med' (or 'small'). Check that the newly created asteroids also have the asteroid_size property.

“Asteroids flicker after splitting” The new asteroids appear at the same y position as the old one. They move down straight away. That’s normal — in a fast game you barely notice it.

“Pygame says ’no module named math’” import math isn’t at the top of the file yet. Ninjas have to add it when they write spawn_particles().


Hints for Stretch and Expert

Stretch: position effects The hardest step is finding the right place in the code to add the particle spawns. Point the ninja at:

  • Exhaust fumes: at the arrow key check, after ship.rect.centerx += 5
  • Explosion debris: at asteroids.remove(rock) in the bullet collision loop
  • Enemy death sparks: at enemies.remove(enemy) where the enemy disappears at the bottom

Expert: splitting asteroids The split function is recursive: split_asteroid calls spawn_asteroid, which makes a smaller size. Have ninjas first change spawn_asteroid so it accepts a size parameter, and only then write the split function.

Challenge for fast ninjas: “What happens if the split function also makes 3 or 4 smaller asteroids? And what if the smaller asteroids are faster than the bigger ones?”


Cliffhanger script

“Today Dojo Defender got a beautiful star background, smoking exhaust fumes, and asteroids that fall apart into pieces. Next time: POWER-UPS. Shields that protect you, speed-boosts and spread-shots that fire three bullets at once. Hold on tight.”