Scratch - Cat Chasing Mouse
We are going to make a simple game where the user controls and moves a mouse around the screen using the arrow keys. The mouse will increase itβs score everytime it eats a cheese. The mouse dies when it gets caught by the cat, and the game is over.
Unsure where the blocks should be placed? Look at the header, such as π Position, that means those blocks is for the Mouse Sprite
Get started
Visit Scratch and Create a new project
Start by creating the following sprites and variables for our game:
Sprites
π Mouse Sprite
πΌ Cat Sprite
π§ Cheese Sprite
Variables
π© Score Variable
π© Highscore Cloud β Variable
π Mouse
π Position
Lets make sure that the π Mouse always starts on the left side of the screen.
when flag clicked go to x: (-180) y: (0)
π Controls
We are going to move our π Mouse with the arrow keys.
First we are starting out with forever loop when the green flag is pressed.
when flag clicked go to x: (-180) y: (0) forever
Everything inside our forever block is going to run over and over until the game is stopped.
Lets make it possible to move our π Mouse forward when we press the up arrow key.
when flag clicked go to x: (-180) y: (0) forever if <key (up arrow v) pressed?> then move (10) steps end
And make so when the down arrow key is pressed, the π Mouse will move backwards.
when flag clicked go to x: (-180) y: (0) forever if <key (up arrow v) pressed?> then move (10) steps end if <key (down arrow v) pressed?> then move (-5) steps end
Now lets add so when we press either left arrow or right arrow we change the direction of the π Mouse by rotating 15 degrees clockwise or counterclockwise.
when flag clicked go to x: (-180) y: (0) forever if <key (up arrow v) pressed?> then move (10) steps end if <key (down arrow v) pressed?> then move (-5) steps end if <key (left arrow v) pressed?> then turn ccw (15) degrees end if <key (right arrow v) pressed?> then turn cw (15) degrees end
The Mouse can now move around on the screen
π§ Cheese
π§ Position
We want the π§ Cheese to always start in the center of the screen.
when flag clicked go to x: (0) y: (0)
π§ Collision
Everytime the π Mouse collides with the π§ Cheese it should move to a random position.
when flag clicked go to (random position v) forever if <touching (mouse v)> then change[score v]by(1 go to (random position v) end
πΌ Cat
πΌ Position
The πΌ Cat should always start on the right side of the screen
when flag clicked go to x: (180) y: (0)
πΌ Movement
when flag clicked go to x: (180) y: (0) forever point in direction (mouse) move (3) steps
πΌ Collision, Highscore and Game over
When the cat collides with the mouse we first want to update the highscore, and right after we are going to end the game.
when flag clicked forever if <touching (mouse v)> then if <(score) > (highscore)> then set [highscore v] to (score) end stop [all v] end