<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Session 1: Catch the Stars :: CoderDojo Python &amp; Pygame</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/index.html</link><description>In this session you build a mini game: a star falls down and you catch it with a basket. By the end of the session everything moves, the game keeps track of how many stars you catch, and you have your first game of your own.
What you’ll learn today Using variables to position objects The draw() function: what you draw every frame The update() function: what changes every frame Keyboard input: moving with the arrow keys Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py in Thonny. Click the green Run button. You see a dark blue window with a basket at the bottom and a star at the top, but nothing moves yet. Problems? Take a look at Installing Thonny. Step 1: Let the star fall The update() function runs 60 times per second. So everything you put in it runs 60 times per second. That is how movement works in a game.</description><generator>Hugo</generator><language>en</language><atom:link href="https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/index.xml" rel="self" type="application/rss+xml"/><item><title>Coordinates in Pygame Zero</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/coordinaten/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/coordinaten/index.html</guid><description>Pixels A screen is a grid of tiny coloured dots: pixels. Our game window is 600 pixels wide and 400 pixels high: 240,000 pixels in total.
Every pixel has an address: (x, y). That way Pygame Zero knows exactly where to draw something.
Where is (0, 0)? In maths graphs the zero point (0, 0) is at the bottom left. In Pygame Zero (0, 0) is at the top left.</description></item><item><title>Session 1: Coach notes</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/mentor-notes/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/mentor-notes/index.html</guid><description>Goal of this session At the end of the Basic checkpoint a ninja can:
Move the basket left and right with the arrow keys. See a star fall from the top of the screen to the bottom. Read the update() function, understand what it says, and make a small change of their own (for example raise the speed). What is not expected after session 1: keeping score, collision detection, random start positions. Those come in session 2.</description></item><item><title>Session 1: Cheatsheet</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/cheatsheet/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/cheatsheet/index.html</guid><description>Opening a window import pgzrun WIDTH = 600 HEIGHT = 400 def draw(): screen.fill((20, 20, 50)) pgzrun.go() Run: green Run button in Thonny
Making an Actor (sprite) basket = Actor('basket') # looks for images/basket.png basket.pos = (300, 380) basket.draw() Drawing in draw() def draw(): basket.draw() star.draw() Moving in update() def update(): star.y = star.y + 3 Keyboard if keyboard.left: basket.x = basket.x - 5 if keyboard.right: basket.x = basket.x + 5 Collision if star.colliderect(basket): # hit! Drawing text screen.draw.text("Score: 0", topleft=(10, 10), color="white") Random number import random star.x = random.randint(20, 580)</description></item><item><title>Session 1: Demo recording</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/demo/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/demo/index.html</guid><description>Pgzero can not be compiled to WebAssembly (only Pygame from session 4 on). That is why the session page shows a GIF of the end result instead of a playable demo.
How to record Run the solution: cd code/sessions/01-catch-the-stars/solution &amp;&amp; uv run pgzrun main.py. Use a screen recorder: Linux: Peek or SimpleScreenRecorder. Windows: ScreenToGif. macOS: built-in QuickTime → export to GIF via ffmpeg or Kap. Record ~10 seconds of gameplay. Save as catch-the-stars.gif in static/sessions/01-catch-the-stars/. Refer to it in the worksheet via: ![Demo](/sessions/01-catch-the-stars/catch-the-stars.gif). Target size: ~600×400 pixels, ≤ 2 MB.</description></item></channel></rss>