Skip to main content

Programs and motion

Activity: Add a new program

Open a new file.

Drag and drop the necessary blocks so that when the green flag is clicked, the cat moves 10 steps (you did it in the blocks section)

Let's add that when you press the "a" key, the sprite rotates 90 degrees:

  1. We will have to use an Events block, specifically the "when space key pressed" block. I put space in italics because we can change it. By clicking on "space", we can change it to "a".

imagen.png

Notice that there are 2 programs in the central area. Each sprite can have several programs, which work in parallel.

IMPORTANT: The programs are identified by starting with an "Events" block whose upper part is oval.

Practical case I

The sprite moves in the direction it is pointing. There is a block that makes the sprite point to another address:

imagen.png

Make the sprite move according to the keyboard arrows.

Solution:

imagen.png


Practical case II

The position of a sprite is controlled with X and Y coordinates. The position of these coordinates on the screen is as follows:

This image is a backdrop that is already created in Scratch (XY-grid), and that you can add to your project.

Add this program to your cat.

imagen.png

What does this program do?

Solution


This program moves the object to the lower right area of the screen when the b key is pressed.

Finally, save the file as programs.sb3