You can build
a game like this.
A 60-second space mission written in real Python with Pygame. No checkpoints today: experiment and see what your code changes.
How to play
Move: arrows or W A S D
Shoot: hold Space · 6-shot capacity
Pause: P or Esc · Restart: R
Click inside the game once for keyboard focus, then press Enter to start. Gameplay uses keys only. Survive 60 seconds, hit drones and dodge their shots. Ammo restores one shot every 0.8 seconds. Watch the ammo meter and recharge bar.
Your first experiments
- Find
PLAYER_SPEED = 420near the top. Try a different speed. - Change
STARTING_LIVES = 3. Does the mission feel easier? - Change
MISSION_SECONDS = 60for a shorter or longer mission. - Edit
CYAN = (91, 233, 225). These three numbers are red, green and blue, each from 0 to 255.
Press Run game after editing. The game restarts from its menu. Press Enter in the preview.
What makes it work?
Variables → game settings
Speed, lives, score and positions are values with names. Changing a starting value changes how the game behaves.
PLAYER_SPEED = 420 STARTING_LIVES = 3
Conditions → rules
A condition decides when a player takes damage, scores points or finishes the mission.
if game['lives'] <= 0:
state = 'lost'Loops → movement and animation
The game repeats: read controls, update positions, check collisions and draw the next frame.
Functions → reusable actions
ship() draws the player. burst() makes an explosion. You will learn to organise actions like these into functions.
The complete program uses some ideas you have not learned yet. Start with the four settings above; you do not need to understand every line today.