Stage 2: Move the Player Fish
Keep your Scratch project tab open all week. Open in a new tab so you don’t leave the course.
a forever loop with four key-press checks
how a sprite reacts to the player's keyboard
a fish that swims up, down, left, and right
Show the room — five minutes, end to end:
- Click your Player sprite. Click the Code tab.
- Drag in when green flag clicked (Events, yellow).
- Drag in switch costume to Fish-a, set rotation style left-right, go to x: 0 y: 10, and show.
- Drag in forever (Control). Inside it, drag four if blocks.
- For each if, drag in key (up arrow) pressed? from Sensing. Set the four keys to up, down, left, right.
- Inside each if, drag in motion blocks: change y by 2, change y by -2, point in direction -90 + change x by -2, point in direction 90 + change x by 2.
- Click the green flag. Press arrow keys. The fish swims.
Then say "Notice the fish flips when you go left. That's the rotation style."
The big idea
Today the Player Fish gets a brain. Press the arrow keys and the fish swims. Let go and it stops.
The pattern is the same one every arcade game on Earth uses: a forever loop runs many times per second, checking "is a key pressed right now?" and moving the sprite if the answer is yes. Pros call this the game loop. In Scratch it's just three words: when green flag clicked → forever → check the keys.
There's one Scratch-specific trick worth noticing today. When the fish moves left, we want it to face left — not slide sideways like a crab. We control this with rotation style. Setting it to left-right means the fish flips horizontally when it changes direction, the same way a real fish turns its body to swim the other way.
- event
- something that happens — like clicking the green flag or pressing a key
- forever loop
- a Control block that runs the same code over and over with no stop
- if/then
- a Control block that only runs its inside code when a question is true
- sensing
- block category that asks questions like 'is key X pressed?'
- rotation style
- tells Scratch how the sprite should turn — 'left-right' flips it horizontally
- X and Y
- the sprite's position numbers — X is left/right, Y is up/down
Stage 1 should be done — your Player sprite has two costumes (Fish-a, Party Hat-a) and is named Player in the sprite pane.
Build it
Step 1 — Open the code area for the Player
In the sprite pane, click the Player sprite. At the top of the editor, click the Code tab.
The code area is empty right now — no blocks. That's where we build today.
Step 2 — Make the game start clean
Every new game should start with the fish looking like a fish (not a party hat) and facing the right way. Drag these blocks into the code area:
- From Events (yellow), drag when green flag clicked. This is the start of every script.
- From Looks (purple), drag switch costume to (Fish-a). Set it to Fish-a using the dropdown.
- From Motion (blue), drag set rotation style (left-right). This is the magic flip block.
- From Motion, drag go to x: (0) y: (10). Center-ish of the stage.
- From Looks, drag show. (In case the fish was hidden at the end of the last game.)
Snap them together in that order. Your script should look like:
Player setup script
Click the green flag. The fish should jump to the center of the stage and look like Fish-a.
Step 3 — Add the forever loop
The fish is set up, but it doesn't do anything yet. We need a loop that watches the keyboard.
From Control (orange), drag forever. Snap it directly under the show block.
The forever block has an opening in the middle. Anything you put inside that opening runs again and again, many times per second.