Introduction to Scratch & Coding

Introduction to the Chase Game

  • In this lesson, we will create a fun chase game using Scratch, like a Tom and Jerry game.
  • In this game, a mouse is the player, a cat chases the mouse, and a piece of cheese gives points to the mouse.
  • If the cat touches the mouse, the game ends.
  • This lesson helps students understand movement, keyboard controls, sensing, conditions, loops, variables, and scoring in Scratch.

What Students Will Learn

  • How to move a sprite using arrow keys
  • How to change sprite direction according to movement
  • How to make another sprite chase the player
  • How to detect collisions between sprites
  • How to stop the game when a condition is met
  • How to create and use a score variable
  • How to reset positions and score when the game restarts

Adding Sprites

In this project, we will use three sprites:

  • Mouse sprite as the player
  • Cat sprite as the chaser
  • Cheese sprite for the player to collect points

How to add sprites:

  • Click on the Choose a Sprite icon at the bottom right corner
  • Select a mouse sprite
  • Select a cat sprite
  • For the cheese, click the paintbrush icon to draw your own cheese sprite:
    • Use the line tool to draw a triangle
    • Use the eraser to create holes in the cheese
    • Click Done

Coding the Mouse Sprite (Player)

Starting the Code

  • Select the mouse sprite
  • Go to Events and pick when green flag clicked

Moving the Mouse with Arrow Keys

  • Use if then blocks from Control to check key presses
  • Sensing → key space pressed, change it to arrow keys (right, left, up, down)
  • Move the sprite:
    • Right arrow: change x by 10
    • Left arrow: change x by -10
    • Up arrow: change y by 10
    • Down arrow: change y by -10
  • Wrap all four if then blocks inside a forever block

Explanation: This allows the mouse to move continuously in all four directions.

Changing Mouse Direction

  • Motion → point in direction
  • Right arrow: 90
  • Left arrow: -90
  • Up arrow: 0
  • Down arrow: 180

Explanation: Ensures the mouse faces the correct direction while moving.

Coding the Cheese Sprite

Gliding Randomly

  • Add when green flag clicked
  • Motion → glide 1 second to random position
  • Put this glide block inside a forever block

Explanation: The cheese keeps moving randomly on the stage.

Eating the Cheese

  • Add if then block from Control
  • Sensing → touching mouse
  • Looks → hide block inside the if then
  • To make the cheese reappear when restarting the game, add when green flag clicked + show block

Explanation: The cheese hides when eaten and shows again at the start.

Coding the Cat Sprite (Chaser)

Chasing the Mouse

  • Add when green flag clicked
  • Motion → point towards mouse
  • Motion → move 3 steps
  • Wrap both blocks inside a forever block

Explanation: The cat continuously follows the mouse.

Game Over Condition

  • Add if then block inside a forever loop
  • Check touching mouse from Sensing
  • Control → stop all inside the if then block

Explanation: If the cat touches the mouse, the game ends.

Setting Starting Positions

  • For all three sprites, add when green flag clicked + go to x: ___ y: ___
  • Place the mouse, cat, and cheese in different corners

Explanation: Ensures the game does not end immediately and sprites start from a fixed position.

Adding a Score

Creating the Score Variable

  • Go to Variables → Make a Variable
  • Name it score

Increasing Score

  • On the cheese sprite, under the hide block, add change score by 1

Explanation: Each time the mouse eats the cheese, the score increases.

Resetting the Score

  • Add when green flag clicked + set score to 0

Explanation: Resets the score at the start of each game.

Summary of What Students Learned

  • How to move a sprite using arrow keys
  • How to change sprite direction based on movement
  • How to make a sprite chase another sprite
  • How to detect collisions
  • How to stop the game when a condition is met
  • How to create, increase, and reset a score variable
  • How to set starting positions for sprites

Task for Students

  • Create your own chase game
  • Choose any player and chaser sprites
  • Add at least one object to collect for points
  • Try adding multiple dangers, changing speeds, or adding sound effects
  • Make your chase game more fun and challenging