This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (January 2026)
Reason: needs more explanation, e.g. at start

Needed Variables

Create this variable.

(Score)// For all sprites.

Coding the Player Sprite

Go to the Costume Library and choose the Rocketship sprite. Then, delete all the costumes except rocketship-a and rename the sprite to Player. In the costume editor, make the ship face to the right. Make sure it's centered. Then, add this code to the sprite.

when gf clicked
set size to (50)%
forever
Main Game Loop:: custom blocks
end
define Main Game Loop
if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then
point in direction (0)
move (5) steps
end
if <<key (up arrow v) pressed?> or <key (d v) pressed?>> then
point in direction (90)
move (5) steps
end
if <<key (down arrow v) pressed?> or <key (s v) pressed?>> then
point in direction (180)
move (5) steps
end
if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then
point in direction (-90)
move (5) steps
end
if <touching (Enemy v)?> then
broadcast (Death v)
end

Coding the Enemy Sprites

Choose a sprite from the library that you think is a good enemy, or draw one yourself. Create this variable in it:

(difficulty)// For this sprite only.

Then, add this code to it:

when gf clicked
hide
set [difficulty v] to (90)
forever
create clone of (myself v)
end
when I start as a clone
if <(pick random (1) to (difficulty)) = (1)> then
go to x: (0) y: (0)
point in direction (pick random (-179) to (180))
move (1000) steps // You don't need to go that far, just to the edge of the screen.
repeat until <touching (Player v)>
point towards (Player v)
move (2) steps
if <touching (Laser v)> then
start sound (Crunch v) // This sound can be found in the Sound Library.
change [difficulty v] by (-1)
delete this clone
end
end
else
delete this clone
end

Coding the Laser Sprite

Obviously, the player has to have some way to fight back against the enemies, so this sprite weaponizes the ship and allows it to fire lasers at the enemies. Paint a new sprite, draw a small red centered horizontal line, and add this code to it:

when gf clicked
hide
forever
if <key (space v) pressed?> then
create clone of (myself v)
start sound (Pew v) // This sound can be accessed via the Scratch sound library.
wait until <not <key (space v) pressed?>> // To prevent the player from firing a steady stream of lasers.
end
end
when I start as a clone
go to (Player v)
point in direction ([direction v] of (Player v):: sensing)
show
repeat until <<touching (edge v)> or <touching (Enemy v)>>
move (20) steps
end
delete this clone

Coding the Death Screen

Paint a new sprite and create a death screen. It should be big enough cover the whole screen and clearly tell the player they have died. Then, add this code to it.

when gf clicked
hide
when I receive [Death v]
go to x: (0) y: (0)
show
play sound (Boom Cloud v) until done // This sound can be found in the Scratch sound library.
stop [all v]

Keeping Score

Find this code in the bat sprite:

when gf clicked
hide
set [difficulty v] to (90)
forever
create clone of (myself v)
end
when I start as a clone
if <(pick random (1) to (difficulty)) = (1)> then
go to x: (0) y: (0)
point in direction (pick random (-179) to (180))
move (2147483647) steps // You don't need to go that far, just to the edge of the screen. This specific number is the 32-bit integer limit.
repeat until <touching (Player v)>
point towards (Player v)
move (2) steps
if <touching (Laser v)> then
start sound (Crunch v) // This sound can be found in the Sound Library.
change [difficulty v] by (-1)
delete this clone
end
end
else
delete this clone
end

And make a change. The block that is new is outlined.

when gf clicked
hide
set [difficulty v] to (90)
forever
create clone of (myself v)
end
when I start as a clone
if <(pick random (1) to (difficulty)) = (1)> then
go to x: (0) y: (0)
point in direction (pick random (-179) to (180))
move (2147483647) steps // You don't need to go that far, just to the edge of the screen. This specific number is the 32-bit integer limit.
repeat until <touching (Player v)>
point towards (Player v)
move (2) steps
if <touching (Laser v)> then
start sound (Crunch v) // This sound can be found in the Sound Library.
change [difficulty v] by (-1)
+change [score v] by (1)
delete this clone
end
end
else
delete this clone
end

Next, find this script in the player sprite:

when gf clicked
set size to (50)%
forever
Main Game Loop:: custom blocks
end
define Main Game Loop
if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then
point in direction (0)
move (5) steps
end
if <<key (up arrow v) pressed?> or <key (d v) pressed?>> then
point in direction (90)
move (5) steps
end
if <<key (down arrow v) pressed?> or <key (s v) pressed?>> then
point in direction (180)
move (5) steps
end
if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then
point in direction (-90)
move (5) steps
end
if <touching (Enemy v)?> then
broadcast (Death v)
end

And add a new block at the start. As before, it is outlined.

when gf clicked
+set [Score v] to (0)
set size to (50)%
forever
Main Game Loop:: custom blocks
end
define Main Game Loop
if <<key (up arrow v) pressed?> or <key (w v) pressed?>> then
point in direction (0)
move (5) steps
end
if <<key (up arrow v) pressed?> or <key (d v) pressed?>> then
point in direction (90)
move (5) steps
end
if <<key (down arrow v) pressed?> or <key (s v) pressed?>> then
point in direction (180)
move (5) steps
end
if <<key (left arrow v) pressed?> or <key (a v) pressed?>> then
point in direction (-90)
move (5) steps
end
if <touching (Enemy v)?> then
broadcast (Death v)
end

More Things You Can Do With This Project

You can give this game a completely different feel by simply changing the costumes. For example, with a little costume editing, it is easy to turn this game into a zombie apocalypse.

Other

A link to an example project can be found here.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.