Scratch is a block-based coding environment. Scratch is a tool that can be used by people of all ages. Especially teachers can teach coding logic to children or can create very good educational content with Scratch. Scratch enables other programming languages to be done in a short time. Of course, you can not write all programs with you can do in other programming languages with Scratch. Because its features are restricted.
In this article we will explain how to make a sample maze game with Scratch step by step.
The objective of the Adventure Maze Game is to find the output by following the right path in the maze within 120 seconds. There is a prize(cake) on the way out. You also need to overcome obstacles (ghosts) and collect rewards (stars) while advancing through the maze. If more contact with ghosts is established, health will decrease and the game will end. It is possible to eliminate the ghosts with a bullet.
Full of the game can be reached from the following link.
https://scratch.mit.edu/projects/269897337/
Step 1: Encode the characters movements
First, open a new project with your Scratch account and make the background color a darker color. We call it a dark color because the maze will be white, so you may experience difficulties in coding in the advanced stages.
If possible, choose monochrome floor. Before adding the maze, add the character and create the basic codes that will turn up, down, left and right, as shown in the screenshot below. In this way, you will be able to focus on the movements of the character and correct the errors.
With codes here,
Step 2: Addition and coding of the maze
We can add the maze after coding the character. You can search the maze as "maze png" from visual search or download the labyrinth used in this project and upload it to your own project.
With codes here,
Stage 3: Addition and coding of ghosts
After encoding the labyrinth, you can add ghosts or any other kind of character you want after encoding. The purpose of adding these characters is to make the main character (your cat) feel hurt when they touch them. So we designed it as obstacles in front of the cat.
With codes here:
Step 4: Adding and encoding stars and point variable
After the addition of ghosts, you can perform a star or gold insertion as a reward. According to the scenario of the game, the goal is to increase the score and at the and show as much as we collected.
With codes here:
Step 5. Add and encode ammo symbol and ammo variable
After the addition of the stars we can add and encode the ammunition symbol and ammo variable. The aim here is when touch the ammunition icon it will be hidden and the ammunition variable is increased. You must add and encode oneammunition sprite and clone after encode it or your work will be extended.
With codes here:
Step 6: Setting the duration with the time variable on the scene, make setting the other variables appearing and hiding, and adjusting the sounds
After coding the ammunition, you can click on the scene to make the necessary codings. It will be provided to set the time to 120 seconds when the game is started, to decrease every second, to set the game sounds, to hide and hide the variables.
With codes here
Step 7: Adjusting the shotting
First of all we select the main character and press the space key to launch the shot broadcast with the following code block:
We then add the direction variable and make it 1 (right), - 1 (left), 2 (up), -2 (down) according to the direction we press on the main character. The reason we do this is to make the bullet move in the direction the cat is turning. We can make the direction variable a secret.
Then add the lead to be seen during the launch as a separate dummy and do the following coding.
With codes here
Step 8: Coding events when the cake is reached
If our cat runs out of the maze successfully within 120 seconds and reaches the cake, we make the following coding to ensure that the star can be seen in the color changing way. And we encode the cat and the cake are brought to the center of the screen:
With codes here
Step 9: Making the final coding for the cat
Our game is almost over. We are doing the following coding for the cat.
With codes here
Finally
Have a nice day...