<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python sessions :: CoderDojo Python &amp; Pygame</title><link>https://python.coderdojohasselt.be/en/sessions/python/index.html</link><description>Ten sessions in which you build a complete Pygame game every month. Every session has a worksheet, a cheatsheet and starter code to download.
Session 1: Catch the Stars: A star falls, you catch it. You write your first draw()/update() loop and move a sprite with the arrow keys. Session 2: Dodge Meteors: Meteors spawn and fall. You keep track of them in a list, remove them once they are off screen and take off a life on every collision. Session 3: Space Blaster: Enemies drop down, you shoot them. You create bullets with SPACE and detect collisions with a loop over a list. Session 4: Pong: Two paddles, one ball. You learn pygame.Rect, make the ball bounce by reversing its speed and keep the score for two players. Session 5: Breakout: Smashing bricks with a bouncing ball. You add sound effects with pygame.mixer and build a win and lose screen. Session 6: Platformer: Jumping and falling on platforms. You simulate gravity with a vel_y variable and detect platform collisions with pygame.Rect. Session 7: Bug Zapper: Bugs crawl, you zap them. You write your first class with __init__ and make a subclass through inheritance. Session 8: Sky Highway: A flying ship on a scrolling road. You spawn obstacles from the right and raise the speed as the score goes up. Session 9: Boss Battle: A boss with an HP bar and attack phases. You build a state machine that changes the shooting and movement behaviour per phase. Session 10: My Game: No fixed assignment. You pick the genre and combine everything you learned in nine sessions into your own game.</description><generator>Hugo</generator><language>en</language><atom:link href="https://python.coderdojohasselt.be/en/sessions/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Session 1: Catch the Stars</title><link>https://python.coderdojohasselt.be/en/sessions/python/01-catch-the-stars/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/index.html</guid><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></item><item><title>Session 2: Dodge Meteors</title><link>https://python.coderdojohasselt.be/en/sessions/python/02-dodge-meteors/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/02-dodge-meteors/index.html</guid><description>Your spaceship drifts in the dark of space while meteors come down from above. Dodge them, or lose a life. The longer you survive, the faster they go. And this time you also build Dojo Defender: the bigger project that grows every session.
What you’ll learn today Using lists to keep track of several objects Spawning (creating) and removing objects Keeping track of lives and showing a game-over screen Dojo Defender: adding your own spaceship to the bigger project Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py. Click Run. You see your spaceship at the bottom, but no meteors are falling yet. Problems? Take a look at Installing Thonny. Step 1: Let meteors spawn Fill in the spawn_meteor() function. A meteor is an Actor that starts at the top of the screen at a random x position:</description></item><item><title>Session 3: Space Blaster</title><link>https://python.coderdojohasselt.be/en/sessions/python/03-space-blaster/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/03-space-blaster/index.html</guid><description>Enemies stand in formation at the top of the screen. You’re at the bottom with a spaceship and one goal: knock them all out before they reach the bottom. Press SPACE to shoot, and don’t miss.
What you’ll learn today Keeping track of bullets in a list Creating a bullet when you press SPACE Collision between bullets and enemies Game over when an enemy reaches the bottom Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py. Click Run. You see the ship at the bottom and 12 enemies in a grid, but nothing moves and you can’t shoot yet. Step 1: Let the ship move The ship already moves with the arrow keys. Check the code in update(). Make sure the ship doesn’t go off the screen:</description></item><item><title>Session 4: Pong</title><link>https://python.coderdojohasselt.be/en/sessions/python/04-pong/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/04-pong/index.html</guid><description>Two paddles, one ball: the classic game of Pong. But there’s a surprise: this session you write the game in real pygame, without pgzrun. You learn to set up the game loop yourself. That’s how most real games work.
What you’ll learn today The pygame game loop: events, update, draw pygame.Rect for rectangles and collisions Making the ball bounce (reversing the speed) Keeping score for two players Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py. Click Run. You see two paddles and a yellow ball in the middle, but the ball doesn’t move yet. Difference with pgzrun: There are no draw() and update() functions any more. Everything sits in one while running: loop.</description></item><item><title>Session 5: Breakout</title><link>https://python.coderdojohasselt.be/en/sessions/python/05-breakout/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/05-breakout/index.html</guid><description>A ball bounces back and forth and smashes rows of coloured bricks to pieces. You steer the paddle to keep the ball in the air. And this time you hear it too: there are sound effects on every collision.
What you’ll learn today Loading and playing sound with pygame.mixer Collisions with several objects (a list of bricks) Making the ball bounce in the right direction Building a win and lose screen Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py. Click Run. You see the paddle, the ball and the bricks. The ball already moves horizontally but not vertically. You’re going to change that. Step 1: Make the ball move vertically Find this line in the starter:</description></item><item><title>Session 6: Platformer</title><link>https://python.coderdojohasselt.be/en/sessions/python/06-platformer/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/06-platformer/index.html</guid><description>In this session you build a micro-platformer. Your player has gravity, can jump, and collects stars on platforms. For the first time you use pygame directly, without pgzrun, and you add sound effects with pygame.mixer.
What you’ll learn today Simulating gravity with a vel_y variable Jumping by making vel_y negative Detecting platform collisions with pygame.Rect Collecting items (collision with stars) Playing sounds with pygame.mixer 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 window with a player, platforms and stars, but the player doesn’t fall yet. Problems? Ask a coach. Step 1: Gravity In a platformer the player falls down all the time, unless they’re standing on a platform. We simulate that with vel_y: a vertical speed that grows every frame because of gravity.</description></item><item><title>Session 7: Bug Zapper</title><link>https://python.coderdojohasselt.be/en/sessions/python/07-bug-zapper/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/07-bug-zapper/index.html</guid><description>Bugs fall down from the top. You shoot up to hit them. In this session you learn OOP: you write your first class of your own (Bug), and then two subclasses: one that swings and one that dives at you. Classes are the building blocks of almost every big program.
What you’ll learn today Writing a class with __init__ and your own methods Inheritance: a subclass that extends an existing class Keeping track of bullets in a list Collision detection between bullets and bugs Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py in Thonny. Click Run. You see a screen with a player at the bottom, but no bugs and no bullets yet. Problems? Ask a coach. Step 1: Spawning bugs and shooting The Bug class</description></item><item><title>Session 8: Sky Highway</title><link>https://python.coderdojohasselt.be/en/sessions/python/08-sky-highway/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/08-sky-highway/index.html</guid><description>Your ship flies through an endless highway in the sky. The background scrolls past you, red obstacles come from the right, and stars give points. The longer you survive, the faster it gets!
What you’ll learn today Making a scrolling background with a scroll_x variable Spawning objects that move from right to left Collision detection with lives Difficulty scaling: raising the speed as the score climbs Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py in Thonny. Click Run. You see a static screen with a ship and a sky background, but nothing moves yet. Problems? Ask a coach. Step 1: Let the background scroll A scrolling background gives the illusion of movement. We draw the background twice next to each other and shift the position every frame.</description></item><item><title>Session 9: Boss Battle</title><link>https://python.coderdojohasselt.be/en/sessions/python/09-boss-battle/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/09-boss-battle/index.html</guid><description>The boss is waiting for you. It moves back and forth, shoots bullets and gets more dangerous as its HP drops. You shoot back, keep track of its HP on a bar, and survive three phases. This is the hardest session, and the most satisfying one if you make it through.
What you’ll learn today Drawing an HP bar on the screen A state machine: the boss behaves differently in each phase Making the boss shoot with a bullet timer Activating phases at HP thresholds Step 0: Setup Open Thonny. Download the starter via this link, unpack the ZIP and open main.py in Thonny. Click Run. You see the boss at the top, your ship at the bottom. No movement, no bullets yet. Problems? Ask a coach. Step 1: Making the boss move The boss moves back and forth across the screen. When it hits the edge, it turns around.</description></item><item><title>Session 10: My Game</title><link>https://python.coderdojohasselt.be/en/sessions/python/10-my-game/index.html</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://python.coderdojohasselt.be/en/sessions/python/10-my-game/index.html</guid><description>This is your session. No fixed steps, no compulsory mechanics. You decide what you build, and today you make it.
Your game, your rules In nine sessions you learned:
Variables, functions and game loops Keyboard and mouse input Sprites, collision detection and score Sound and animation Classes and inheritance Scrolling backgrounds, spawning and difficulty scaling HP bars, state machines and boss AI All those building blocks are ready. Today you combine them in your own game.</description></item></channel></rss>