+21622886281
Scratch

Snake game with Scratch

Description of snake game with Scratch:

The snake game has been around for decades. It was originally played on a battery-operated handheld device known to the world as Tetris.

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 sprite Sprite 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 commentaire


Leave a comment

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

Scroll to Top