Skip to main content

Stage 7: Portal Flip

Stage 7: Portal Flip

Course progressStage 7 of 10
~90 min
Your workspace

Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.

Build

a portal that changes gravity rules

Learn

how one mode variable can reshape controls

Ship

a level twist that feels surprising but readable

Teacher demo
  1. Paint or use a Portal sprite.
  2. Create gravityMode and set it to normal on green flag.
  3. When Cube touches Portal, switch gravityMode to flipped.
  4. Change the jump script so flipped gravity pulls upward instead of downward.

The big idea

A portal is a rule changer. The sprite looks like an object, but its real job is to switch a variable that the movement code reads.

New words
mode
the current version of the rules
portal
an object that changes the player's mode
gravity flip
making the cube fall in the opposite direction
state variable
a variable that remembers what mode the game is in
Before you start

Stage 6 should be done. Score and time should work.

Use the examples

Follow the target shapes shown here so your scripts match the lesson quickly.

Make your own

Draw a custom cube, spikes, portal, or backdrop in Scratch. Keep the same sprite names so the code still works.

Finished game target
Score 240Time 38
Cube runnerSpike obstacleGravity portal

The cube stays near the left side while the level scrolls toward it. Jump timing is the whole game.

Build it

  1. Make a Portal sprite and place it on the right side.
  2. Create gravityMode for all sprites.
  3. Set gravityMode to normal when the game starts.
  4. When Cube touches Portal, set gravityMode to flipped and hide the portal.
  5. Update the gravity part of the jump loop so it uses the mode.

Portal mode switch

when green flag clicked
set [gravityMode v] to [normal]

forever
if <<touching [Portal v] ?> and <(gameOn) = (1)>> then
set [gravityMode v] to [flipped]
set [gravity v] to (1)
set [ySpeed v] to (0)
end
end
variable

gravityMode

The variable gravityMode stores the current rule set. Use words like normal and flipped so students can read the mode while debugging.

Understand it

Do not duplicate the whole movement script for the portal. Keep one movement system and let gravityMode change the values it uses.

Try this

Learning beat

Try this

Three short experiments. Predict before you run, then test your guess.

Predict first
What happens if gravity changes to 1 but ySpeed does not reset?
Compare
Try a blue portal for normal and yellow portal for flipped. Which is easier to read?
Connect
Stage 8 adds rhythm cues. How could sound warn the player that a portal is coming?

Test your stage

  • Portal is named Portal exactly.
  • Touching Portal sets gravityMode to flipped.
  • Gravity changes after portal contact.
  • The portal effect happens once per run.

If it breaks

  • If gravity feels chaotic, reset ySpeed when the mode changes.
  • If the portal triggers over and over, hide it or move it after touching.
Coach notes

Keep students moving on the default path first. Custom assets are encouraged, but the required names and variables are not optional. If debugging takes more than a few minutes, compare the student's sprite names, variable names, and block order against the stage test list.