- Open ScratchGo to scratch.mit.edu โ Click Create. You'll see: the Stage (your game window, 480ร360 pixels), the Sprite List, and the Code Blocks on the left.
- Add your first backdrop โ Shallow WaterClick the Stage thumbnail (bottom-right) โ Choose a Backdrop โ search "Underwater 1". This will be your Level 1 background. Later you'll add more backdrops for higher levels.
- Delete the cat, add a SharkRight-click the cat โ Delete. Click Choose a Sprite โ search Shark. If you can't find one, use Paint to draw a simple shark shape. Resize it so it fits comfortably on the stage (try 80px wide).
- Position the shark at the centre-leftDrag the shark to around x: -150, y: 0 on the stage. This will be its start position.
Scratch uses X and Y coordinates. The centre of the stage is (0, 0). X goes from -240 (left edge) to +240 (right edge). Y goes from -180 (bottom) to +180 (top). Every sprite has an X and Y position at all times.
- Click on the Shark sprite โ all code goes hereMake sure the shark is highlighted in the sprite list before dragging blocks.
-
Build the movement code:Press the green flag and test it. The shark should move in all 4 directions.๐ฉ when Green Flag clickedgo to x: (-150) y: (0)foreverif <key [right arrow โผ] pressed?> thenchange x by (6)point in direction (90)if <key [left arrow โผ] pressed?> thenchange x by (-6)point in direction (-90)if <key [up arrow โผ] pressed?> thenchange y by (5)if <key [down arrow โผ] pressed?> thenchange y by (-5)
- Keep the shark inside the stageAdd this inside the forever loop to stop the shark going off-screen:Or for more control, use:if on edge, bounce
if x position > 230 โ set x to 230(repeat for all 4 edges).
Now we'll create all the variables the game will need. Go to Variables โ Make a Variable for each one. Set them all to "For all sprites".
| Variable Name | Type | Starting Value | Purpose |
|---|---|---|---|
| Score | Number | 0 | Points earned by catching fish |
| HiScore | Number | 0 | Best score ever โ survives between games |
| Lives | Number | 3 | Lives remaining โ lose all = Game Over |
| Health | Number | 100 | Hit points โ drains from hazards |
| Level | Number | 1 | Current level (1โ6) |
| FishSpeed | Number | 3 | How fast fish move across the screen |
| TimeBonus | Number | 30 | Seconds left in the level โ becomes bonus points |
| PoisonActive | Boolean | 0 | 1 = shark is poisoned, 0 = shark is fine |
- Set all starting values when the green flag is clickedAdd these at the top of your shark's green flag script, above the forever loop:In Lesson 3 we'll move all of this into a proper named function calledset [Score โผ] to (0)set [Lives โผ] to (3)set [Health โผ] to (100)set [Level โผ] to (1)set [FishSpeed โผ] to (3)set [TimeBonus โผ] to (30)set [PoisonActive โผ] to (0)
startGame.
- Show Score, Lives and Health on screenTick the checkbox next to each variable in the Variables palette. They appear as monitors on the stage. Drag them to neat positions โ Score top-left, Lives top-centre, Health top-right.
- Hide FishSpeed, PoisonActive, Level from the playerUntick those checkboxes โ the player doesn't need to see those. Or right-click a monitor and choose hide.
Make the shark animate as it swims. In the Costumes tab, duplicate the shark costume and slightly move the tail fin. Then add next costume inside a wait 0.15 seconds loop running alongside your movement code.
- Ocean backdrop is displayed
- Shark sprite moves with all 4 arrow keys
- Shark stays within the stage edges
- All 8 variables are created
- Score, Lives and Health show on screen
- All values reset correctly when green flag is clicked
- You can explain: what a variable is, what a coordinate is, what a forever loop does