How to create a 3D game in Scratch from scratch – tutorial for kids

In this lesson we will learn how to develop our own 3D game in Scratch – a visual programming environment for children and beginner developers. Here, the script is created by dragging multi-colored command blocks. Vivid visualization involves children in learning and allows them to clearly see the results of their work – the created game or cartoon.

Despite the fact that Scratch is a program for creating 2D games, we can implement a 3D game in it if we follow certain rules, which we will talk about in this material.

Lesson prepared by a programming school for children Pixel. The tutorial is intended for children aged 8-9 years and older.

Before the lesson starts

At the end of the material we have added video instructions in case it is more convenient for you to perceive the information this way.

If you've never created a project in Scratch before and are completely new to the environment, take a look series training lessons for beginners. This will help you understand the basics, find out how the interface works and what blocks exist in the program. However, if you follow the video tutorial, you can start right away with this tutorial.

Adding sprites and explaining how a 2D game differs from a 3D format

Let's look at the differences. Imagine a picture book, the images in it are flat, as if drawn on paper. It’s the same in 2D games: characters and objects only move left and right, up and down, but do not go off the screen.

Now imagine a toy car. You can walk around it from all sides, look at it from above and below. The same thing happens in 3D games: characters and objects are three-dimensional and can be seen from different angles. Movement occurs in three dimensions: left-right, up-down and back-and-forth.

We have prepared in advance the necessary sprites for the implementation of this project: our main character is a cube-shaped slime, as well as polygons that will play the role of a gaming platform.

You can create the same ones using our life hack: to create three-dimensional cubic objects, add the “Xy-grid-30px” background from the background library. Now we can draw our sprite cell by cell to maintain the required scale. We will do this for each sprite.

Now let's add costumes to our polygons. We need the polygon to have 4 suits: an empty polygon, a polygon with a red, yellow and green dot. Now we can use the “duplicate” function and create many polygon sprites. We will make only one suit for one of them – a blue fill. This will be the initial platform where the character will spawn.

Placement of sprites on the stage

Since we made a lot of identical polygons, arranging them will not be as difficult as it might seem at first glance. The most important thing is to be able to work with coordinates. We can connect two polygons and use simple math to find out the measure of our step. For example: we see that this polygon has x= 10;y= -23;, and the neighboring one has x=40;y=-23. We simply subtract the coordinates of the first polygon from the coordinates of the second. With each polygon we will add this difference in coordinates and thus get the gaming platform we need.

Main character movement

We created our character and polygons. Let's move on to writing programs. Let’s set our character to the “spawn” polygon, for this we’ll write a small program: when the green flag is pressed and set the coordinates. We set the coordinates to be the same as the spawn polygon.

Now let's implement the movement of our character. Using the “when a key is pressed” event blocks, we set the motion control keys: W for forward movement, S for backward movement, D for right movement, A for left movement.

As you may have noticed, forward and backward movement is created using two movement blocks at once. We change both x and y. The required value for change is our step between the polygon above and below. For movement to the right and left we change only the difference in x.

Let's test the movement. As we can see, we managed to achieve a 3D effect.

Creating game mechanics

Let's move on to creating the game mechanics. Let's add two variables: “lives” and “captured”.

Let's set the initial number of lives (5) and the initial number of points (0).

Next, we will create the conditions for winning and losing the character. The slime will win if he scores 8 points, and loses if his lives are 0.

If a player touches red, 1 life is taken from him. If it touches yellow, plus one capture point. Green suit cells will help us close the levels.

Let's look at the rules of our game. There are three levels: at level 1 the slime collects only two points from captured cells (to collect a point the player must step on the yellow circle), at level 2 the player must score 5 points, and at level 3 – 8 points. Level transitions are implemented using message passing (capture, capture1 and capture2).

Let's start writing programs for our polygons. Let's set the required order for changing costumes. Pay attention to the order of the costumes in the “costumes” tab. The first suit must have a green circle, the second is empty. And the third and fourth can be swapped depending on your desire.

Pay attention to the “when will I receive the message” block. We will use it to move to another level. Level 1 – green flag, level 2 – capture, level 3 – capture1, end – capture2.

To create an ambiance, be sure to add a background. You can choose it from the gallery or draw your own – the main thing is that the colors do not confuse our sensors.

Let's test our game. And we will go through two scenarios – victory and loss.

This concludes our lesson.

Video: 3D game on Scratch

Watch the video to see how the game turned out.

***

The material was prepared by the children's IT school Pixel. If you want to know more about creating games with Scratch, visit us at courses and we will teach you everything.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *