Dojo Defender Session 1: Coach notes
Goal of this session
After this session a ninja can:
- Create and manage a list of asteroids with
Actor - Spawn asteroids with a timer and remove them when they are off screen
- Detect collisions with
colliderect - Keep track of lives and force game over
- Show a simple explosion animation
Preparation (30 min before the session)
- Starter ZIPs ready on USB and on the site:
dojo-defender-s2-starter.en.zipanddojo-defender-s2-solution.en.zip. - Run the starter yourself once on the dojo room laptop.
- Explain that Dojo Defender comes back every session β encourage them to keep the code safe.
Schedule (3 hours)
This session is an integral part of the normal session 2 (Dodge Meteors). Use the time as follows:
| Time | Activity |
|---|---|
| 0:00 to 1:00 | Session 2: Dodge Meteors (step 1-4) |
| 1:00 to 1:15 | Dojo Defender intro + downloading the starter |
| 1:15 to 1:45 | Step 1-2: spawning + moving asteroids |
| 1:45 to 2:15 | Step 3: collision + lives |
| 2:15 to 2:45 | Step 4: explosions + invincibility |
| 2:45 to 3:00 | Showcase + cliffhanger |
Common questions
“My asteroids aren’t drawn”
The for loop for asteroids is probably not in draw(), or it sits after a return statement.
"global gives an error"
global timer has to be at the top of the function, before the first time timer is used.
“The ship is invisible after a collision”
Check that ship.visible = True is set when the explosion is over. The reset has to come after frame 4 of the explosion.
“The explosion isn’t shown”
Don’t forget to call explosion.draw() in draw(), and to set explosion_active to True on a collision.
Hints for Stretch and Expert
Stretch: collision
Explain that colliderect checks whether two rectangles (hitboxes) overlap. This is the standard way in pgzero.
Expert: explosion
The explosion mechanism is a manual frame animation: change the image of the Actor every 5 frames. This is a simple but effective technique.
Expert: invincibility Invincibility stops you from getting hit again straight after an explosion. Use a counter that counts down every frame.
Cliffhanger script
“Today you dodged asteroids and watched your ship blow up. Next time: your spaceship SHOOTS BACK. Enemies in formation, and you have lasers. Ready to attack?”