Snake In Scratch

  1. Snake Scratch Code
  2. Scratch Snake Game Tutorial

Want to know how to create a timer in Scratch to set a time limit for a game? Follow the instructions to create a counter that tracks each second that passes. When a specific time is reached, the timer stops counting and the game ends.

About the Scripts and Your Game

  1. As part of the exhibition “Hamster Hipster Handy” we have reprogrammed the mobile game classic “Snake” in a workshop called “Scratch the Snake”. For this the Programming-Basics-Team taught basic understanding of the logic and structure of the game, so participants could playfully learn how to use the graphical programming environment and implement the programming independently.
  2. The pen is a feature in Scratch that allows a sprite to draw shapes, plot colored pixels, and so forth on the screen with the pen blocks.Pen was introduced in Scratch 1.0.The pen is derived from Logo's turtle graphics, as are the motion blocks with which the pen is used.

Scratch Class Handbook. After being an instructor for the Saturday Morning Scratch Classes at the Museum of Art and Digital Entertainment in Oakland, CA, Al Sweigart has compiled a handbook of tips for teachers and parents interested in using Scratch to lead an after school coding club. Scratch Class Handbook PDF (version 3, updated 2020/10/07).

Scratch

The directions listed below explain how to add a timer to an existing Scratch project. You may need to adjust the scripts slightly to suit your game.

About the Timer Variable

Snake Scratch Code

The script requires the use of a variable. A variable is a factor that can change. Create a timer variable. It will be used to hold the number of seconds.

Scratch Coding Blocks Used to Create a Timer

Scratch Snake Game Tutorial

Scratch has several coding blocks that you will use to build the script:

Snake scratchboard

About the Timer Script

Before making the variable and building the script it is important to understand how the timer script works. Study the script below.

Does the timer equal 15? If no, wait 1 second and then increase the timer by 1 second. Repeat until the timer equals 15.

Game Design with a Timer Video

Watch the video to understand how a timer can be used to set a time limit for a game. If this is a coding project that you would like to make, TechnoCode has a game design coding unit. The instructions explain how to build scripts to have a player touch targets to earn points. The lessons also include a planning sheet, game consultant checklist, coding journal log, Scratch quiz, and marking sheet.

How to Create a Timer in Scratch

Game

Create a Timer Variable

  1. Open the saved game project in Scratch.
  2. Select the sprite that you will use to track the time (it might be the player).
  3. From the Variables palette, click Make a Variable.
  4. Type timer as the variable name. Click OK.
  1. Select the timer variable to display it.

Build the Script using the Timer Variable

  1. Use your skills to build this script:
    How do you want the script to start? Notice that in the sample script below, it begins with when I receive play game. This is a broadcasted message that you may have already created. If the broadcast message was not made, you can use the when Go clicked Hat block. To learn about broadcasting read the post, How to Broadcast a Message in Scratch.

Tip to Setting the Operator Coding Block:

  • View the Operator palette.
  • Drag __=50 into the if-then block .
  • Edit the number of seconds to the time limit. For example, 15.
  • View the Variable palette. Add the timer.
Snake In Scratch

Test the Timer

  1. Play the game. When done, click Stop.
    • Does the timer increase when one second passes?
    • Does the timer stop when it reaches the time limit?

Set the Timer to Zero When a New Game Begins

  1. Play the game again. Does the timer start at zero? NO, it doesn’t.
  2. Select the sprite that tracks the time.
  3. From the Variables palette, add set my variable to 0 to the start of a script. Click the Variable arrow and select timer.

WHERE SHOULD THE CODING BLOCK GO? Notice where the set timer to 0 block is located in the script above. It was placed after the when Go clicked Hat block of an existing script. Look at your scripts. Where should it be placed in your game?

  1. Play the game again. The timer should start at 0.

Programming Lessons – Coding Units

Interested in Scratch lessons? Learn more about TechnoCode published by TechnoKids Inc. TechnoCode is a technology project that includes a teacher guide, workbook, and resource files. Use the instructional materials to teach a coding unit to students in Grades 6-9.