🏆 Phase 4 · Advanced Projects 🟣 Advanced MODULE 13

Platform Jumper

⏱️ 50 min
📖 Theory + Build
🧩 5 Quiz Questions
🎮 Full Game Build
Your progress in Phase 425%
🎯 What you'll learn: How to simulate gravity in Scratch using a variable, making a character feel realistic as it falls and jumps. This is the most important technique in platform games like Mario!

Simulating Gravity with a Variable

Real gravity pulls things down faster and faster — it accelerates. In Scratch, we fake this with a velocity variable. Every frame, velocity gets a little more negative (pulling down), and the sprite's Y position changes by that velocity.

GRAVITY IN ACTION — THE VELOCITY BUILDS UP EACH FRAME
🐱
Frame 1
vel: -1
🐱
Frame 2
vel: -2
🐱
Frame 3
vel: -3
🐱
Frame 4
vel: -4
🐱
Frame 5
vel: -5
Each frame, velocity increases downward — the cat falls faster and faster!
🐱
FLOOR (colour detect)
Platform (same colour)
GOAL — reach it!
Platform 2
Gravity Algorithm — The Key to Platform Games
SCRATCH BLOCKS
-- Variables needed: velocity_y --

when 🚩 clicked
set [velocity_y] to (0)
go to x: (-180) y: (-130)

forever

  -- Apply gravity: velocity pulls sprite down --
  change [velocity_y] by (-1)     ← gravity! reduces velocity each frame
  change y by (velocity_y)       ← move by however fast we're falling

  -- On the ground or platform? Reset velocity --
  if <touching color [green]?> then   ← floor/platform colour
    set [velocity_y] to (0)
    change y by (2)               ← nudge up off surface

  -- Jump: press space when on ground --
  if <key [space] pressed?> then
    if <touching color [green]?> then  ← only jump if on ground!
      set [velocity_y] to (12)       ← positive = launch upwards

  -- Left/Right movement --
  if <key [right arrow] pressed?> then
    change x by (4)
  if <key [left arrow] pressed?> then
    change x by (-4)

Build: Platform Jumper Step by Step

1
Design the level backdrop
Draw a platform level on the Stage backdrop. Floor at the bottom in green. Add 3-5 floating platforms (also green). Add a star or flag at the top-right as the goal!
2
Create the velocity variable
Create a variable called velocity_y. This stores how fast the player is moving up or down. Uncheck "Show variable" — players don't need to see it!
3
Set up the player sprite
Use a small cat or custom sprite. Set size to 40%. Place it near the bottom-left. The player must jump up the platforms to reach the goal!
4
Code the gravity loop
Add the gravity code from Section 1. Test it — the cat should fall, land on platforms, and be able to jump with Space!
5
Add the win condition
Use a separate "star" sprite as the goal. In the player's code: if touching [Star] then say "You Win! 🌟" → stop all. Or use colour detection for the goal zone!
6
Add lives and obstacles
If player falls below y:-170 → change lives by -1 → go back to start. Add a moving enemy sprite that the player must avoid!
🎮
Make the jump feel right!
The feel of a jump matters a lot! If velocity_y starts at 12 and gravity is -1, the jump arc lasts about 24 frames. Try: velocity = 10, gravity = -0.8 for a floatier jump. Velocity = 15, gravity = -1.5 for a snappier jump. Experiment!
🧩 Knowledge Check — Lesson 13
5 questions on platform game physics!
1. In Scratch gravity simulation, what does the "velocity_y" variable represent?
2. To simulate gravity, what happens to velocity_y every frame?
3. When the player jumps, what value should velocity_y be set to?
4. Why should we only allow jumping when the player is touching the ground colour?
5. What should happen to velocity_y when the player lands on a platform?
💪
Platform Challenge — Lesson 13
Gravity mastery · Advanced Level
Challenge: Moving Platforms & Collectibles! 🌟

Upgrade your platformer with moving platforms and coins to collect!

Requirements:
1. Add one platform that moves left and right using a forever + glide loop
2. Add 5 coin sprites placed on platforms — when touched: +10 score + hide coin
3. Add a moving enemy (bouncing left and right) — touching it loses a life
4. Show the total score at the end when the player reaches the goal
5. Add a double jump: allow a second jump in the air (track how many jumps used)
💡 Show hints if you're stuck
  • Moving platform: forever → glide 2 secs to x:100 y:0 → glide 2 secs to x:-100 y:0
  • Double jump: create variable jumps_left (set to 2). Each jump: if jumps_left > 0 then set vel to 12, change jumps_left by -1. Reset to 2 on landing.
  • Coins: when touching [Coin sprite] then score +10, hide coin
  • Enemy: left-right glide in a loop using if on edge, bounce or manual x swaps
Finished this lesson?
Mark it complete to track your progress.
🦘

Lesson 13 Complete!

You understand gravity simulation! Next: Space Shooter — code bullets, enemies, and lives!

Module 13 of 16Phase 4 — Advanced Projects