Scratch 3.0

Essential Elements of Scratch 3.0

Programmingempire

In this article on Essential Elements of Scratch 3.0, I will explain some basic concepts for learning Scratch 3.0.

The following section describes different types of block commands in Scratch including sequential commands, conditional commands, and looping commands.

To begin with, let us see how to create some sequential commands. In order to create a Scratch project, visit the following URL.

https://scratch.mit.edu/

Next, click on the Create tab as shown below.

Create a Scratch Project
Create a Scratch Project

The following Scratch editor opens.

Scratch Editor
Scratch Editor

At first, let us create a simple project of moving sprites. Therefore, select a sprite as shown below.

Select a Sprite
Select a Sprite

After that, you need to drag the code blocks that cause this sprite to move. Hence, we select the following blocks.

  1. Go to a random position
  2. Move 30 steps
  3. Wait for 0.1 seconds
  4. Repeat above steps forever
  5. Start when green flag is clicked

As can be seen below, the above steps move the ball sprites forever.

Code Blocks for Moving a Ball

Output

Moving Ball
Moving Ball

Once we get the ball moving, we can proceed further to create a simple game. In this game, we have another paddle sprite that moves horizontally. Whenever, ball touches the paddle its color changes for certain duration. After that, again its color gets normal.

Code for Ball Sprite

At first, we take two variables z and y. While, y indicates a touch, the variable z is used for the duration, the color of ball remains changed. Therefore, initially, we set z to 20 anf y to 0. After that, in forever loop, ball goes to random position, moves 30 steps, and waits for 0.2 seconds. If the ball touches the paddle, its color changes and y becomes 1. Further, if y is 1, z decrements by 1 in each step until it becomes 0. Once z becomes 0, y and z both get their initial value of 0 and 20 respectively. After that, graphics of the ball is cleared.

Ball Sprite
Ball Sprite

Code for Paddle Sprite

Since, the paddle sprite needs to move horizontally, we take two variables x and offset. While x denotes the x coordinate, the variable offset represents change in its value. Further, the y-coordinate remains same at -150, since paddle is not moving vertically. Therefore, in the forever block, first the paddle moves to x and y coordinate. After that, the value of x changes by the offset and paddle waits for 0.1 seconds. If the value of x reaches -150, the offset becomes10. Hence, now paddle moves in right direction. Similarly, if the value of x becomes 150, the offset is again becomes -10 so that now paddle moves in left direction.

Paddle Sprite
Paddle Sprite

Output

Bouncing Ball
Bouncing Ball

You can view the project here:

https://scratch.mit.edu/projects/629113225/


Further Reading

How to Create Moving Balloons Project in Scratch 3.0

Cloning Sprites in Scratch 3.0

Getting Started with Scratch 3.0

Block Commands in Scratch 3.0

Essential Elements of Scratch 3.0

HTML Practice Exercise

Example of Column Properties in CSS

CSS Box Model

Examples of Outline Properties in CSS

Styling Links and Lists

You may also like...