How to Build a Simple Game with Scratch or Pygame ๐ŸŽฎ๐Ÿ

Boomi Nathan
6 Min Read
Disclosure: This website may contain affiliate links, which means I may earn a commission if you click on the link and make a purchase. I only recommend products or services that I personally use and believe will add value to my readers. Your support is appreciated!

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!

  • 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! ๐ŸŽฎ๐Ÿ”ฅ

Share This Article

J. BoomiNathan is a writer at SenseCentral who specializes in making tech easy to understand. He covers mobile apps, software, troubleshooting, and step-by-step tutorials designed for real peopleโ€”not just experts. His articles blend clear explanations with practical tips so readers can solve problems faster and make smarter digital choices. He enjoys breaking down complicated tools into simple, usable steps.