How to Create a Dodge Ball Game in Scratch: A Complete Step-by-Step Tutorial for Beginners

Scratch Game

Introduction: How to Create a Dodge Ball Game in Scratch

Welcome to the ultimate Scratch game tutorial! If you've been searching for how to make a game in Scratch or looking for Scratch programming for beginners, you're in the right place.

In this blog post, we'll walk you through building an exciting Dodge Ball game in Scratch, inspired by the Kodex Academy's YouTube tutorial. This step-by-step tutorial will guide you through how to create a Dodge Ball game in Scratch from scratch! In this game, you'll control a character trying to dodge falling balls, earn points, and survive as long as possible. Along the way, you'll learn fundamental Scratch programming concepts like sprite movement, variables, collision detection, and game state management — all explained in an easy-to-follow way. So grab your computer, open Scratch, and let's build your very own interactive Dodge Ball challenge!

What You'll Learn:

  • ✅ How to set up sprites and backdrops in Scratch
  • ✅ Creating variables for scoring, lives, and ball speed
  • ✅ Programming player movement using arrow keys
  • ✅ Coding falling balls with increasing speed
  • ✅ Implementing collision detection and life tracking
  • ✅ Managing game states: Win and Game Over
  • ✅ Adding sounds and background music
  • ✅ Enhancing the game with additional features

Game Design & Objective

  • The game centers around a player-controlled sprite (Pico) that must dodge falling balls.
  • The objective is to survive until the score reaches 30 points.
  • The game ends either with a "You Win" screen (on success) or a "Game Over" screen (on losing all lives).

How to Create a Dodge Ball Game in Scratch: Step-by-step Coding

Step 1: Game Overview & Demo

The game is simple but fun — control a character (Pico) to dodge falling balls. Your score increases the longer you survive, but if a ball touches Pico, you lose a life. Survive long enough to win!

Step 2: Setting Up Your Scratch Project

  1. Create a new Scratch project at scratch.mit.edu
  2. Delete the default Scratch Cat sprite.
  3. Choose the Pico Walking sprite (or any character you like).
  4. Resize the sprite to about 60% for better gameplay.
  5. Choose a backdrop — Kodex Academy used Jurassic for the main game.
  6. Duplicate the backdrop twice, renaming them to Game Over and You Win.

Step 3: Designing Game Screens

  • On the Game Over backdrop, add red text saying "Game Over."
  • On the You Win backdrop, add pink text saying "You Win."

Feel free to customize fonts and colors for your style!

Step 4: Create Variables

Go to the Variables category and create:

  • score (for all sprites)
  • ball speed (for all sprites)
  • lives (for all sprites)

Step 5: Coding the Player (Pico)

Here's the basic code blocks you need:

when green flag clicked
go to x: -2 y: -18
set [score v] to 0
set [lives v] to 3
set [ball speed v] to -5
set rotation style [left-right v]

forever
  if then
    point in direction (90)
    change x by (10)
    next costume
  end
  if then
    point in direction (-90)
    change x by (-10)
    next costume
  end
end

This moves Pico left and right with arrow keys and changes costumes to simulate walking.

Step 6: Adding the Falling Balls

  1. Add a new sprite — use a baseball or ball.
  2. Code the ball to fall from the top with increasing speed.
when green flag clicked
show
go to y: 180
go to x: (pick random -230 to 230)

forever
  change y by (ball speed)
  if <(y position) < -170> then
    set y to 180
    set x to (pick random -230 to 230)
    play sound [pop v]
    change [score v] by 1
    change [ball speed v] by 0.2
  end
  if then
    play sound [jump v]
    change [lives v] by -1
    set y to 180
  end
end

You can duplicate the ball sprite to increase difficulty.

Step 7: Game Over & Winning Conditions

Add code to the Stage to switch backdrops based on game state:

when green flag clicked
switch backdrop to [Jurassic v]

forever
  if <(score) = 30> then
    switch backdrop to [You Win v]
    broadcast [You Win v]
  end
  if <(lives) = 0> then
    switch backdrop to [Game Over v]
    broadcast [Game Over v]
  end
end

Step 8: End Game Behavior for Sprites

For Pico and balls, add reactions on game end:

when I receive [Game Over v]
hide
stop [this script v]
when I receive [You Win v]
hide
stop [this script v]

For Pico, show messages before stopping:

when I receive [Game Over v]
say (join [Nice try! Your score is ] (score)) for 2 seconds
stop [all v]
when I receive [You Win v]
say (join [Well done! Your score is ] (score)) for 2 seconds
stop [all v]

Step 9: Adding Background Music

To make the game more immersive:

when green flag clicked
forever
  play sound [Eggs - Softer v] until done
end

You can choose any background music or upload your own sound.

Step 10: Final Testing

Test your game by clicking the green flag and try to dodge balls. Increase the number of balls or change speed variables for more challenge!

Enhancement Features and Code

1. Multiple Levels with Increasing Difficulty

Add levels and increase the speed and number of balls as player scores more.

when green flag clicked
set [level v] to 1

forever
  if <(score) > (level * 10)> then
    change [level v] by 1
    change [ball speed v] by 1
    create clone of [ball v]
  end
end

Use clones for balls to dynamically add more balls.

2. Power-Ups for Extra Lives

Create a new sprite as a heart or shield that appears randomly. If Pico touches it, increase lives.

when green flag clicked
hide
wait (pick random 10 to 30) seconds
show
go to x: (pick random -230 to 230) y: 180

forever
  change y by -5
  if then
    change [lives v] by 1
    hide
    wait (pick random 10 to 30) seconds
    show
    go to x: (pick random -230 to 230) y: 180
  end
  if <(y position) < -170> then
    hide
    wait (pick random 10 to 30) seconds
    show
    go to x: (pick random -230 to 230) y: 180
  end
end

3. High Score Saving

Scratch doesn't have built-in persistence, but you can show a high score for the session.

when green flag clicked
set [high score v] to 0

forever
  if <(score) > (high score)> then
    set [high score v] to (score)
  end
end

Display the high score on the screen using a sprite or variable monitor.

Summary

Learning Outcomes

  • Game development structure in Scratch.
  • Visual coding concepts like motion, events, variables, and conditionals.
  • Creating polished, interactive experiences with sound and visuals.
  • Debugging and refining logic using real-time testing.

Call to Action

  1. Don't forget to check out the full video tutorial: How to Create a Dodge Ball Game in Scratch | Fun & Easy Coding Game by Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. Subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we're passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links