๐ป Scratch Tutorials (Code)
Complete code reference for all Scratch tutorials. Copy and paste these code blocks into your Scratch projects.
๐ Download Complete Tutorial PDFs
Get the complete step-by-step PDF guides for all our Scratch tutorials. Perfect for offline learning or printing!
๐ก Tip: Each PDF contains detailed instructions, code examples, and visual guides. Download them to follow along offline or share with classmates!
๐ Table of Contents
๐ Lesson 1: Movement
๐ PDF Resources
Download the complete Movement tutorial PDFs:
๐ฅ Movement Tutorial PDF ๐ฅ Jump Mechanics PDFStep 1: Move Right
Make your character move to the right when the right arrow key is pressed.
when green flag clicked
forever
if <key [right arrow v] pressed?> then
change x by (10)
end
end
Step 2: Move Left
Make your character move to the left when the left arrow key is pressed.
when green flag clicked
forever
if <key [left arrow v] pressed?> then
change x by (-10)
end
end
Step 3: Jump Up
Make your character jump up when the space key is pressed.
when green flag clicked
forever
if <key [space v] pressed?> then
repeat (10)
change y by (5)
end
end
end
Step 4: Jump Down (Gravity)
Add gravity so the character falls back down after jumping.
when green flag clicked
forever
if <key [space v] pressed?> then
repeat (10)
change y by (5)
end
repeat (10)
change y by (-5)
end
end
end
Makey Makey: Left Pad
Connect Makey Makey left pad to move left.
when [left pad v] pressed change x by (-10)
Makey Makey: Right Pad
Connect Makey Makey right pad to move right.
when [right pad v] pressed change x by (10)
Makey Makey: Jump Pad
Connect Makey Makey space pad to jump.
when [space pad v] pressed
change y by (5)
repeat (6)
change y by (-3)
end
๐ฅ Lesson 2: Collision Detection
๐ PDF Resources
Download the complete Collision Detection tutorial PDF:
๐ฅ Jump Mechanics & Collision PDFStep 1: Create a Block Sprite
Paint a new sprite as a square block. This will be your ground/platform.
Step 2: Block Scrolling (Right to Left)
Make blocks move from right to left to create a scrolling effect.
when green flag clicked
go to x: (200) y: (-140)
forever
change x by (-5)
if <x position < (-250)> then
go to x: (250) y: (-140)
end
end
Step 3: Coin Collection
Create a coin sprite that scrolls and disappears when touched.
when green flag clicked
go to x: (155) y: (-115)
forever
change x by (-6)
if <x position < (-150)> then
go to x: (155) y: (-115)
end
if <touching [Bear-walking v]?> then
hide
wait (1) seconds
show
end
end
Step 4: Collision Detection with Ground
Prevent the character from falling through the ground.
when green flag clicked
forever
if <touching [Block v]?> then
change y by (5)
end
end
๐ฅ Lesson 3: 2-Player Controller
๐ PDF Resources
2-Player Controller tutorial resources:
Follow the code examples below. PDF coming soon!
Step 1: Player 1 (Bear) Movement โ WASD
Player 1 controls using W, A, S, D keys.
when green flag clicked
forever
if <key [a v] pressed?> then
change x by (-6)
end
if <key [d v] pressed?> then
change x by (6)
end
if <key [w v] pressed?> then
change y by (8)
repeat (6)
change y by (-3)
end
end
end
Step 2: Player 2 (Opponent) Movement โ Arrow Keys
Player 2 controls using arrow keys.
when green flag clicked
forever
if <key [left arrow v] pressed?> then
change x by (-6)
end
if <key [right arrow v] pressed?> then
change x by (6)
end
if <key [up arrow v] pressed?> then
change y by (8)
repeat (6)
change y by (-3)
end
end
end
Step 3: Health Variables
Create health variables for both players.
when green flag clicked set [Bear HP v] to (100) set [Opponent HP v] to (100)
Step 4: Attack + Hit Detection
Player 1 attacks with F key, Player 2 attacks with L key.
// Bear sprite when [f v] key pressed if <touching [Opponent v]?> then change [Opponent HP v] by (-10) end // Opponent sprite when [l v] key pressed if <touching [Bear v]?> then change [Bear HP v] by (-10) end
Step 5: Win Condition
Check if either player's health reaches 0.
forever
if <(Bear HP) <= (0)> then
say [Opponent Wins!] for (2) seconds
stop [all v]
end
if <(Opponent HP) <= (0)> then
say [Bear Wins!] for (2) seconds
stop [all v]
end
end
Step 6: Health Bars
Visual health bars that shrink as health decreases.
// Bear HP Bar sprite when green flag clicked go to x: (-200) y: (160) set size to (100) % show forever set size to (Bear HP) % end // Opponent HP Bar sprite when green flag clicked go to x: (200) y: (160) set size to (100) % show forever set size to (Opponent HP) % end
๐ Lesson 4: Projectiles & Power-ups
๐ PDF Resources
Projectiles & Power-ups tutorial resources:
Follow the code examples below. PDF coming soon!
Step 1: Projectile Sprite Setup
Create a projectile sprite and hide the original. Use clones for each shot.
// Projectile sprite
when green flag clicked
hide
define fire (startX) (startY) (direction)
go to x: (startX) y: (startY)
point in direction (direction)
create clone of [myself v]
when I start as a clone
show
repeat until <touching [edge v]?>
move (12) steps
if <touching [Opponent v]?> then
change [Opponent HP v] by (-10)
delete this clone
end
end
delete this clone
Step 2: Fire Controls + Cooldown (Player 1)
Player 1 fires with H key. Includes cooldown to prevent spamming.
// Bear sprite
when green flag clicked
set [canShoot v] to [true]
forever
if <<key [h v] pressed?> and <(canShoot) = [true]>> then
set [canShoot v] to [false]
broadcast [bear-fire v]
wait (0.5) seconds
set [canShoot v] to [true]
end
end
when I receive [bear-fire v]
call fire ((x position)) ((y position)) (90)
Step 3: Fire Controls + Cooldown (Player 2)
Player 2 fires with semicolon (;) key.
// Opponent sprite
when green flag clicked
set [canShoot v] to [true]
forever
if <<key [; v] pressed?> and <(canShoot) = [true]>> then
set [canShoot v] to [false]
broadcast [opponent-fire v]
wait (0.5) seconds
set [canShoot v] to [true]
end
end
when I receive [opponent-fire v]
call fire ((x position)) ((y position)) (-90)
Step 4: Power-ups (Speed + Heal)
Create power-ups that spawn randomly and give speed boost or heal.
// PowerUp sprite
when green flag clicked
forever
wait (10) seconds
go to x: (pick random (-200) to (200)) y: (pick random (-120) to (120))
switch costume to (pick random (1) to (2))
show
wait until <touching [Bear v]?> or <touching [Opponent v]?>
if <costume [name v] = [speed]> then
if <touching [Bear v]?> then
broadcast [bear-speed v]
else
broadcast [opponent-speed v]
end
else
if <touching [Bear v]?> then
change [Bear HP v] by (20)
else
change [Opponent HP v] by (20)
end
end
hide
end
Step 5: Speed Power-up Effect
Apply speed boost when power-up is collected.
// Bear sprite when I receive [bear-speed v] set [moveSpeed v] to (8) wait (5) seconds set [moveSpeed v] to (6)
โญ Geometry Dash Tutorial
๐ PDF Resources
Geometry Dash tutorial resources:
Follow the code examples below. PDF coming soon!
Step 1: Player Setup
Set up the player sprite at the start position.
when green flag clicked show point in direction (90) go to x: (-152) y: (-104)
Step 2: Player Jump
Make the player jump when space key is pressed.
when green flag clicked
forever
if <key [space v] pressed?> then
repeat (10)
turn cw (10) degrees
change y by (10)
end
repeat (10)
turn cw (10) degrees
change y by (-10)
end
point in direction (90)
end
end
Step 3: Spike Clones
Create spikes that spawn continuously.
// Spike sprite when green flag clicked set [score v] to (0) hide forever create clone of [myself v] wait (1) seconds end when I start as a clone show go to x: (170) y: (-108) switch costume to (pick random (1) to (3)) glide (1) secs to x: (-280) y: (y position) delete this clone
Step 4: Score System
Increase score while player is alive.
when green flag clicked
forever
repeat until <touching [spikes v]?>
change [score v] by (1)
end
end
Step 5: Game Over
End game when player touches spikes.
when green flag clicked
forever
if <touching [spikes v]?> then
switch backdrop to [game over v]
stop [all v]
end
end
when backdrop switches to [game over v]
hide
play sound [game over v] until done
๐จ Project Handouts
Download complete project tutorials! These PDFs guide you through building full games and projects from start to finish.