Step-by-step guide to making snake game in scratch

Scratch 16-05-25
35 0

Tutorial plan

1- What is the Snake game ?

2- Set Up the Snake game in Scratch

 

What is the Snake game ?

The Snake game is a classic arcade-style video game where the player controls a snake that moves continuously around the screen, growing longer as it eats food. The challenge is to avoid crashing into the walls, obstacles, or the snake's own body.

Movement:

The snake moves in one direction and turns when the player presses arrow keys.

Movement is usually grid-based or continuous in four directions: up, down, left, right.

Objective:

Eat the "food" that appears randomly on the screen.

Each time the snake eats, it grows longer and the player's score increases.

Challenge:

Avoid running into the walls (edges of the screen).

Avoid running into your own body as it grows.

The game gets harder as the snake grows and there's less room to move.

 

Set Up the Snake game in Scratch

In this lesson, we will create a simple snake game with Scratch, by moving a snake using the 4 direction arrows on the keyboard. When the snake touches the mouse, two things happen: the score increases by one point and the mouse randomly changes its position.

1) Click on the Choose sprite icon

2) Select the Snake from the Scratch library

3) Explanation of the program:

The code block of the loop repeat indefinitely makes it possible to repeat its contents in an unlimited way.

If the up arrow key is pressed, the snake moves upwards.

If the down arrow key is pressed, the snake moves down.

If the right arrow key is pressed, the snake moves to the right.

If the left arrow key is pressed, the snake moves to the left.

The bounce if edge reached block checks if the snake sprite is touching the edge of the screen with the move steps block. If so, the sprite will point in a direction that reflects the direction it is from. come. It uses a line perpendicular to the edge to determine the angle of reflection.

the move 10 steps block moves the snake sprite forward 10 steps in the direction it is facing.

4) Added mouse sprite:

5) Added the code snippets in the mouse script:

On board, we must create the variable score.

The set score to 0 block is executed when the green flag is clicked.

The code block of the loop repeat indefinitely makes it possible to repeat its contents in an unlimited way.

The block touches the Snake checks if the snake touches the mouse. If this block returns true, the go to random position block changes the position of the mouse in a random fashion and the add 1 to score block increases the score variable by 1.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info