The aim of the game is to control the kid and dodge the objects coming his way for as long as possible. You can’t dodge them forever; because basically we are playing a game of survival and the challenge essentially is to stay in the game for as long as possible. Let’s begin by explaining the rules of the game through some figures.
Lets make the game 😎
Scratch is a graphical programming language which let you interface and control your evive with laptop. If you have not installed Scratch visit here to get full instruction on installing Scratch.
To learn about the Scratch interface, visit here. There are four important things you have to know in Scratch:
We have developed these Scratch extensions containing special blocks through which you can control your evive in Scratch:
In Scratch, there are two modes in which you can work:
In this project we are using stage and sprite, hence we have to work in Scratch mode to use the block which senses the keyboard input.
You should be familiar with designing and importing backdrops and sprites while making Shoot the Bat game. If not, go through the game or few tutorials like:
The sprite for the kid is not available in the library so import it. Download them from here. The basketball, the school backdrop and the plane sprite are present in the library. Change the school backdrop name to “School”.
Select the sprite and scripts tab. He is running when he isn’t jumping or sliding. Also, we have created a bird flapping animation before (in the bat game). We know that all we have to do is to just switch between costumes as fast as possible. The various costumes for running are shown in sequence:
The Running script can easily be created.
Let us now write scripts which shall help the boy jump and slide. The costumes for jumping are given below. The 3 costumes in the middle represent time when the boy is in the air while the first and last represent the start and the end of the jump respectively. The 2nd and 4th costumes represent the times it is about to take off and touchdown respectively. While the 3rd costume represents the highest points of the jump.
Observe that, and this is important, the sprite should remain in air for more time than on ground because we are jumping.
Another thing worth noting is that when you switch costumes, your Y-coordinate should increase when you switch from 1->2 and 2->3 with the Y-coordinate for the 3rd costume having the highest Y-coordinate (height). To get an idea (of the Y-coordinate), bring your ball sprite near the boy and drag around to see which height is suitable. Make sure that the height is enough so as the boy may be able to go over the ball.
The subsequent images show the stages of sliding. Again, one has to carefully manipulate the time and height on each costume so it may be possible to slide under the plane.
Notice the increased time (in seconds) the sprite spends in costumes 3, 4 and 5, where the boy looks as if he is sliding.
We will jump and slide to avoid obstacles and run at all other times. What we need for this purpose is for the three scripts: “Running, Jumping, And Sliding” to interact with each other. We will make changes in the Running script in such a way that the Jumping and Sliding scripts “know” when to activate. The Jumping and Sliding scripts start off with the “When I receive” block. We will check if the tactile switch 1 or the tactile switch 2 of evive is pressed and then jump or slide accordingly.
We know what to do. The question is: How to do it? Worry not, for Scratch has the required blocks.
It’s time for the obstacles now. We are not yet programming our plane and ball. Instead, we are just deciding at what times they will appear on stage. We will pick a random time interval at which the plane and ball appear. See the script given below:
We first wait for a random time period from 1 to 5 seconds. Then, we want any of the ball or the plane to appear so we choose randomly between the two.
Depending on what is broadcasted (chosen), the respective scripts under the ball and the plane sprite get activated. We will now write the scripts for the ball and the plane.
Starting from the right edge, keep the Y-coordinate constant and glide the plane to the same position at the other end. Remember the plane has to disappear at the end. Hence we hide it at the end of the script. Also after going to the initial position, we show the plane. Every time the plane successfully passes the boy, Score should increase by 1. We are executing this using Change block in the variable palette.
Next, we write a script for the ball. Start the ball from (240,0). Don’t get confused; ground level (where the boy’s feet are) is at -120 (Y-coordinate).
Because the ball has to bounce on its’ way before settling down, the code is a bit complicated. We create variables X, Y and XSpeed, YSpeed to keep track of position and speeds (in horizontal and vertical directions) respectively.
In this section, we will control what happens when the game is over, i.e. either the plane or the ball has struck the boy. When the game ends, we want these things to happen:
Script for the Boy
We will check if the boy touches the plane or the ball. After that we will broadcast GAME OVER throughout the scripts. This will notify the other sprites in the game to execute their respective “GAME OVER” scripts. We will also make the kid say – “Ouch! I’m hurt”, hide the sprite and switch backdrops.
We use “stop other scripts in sprite” to avoid glitches. This option is available in the drop down of the stop block.
The ball and the plane
As soon as the ball receives GAME OVER, it stops other scripts, hides the ball and sends it to its’ starting point: (240, 0).
The same script is written for the plane too, except that its’ starting point is different from that of the ball.
Also, when you start the game, the sprites, the ball and the plane, should go to their initial position and should be invisible. Given below is the script for the same.
And the game is complete and ready for playing. You can adjust the speed of the moving objects to make the game easy or hard.
Only evive is required in this project