Introduction
Have you ever wanted to create your own video game but didn’t know where to start? 🤔 Whether you’re a complete beginner or have some coding experience, Scratch and Pygame are two great tools for building games easily!
- Introduction
- Option 1: Building a Game in Scratch (No Coding Required) 🧩
- 1️⃣ Getting Started with Scratch
- 2️⃣ Creating a Simple “Catch the Falling Object” Game 🎯
- Step 1: Add Sprites & Background
- Step 2: Make the Basket Move 🚀
- Step 3: Make the Apple Fall 🍎
- 3️⃣ Test & Improve Your Game 🏆
- Option 2: Building a Game in Pygame (Python) 🐍
- 1️⃣ Installing Pygame 🛠️
- 2️⃣ Creating a Simple “Dodge the Enemy” Game 🎯
- Step 1: Import Pygame & Set Up the Game Window
- Step 2: Add the Player & Enemy Sprites 🎭
- Step 3: Make the Player Move 🕹️
- Step 4: Make the Enemy Fall & Restart
- Step 5: Detect Collisions & End Game ❌
- 6️⃣ Run Your Game! 🚀
- Bonus Features & Challenges 🏆
- Conclusion 🏁
- Scratch is a drag-and-drop visual coding tool, perfect for beginners and kids. 🧩
- Pygame is a Python library for making 2D games, ideal for those comfortable with basic coding. 🐍
In this guide, you’ll build a simple game using Scratch or Pygame and learn essential game development concepts. 🚀🎮
Option 1: Building a Game in Scratch (No Coding Required) 🧩
1️⃣ Getting Started with Scratch
✅ Go to Scratch and click “Create”.
✅ Scratch uses blocks instead of code, making it beginner-friendly.
2️⃣ Creating a Simple “Catch the Falling Object” Game 🎯
📌 Goal: Move a character left and right to catch falling apples! 🍎
Step 1: Add Sprites & Background
✅ Click “Choose a Sprite” → Pick a Basket (player).
✅ Click “Choose a Sprite” → Pick an Apple (falling object).
✅ Click “Choose a Backdrop” → Pick any background.
Step 2: Make the Basket Move 🚀
Add this code to the Basket sprite:
scratch ---- when green flag clicked forever if right arrow key pressed then change x by 10 if left arrow key pressed then change x by -10 end
✅ This makes the basket move left and right when arrow keys are pressed.
Step 3: Make the Apple Fall 🍎
Add this code to the Apple sprite:
scratch
----
when green flag clicked
forever
go to random position at top of screen
repeat until touching Basket
change y by -5
end
play sound pop
end
✅ The apple falls from the top and disappears when caught!
💡 Challenge: Add a score counter that increases when the basket catches an apple!
3️⃣ Test & Improve Your Game 🏆
🚀 Click the green flag to start playing!
💡 Bonus Features:
- Add a timer to make it more challenging. ⏳
- Add different objects (some good, some bad). 🏆💣
✅ Congratulations! 🎉 You just built a game in Scratch!
Option 2: Building a Game in Pygame (Python) 🐍
1️⃣ Installing Pygame 🛠️
If you haven’t installed Pygame yet, run this in your terminal:
bash ---- pip install pygame
✅ Now you’re ready to start coding!
2️⃣ Creating a Simple “Dodge the Enemy” Game 🎯
📌 Goal: Move a player character left and right to avoid falling enemies.
Step 1: Import Pygame & Set Up the Game Window
Create a new Python file (game.py) and add:
python
----
import pygame
pygame.init()
# Window setup
WIDTH, HEIGHT = 600, 400
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Dodge the Enemy")
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
# Game loop
running = True
while running:
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
pygame.quit()
✅ This creates a window where our game will run!
Step 2: Add the Player & Enemy Sprites 🎭
python ---- player = pygame.Rect(250, 350, 50, 50) # x, y, width, height enemy = pygame.Rect(250, 0, 50, 50) player_speed = 5 enemy_speed = 5
✅ This defines the player (rectangle at the bottom) and an enemy (falling from the top).
Step 3: Make the Player Move 🕹️
python
----
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player.x > 0:
player.x -= player_speed
if keys[pygame.K_RIGHT] and player.x < WIDTH - 50:
player.x += player_speed
✅ Now, the player moves left and right using arrow keys!
Step 4: Make the Enemy Fall & Restart
python
----
enemy.y += enemy_speed
if enemy.y > HEIGHT:
enemy.y = 0 # Restart at the top
✅ The enemy falls and restarts when it reaches the bottom.
Step 5: Detect Collisions & End Game ❌
python
----
if player.colliderect(enemy):
print("Game Over!")
running = False
✅ If the player touches the enemy, the game ends.
6️⃣ Run Your Game! 🚀
✅ Save your file as game.py and run:
bash ---- python game.py
🚀 Now, play your Dodge the Enemy game!
Bonus Features & Challenges 🏆
Want to make your game even cooler? Try adding:
✅ A score counter (tracks how long you survive).
✅ Multiple enemies for extra difficulty.
✅ Power-ups (e.g., a shield or speed boost).
Conclusion 🏁
🎉 Congratulations! You just built a simple game using Scratch or Pygame!
✅ Scratch → Perfect for beginners, no coding needed.
✅ Pygame → Great for learning Python and building advanced games.
What’s Next?
🚀 Keep improving your game by adding more challenges and levels!
📚 Explore more Scratch projects at scratch.mit.edu.
💡 Try another Pygame tutorial—maybe a Flappy Bird clone!
🌟 The best way to learn game development is to keep building. So, go create something amazing! 🎮🔥