Game Discussion & Design Details
🕹 Discussion Time: 10-15 minutes
1️⃣ Observing the Game Elements:
What objects do you see? What are their properties?
- The game features one large green object (the player’s ship) and multiple small red enemies.
- Background: Black.
- Shapes: The ship and enemies are rectangles.
- Properties:
- Each object has dimensions (width, height).
- Each object has a background color.
- The ship starts at the top-left and has defined x (horizontal) and y (vertical) positions.
- Enemies spawn on the right with random starting positions (x, y).
2️⃣ Game Mechanics
- Ship Movement:
- The ship moves using arrow keys.
- It cannot move outside the game screen.
- Enemy Behavior:
- Enemies automatically move left at random speeds.
- They disappear when they reach the left edge.
- Game Over Condition:
- If the ship collides with an enemy, the game ends.
- When the ship is hit by an enemy, the game is over.
3️⃣ Developing the Game with Pygame
- ✅ Why Pygame?
- It simplifies game design by handling graphics, input, and game logic.
- This game is coded in just 100 lines of Python.
- We will develop it step by step together.
- 🕹 How Pygame Works
- Pygame runs a game loop that continuously updates the game screen.
- Each cycle of this loop is called a frame.
- We control the frame rate (maximum frames per second).
- 🔄 In Each Frame, We:
- Check for user input (key presses).
- Update the ship’s position based on input.
- Move enemies across the screen.
- Detect collisions between the ship and enemies.
- End the game if there’s a collision or the user presses ESC.
4️⃣ Program Structure
- Import libraries
- Define variables
- Initialize Pygame
- Create the ship
- Define functions:
updatePlayer()
: Update ship position
createEnemy()
: Spawn new enemies
updateEnemies()
: Move enemies across the screen
- Start the Game Loop
- Each iteration = one frame
- Check forevents (key presses)
- Create new enemies
- Set background color
- Update ship and enemies
- Detect collisions
- Draw everything on the screen
- Show the updated frame