<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Dojo Defender: Session 2 :: CoderDojo Python &amp; Pygame</title><link>https://python.coderdojohasselt.be/en/dojo-defender/session-2/index.html</link><description>Your ship has a weapon now. Enemies are coming. Shoot them down before they reach the bottom. Every 10 enemies means a new wave — and it gets harder and harder.
What you’ll learn today Shooting with the space bar and a cooldown Lists for bullets and enemies Collision between bullets and enemies Waves that get harder and harder Enemies that make sine movements Step 0: Open the starter Open Thonny. Download the Dojo Defender starter for today, unpack the ZIP and open main.py. Were you not there last time? Download the solution from session 1 and start with that. Click Run. You see the same game as last time: ship, asteroids, explosions. Problems? Take a look at Installing Thonny. Step 1: Shooting with SPACE Your ship has a laser cannon. Add a list for bullets at the top:</description><generator>Hugo</generator><language>en</language><atom:link href="https://python.coderdojohasselt.be/en/dojo-defender/session-2/index.xml" rel="self" type="application/rss+xml"/><item><title>Dojo Defender Session 2: Cheatsheet</title><link>https://python.coderdojohasselt.be/en/dojo-defender/session-2/cheatsheet/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/dojo-defender/session-2/cheatsheet/index.html</guid><description># Shooting with SPACE def on_key_down(key): global shoot_cooldown if key == keys.SPACE and shoot_cooldown == 0: bullet = Actor('bullet') bullet.x = ship.x bullet.y = ship.y - 20 bullets.append(bullet) shoot_cooldown = 15 # Make bullets move and remove them for bullet in bullets[:]: bullet.y -= 8 if bullet.y &lt; -10: bullets.remove(bullet) # Spawn an enemy def spawn_enemy(): enemy = Actor('enemy_drone') enemy.x = random.randint(30, WIDTH - 30) enemy.y = -30 enemy.speed = random.uniform(1, 3) enemies.append(enemy) # Enemy spawn interval spawn_counter += 1 if spawn_counter >= spawn_interval: spawn_counter = 0 spawn_enemy() # Bullet hits enemy for bullet in bullets[:]: bullet.y -= 8 if bullet.y &lt; -10: bullets.remove(bullet) continue for enemy in enemies[:]: if bullet.colliderect(enemy): bullets.remove(bullet) enemies.remove(enemy) score += 10 break # Waves enemies_destroyed += 1 if enemies_destroyed % 10 == 0: wave += 1 spawn_interval = max(60, spawn_interval - 10) # Sine movement (import math) enemy.x = enemy.start_x + math.sin(timer * 0.03 + enemy.strafe_offset) * 50 # Show wave text if wave_display_timer > 0: screen.draw.text(f"WAVE {wave}!", center=(WIDTH/2, HEIGHT/2), color="yellow", fontsize=60)</description></item><item><title>Dojo Defender Session 2: Coach notes</title><link>https://python.coderdojohasselt.be/en/dojo-defender/session-2/mentor-notes/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/dojo-defender/session-2/mentor-notes/index.html</guid><description>Goal of this session After this session a ninja can:
Create bullets with on_key_down and a cooldown mechanism Spawn enemy objects and make them move with a sine oscillation Collision detection between bullets and enemies (nested loop) Set up a wave system with increasing difficulty Preparation (30 min before the session) Starter ZIPs ready on USB and on the site: dojo-defender-s3-starter.en.zip and dojo-defender-s3-solution.en.zip. Run the starter yourself once on the dojo room laptop. Ninjas who missed S1: point them to the S1 solution. Schedule (3 hours) This session is an integral part of the normal session 3 (Space Blaster). Use the time as follows:</description></item><item><title>Dojo Defender Session 2: Demo</title><link>https://python.coderdojohasselt.be/en/dojo-defender/session-2/demo/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/dojo-defender/session-2/demo/index.html</guid><description>How to demo the solution Open a terminal in the project folder. Run: uv run python3 code/sessions/03-space-blaster/dojo-defender-solution/main.py Show: The ship moves left/right with the arrow keys. SPACE fires a bullet up (cooldown visible). Enemies (enemy_drone) spawn at the top and fall with a sine movement. Bullet hits enemy → both disappear, +10 points. Every 10 kills: the wave goes up, enemies spawn faster. Asteroids still keep falling (from S1). A bullet can also hit asteroids (+5 points). Three lives, explosion animation, invincibility, game over — everything from S1 still works.</description></item></channel></rss>