Capstone: Build Your Own Game

The grand finale — a complete Space Shooter you can run, then a menu of ideas for making it your own and sharing it with the world.

You made it to the end of Code Your Own Games 🎉. Look back at how far you’ve come: you opened a game window and met the game loop, learned the screen’s X-and-Y map, made things move and respond to keys, caught falling things, juggled whole lists of them, snapped between states, and built two complete games — Catch and Dodge the Asteroids.

This is the capstone. I’m handing you one more complete game — a real Space Shooter — fully built and ready to run. Then the best part: it’s yours to change. We’ll go through a menu of ways to make it your own, and I’ll show you how to share it.

Let’s launch it.

Your Space Shooter

Here’s the whole game. Read the controls, press ▶ Run, click the screen, and play. Then come back and we’ll take it apart.

Controls: ← → to move, SPACE to fire, SPACE to restart after Game Over.

 

Runs on Skulpt + pygame4skulpt — in your browser, nothing installed.

Play it for a minute. The shooter works — but did you notice the score never moves? We never told it to go up when a bullet hits an enemy. That’s the perfect last thing to fix. Add scoring, and you’ll have a clean game to make your own.

How the shooter works

It’s the same toolkit you already know, arranged a new way:

  • The ship is the cyan triangle (pg.draw.polygon), steered with ← →, just like the dodger.
  • Bullets are a list. Pressing SPACE does bullets.append({"x": ship_x, "y": 430}) — a new bullet born at the ship’s nose. Each frame every bullet moves up (y - 8), and bullets that fly off the top are removed by rebuilding the list.
  • Enemies are another list of red circles, spawned over time at random x, falling down — exactly the asteroid storm from lesson 11.
  • The collisions are the new idea: for each enemy, we check it against every bullet with colliderect. A hit removes both (the enemy is dropped, the bullet gets flung off-screen with b["y"] = -999). And if an enemy reaches the ship — or slips past to the bottom — it’s Game Over.

Fixing the score

The fix is to count the hits as they happen — add 10 points right where a bullet strikes an enemy. Replace the hit-check chunk with this:

        survivors = []
        for en in enemies:
            hit = False
            en_box = pg.Rect(en["x"] - 18, en["y"] - 18, 36, 36)
            for b in bullets:
                b_box = pg.Rect(b["x"] - 3, b["y"] - 10, 6, 20)
                if en_box.colliderect(b_box):
                    hit = True
                    b["y"] = -999
            if hit:
                score = score + 10
            else:
                survivors.append(en)
        enemies = survivors
        bullets = [b for b in bullets if b["y"] > -10]

Now every enemy you shoot adds 10 to the score, hit enemies are dropped from the list, and used-up bullets are swept away. Here’s the finished, clean game with that fix in place — this is the one to copy and make your own:

 

Runs on Skulpt + pygame4skulpt — in your browser, nothing installed.

Shoot the red invaders before they reach you. Every hit is +10. Let even one slip to the bottom and it’s Game Over. That’s the game to make your own.

Make it yours — the idea menu 🚀

This is the whole point of the capstone. Copy that finished game and pick something from the menu below. Get it working, then pick another. There are no wrong answers — only your game.

Easy tweaks (change a number)

  • Rapid fire: bullets feel slow? Change b["y"] - 8 to b["y"] - 12.
  • Tougher waves: spawn enemies faster — change timer >= 35 to timer >= 20.
  • Different colors: make the ship green (90, 255, 140) and the enemies purple (190, 110, 255). Paint your own ship!

Add a high score

Keep a best = 0 variable up top (outside the loop, so restarting doesn’t wipe it). When the game ends, check it:

            if state == "over":
                if e.key == pg.K_SPACE:
                    if score > best:
                        best = score
                    ship_x, bullets, enemies, score, timer = new_game()
                    state = "play"

Then blit "Best: " + str(best) under the score. Now beating your own record means something.

Levels that speed up

Make the game get harder as your score climbs — just like the asteroid dodger did. Build the enemy speed from the score:

        speed = 3 + score // 200
        for en in enemies:
            en["y"] = en["y"] + speed

At 200 points the invaders fall faster; at 400, faster still. How high can you get?

More enemy types

Give each enemy a size and color when it’s born, so some are big and slow, others small and quick:

        if timer >= 35:
            timer = 0
            kind = random.choice(["small", "big"])
            if kind == "small":
                enemies.append({"x": random.randint(20, 380), "y": -30, "r": 12})
            else:
                enemies.append({"x": random.randint(20, 380), "y": -30, "r": 24})

Then draw each with en["r"] as its radius (and remember to use en["r"] in the collision box too, not the fixed 18). Tiny enemies are harder to hit!

A title screen

Add a third state. Start in state = "title" instead of "play", show a welcome message, and begin the game when SPACE is pressed:

            if state == "title":
                if e.key == pg.K_SPACE:
                    state = "play"

…and in the drawing part:

    if state == "title":
        hello = big.render("SPACE SHOOTER", True, (90, 220, 255))
        screen.blit(hello, (35, 200))
        go = font.render("Press SPACE to start", True, (255, 255, 255))
        screen.blit(go, (75, 250))

You already know states cold — this is just one more.

Share your game 🌟

When you’ve got a version you’re proud of:

  1. Copy the code out of the editor (select it all, copy).
  2. Paste it somewhere safe — a document, a note, a message to a grown-up or a friend.
  3. Send the link to this page along with your code, and tell them: paste it into the editor and press Run. Your game runs on their screen, no install — they can play and read how you built it.

You’re not just playing games anymore. You’re shipping them.

Your Games journey

Look at the whole road you walked:

  • The game loop — every game’s heartbeat: draw, show, repeat.
  • The X-and-Y map and colors — painting exactly what you want, where you want it.
  • Movement and keys — making the player respond to you.
  • Catch — your first complete game.
  • Lists — handling a whole crowd of things at once.
  • States — Playing, Game Over, restart.
  • Dodge the Asteroids — a second full game, a different genre.
  • This capstone — a Space Shooter that’s yours to grow.

Every real game — the big ones on phones and consoles — is built from these same bones, just more of them. You have the bones now. Keep building. Make a maze game. A platformer. A two-player duel. The editor’s right there.

You came in having drawn with a turtle and made programs that chat. You’re leaving as someone who codes their own games. That’s a real, true thing you can do now. 🎮

And there’s a whole other superpower waiting. So far your programs have made things. Next, you’ll make programs that find things out — loading real data, asking questions of it, and drawing charts that reveal the answers. Time to become a Data Detective.

Next: Python for Kids · Phase IV — Data Detective 🕵️

Comments