Session 10: My Game

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.

Choose your concept

No idea yet? Here are a few genres to start from:

Dodge game: dodge objects that come faster and faster. Simple but addictive.

Platformer: jump from platform to platform, collect items, avoid enemies.

Shooter: shoot enemies that come from above or from the side.

Puzzle game: slide blocks, connect dots, or solve a pattern.

Racing game: design a course and get to the finish as fast as you can.

Tell a story: no score, no lives. Let the player click and make choices.

You can also combine things: a shooter with puzzle elements, a platformer with a boss at the end. Anything goes.

Plan your game

Before you write code, answer these three questions:

  1. What does the player do? (move, shoot, jump, click, …)
  2. What is the goal? (get a score, beat the boss, reach the end, …)
  3. What makes it hard? (enemies, obstacles, a timer, …)

Write your answers on a piece of paper or in a comment at the top of your code. That helps you stay focused when you get stuck.

Animation: switching sprite per frame

Do you want a loop animation, an explosion or a blinking object? Make a list of image names and switch actor.image every N milliseconds. The demo below shows how that works: use the slider to change the speed and the button to pause:

In Python you then use a list of image names and a timer:

frames = ['lopen_1', 'lopen_2', 'lopen_3', 'lopen_4']
anim_timer = 0
FRAME_DUUR = 10   # frames (at 60 fps = ~167 ms)

def update():
    global anim_timer
    anim_timer += 1
    speler.image = frames[(anim_timer // FRAME_DUUR) % len(frames)]

Getting started

Download the starter via this link. The starter has:

  • A working pygame game loop
  • An empty draw() and update() section
  • Colour constants and a font variable ready to go
  • Comments that show where you can put what

Open main.py and start with Step 1 of your own plan. The cheatsheet on this page has all the patterns from the previous sessions at hand.

Stuck? Ask a coach. Describe what you want to achieve, not just what isn’t working. Then we can work out the best approach together.

Finished too fast? Add sound, make a start screen, or add a second player.

Showcase

At the end of the session everyone presents their game. You don’t have to finish it. Show what you made and tell:

  • What is the concept of your game?
  • Which technique from a previous session did you use?
  • What would you still like to add if you had more time?

What now?

CoderDojo stops after ten sessions. Building things yourself doesn’t stop.

Keep building. Small projects teach you more than big courses. Make a game for your brother or sister, your pet, or just for yourself.

Need inspiration?

CoderDojo will be back. Will you?

Keep building!

In ten sessions you built a platformer, a shooter, a boss battle and more. Take that code home, open it again next week, and just add one thing. That is how programmers work.

View the cheatsheet for this session