MIT Scratch Turret Game Instructions

Create a path-following ball game with two player-controlled turrets.

Game Goal

Create a MIT Scratch game where a ball follows a path across the screen. Two turrets can rotate and shoot at the ball. The player controls the turret direction and shooting. When a bullet hits the ball, the ball disappears, an explosion animation plays, and the score increases.

Sprites Needed

  1. Ball
  2. Turret 1
  3. Turret 2
  4. Bullet 1
  5. Bullet 2
  6. Explosion
  7. Optional: Path or custom background

Variables Needed

Create the following variables for all sprites:

Part 1: Create the Background Path

  1. Click the Stage.
  2. Go to Backdrops.
  3. Draw a road or path using the paint tools.
  4. Make the path go from the left side of the screen to the right side.
  5. The ball will follow this path.

Path Ideas

Part 2: Add a Timer

Add this code to the Stage.

when green flag clicked
set [Timer v] to [0]

forever
    wait [1] seconds
    change [Timer v] by [1]
end

The timer counts how long the game has been running.

Part 3: Make the Ball Move Faster Over Time

Add this code to the Stage.

when green flag clicked
set [Ball Speed v] to [2]
set [Level v] to [1]

forever
    wait [10] seconds
    change [Level v] by [1]
    change [Ball Speed v] by [-0.2]

    if <(Ball Speed) < [0.5]> then
        set [Ball Speed v] to [0.5]
    end
end

Important: In Scratch, a larger glide time makes the ball move slower. A smaller glide time makes the ball move faster.

Part 4: Program the Ball

The ball should move along the path using several glide points.

when green flag clicked
set [Score v] to [0]
set [Ball Alive v] to [1]
show
go to x: [-220] y: [0]
point in direction [90]

forever
    if <(Ball Alive) = [1]> then
        glide (Ball Speed) secs to x: [-100] y: [80]
        glide (Ball Speed) secs to x: [0] y: [20]
        glide (Ball Speed) secs to x: [100] y: [-60]
        glide (Ball Speed) secs to x: [220] y: [0]
        go to x: [-220] y: [0]
    end
end

Part 5: Program Turret 1

Turret 1 will rotate left and right.

Turret 1 Controls

when green flag clicked
go to x: [-150] y: [-120]
point in direction [0]

forever
    if <key [a v] pressed?> then
        turn left [5] degrees
    end

    if <key [d v] pressed?> then
        turn right [5] degrees
    end
end

Part 6: Program Bullet 1

Bullet 1 should start at Turret 1, point in the same direction as Turret 1, and move forward.

when green flag clicked
hide

when [w v] key pressed
go to [Turret 1 v]
point in direction ([direction v] of [Turret 1 v])
show

repeat until <<touching [edge v]?> or <touching [Ball v]?>>
    move [10] steps
end

if <touching [Ball v]?> then
    change [Score v] by [1]
    set [Ball Alive v] to [0]
    broadcast [Ball Hit v]
end

hide

Part 7: Program Turret 2

Turret 2 will also rotate left and right.

Turret 2 Controls

when green flag clicked
go to x: [150] y: [-120]
point in direction [0]

forever
    if <key [left arrow v] pressed?> then
        turn left [5] degrees
    end

    if <key [right arrow v] pressed?> then
        turn right [5] degrees
    end
end

Part 8: Program Bullet 2

when green flag clicked
hide

when [up arrow v] key pressed
go to [Turret 2 v]
point in direction ([direction v] of [Turret 2 v])
show

repeat until <<touching [edge v]?> or <touching [Ball v]?>>
    move [10] steps
end

if <touching [Ball v]?> then
    change [Score v] by [1]
    set [Ball Alive v] to [0]
    broadcast [Ball Hit v]
end

hide

Part 9: Make the Ball Disappear When Hit

Add this code to the Ball sprite.

when I receive [Ball Hit v]
hide
wait [1] seconds
go to x: [-220] y: [0]
set [Ball Alive v] to [1]
show

This makes the ball disappear when it is hit, then respawn after 1 second.

Part 10: Add an Explosion Sprite

Create a new sprite called Explosion.

Explosion Costume Ideas

You can draw these costumes using circles, stars, or burst shapes.

Part 11: Program the Explosion Animation

Add this code to the Explosion sprite.

when green flag clicked
hide

when I receive [Ball Hit v]
go to [Ball v]
show
switch costume to [explosion1 v]
wait [0.1] seconds
next costume
wait [0.1] seconds
next costume
wait [0.1] seconds
next costume
wait [0.1] seconds
hide

This makes the explosion appear where the ball was hit.

Part 12: Timer-Based Game Over

Add this code to the Stage if you want the game to last 60 seconds.

when green flag clicked
wait [60] seconds
say [Game Over!] for [3] seconds
stop [all v]

Part 13: Score Goal

You can stop the game when the score reaches 10.

when green flag clicked
forever
    if <(Score) >= [10]> then
        say [You win!] for [3] seconds
        stop [all v]
    end
end

Final Game Requirements

Student Drop-Off Requirements into google classroom

Submit the following items:

  1. Scratch project file or Scratch share link.
  2. Screenshot of your game running.
  3. Short video showing the required game features.

Your video should show:

Suggested File Names

PX_ScratchTurretGame_lastname.sb3
PX_ScratchTurretGame_lastname.png
PX_ScratchTurretGame_lastname.mp4