Lesson 1 of 0
Who doesn’t like playing games!
In this activity, we will learn how to make a sprite move with the keys of a keyboard? And create a game to catch the falling apple.
Choosing the Backdrop
Follow the steps below to add a backdrop:
Choosing the Sprite
Making the Scripts for the Monkey
- Select the Monkey sprite by clicking its icon.
- Set its initial position to 0, -100.
- We will use a when () key pressed block from the Events palette to write a small script to make the Monkey sprite move left using the left arrow key. The ‘-‘ sign indicates that the sprite should move left.
- Similarly, we will use another when () key pressed block to write a small script to make the Monkey sprite move right using the right arrow key.
Making the Script for the Apple
- Select the Apple sprite by clicking its icon.
- Set its initial position to 0,140.
- Now, when an apple falls, it falls vertically, i.e. along the Y-axis. Therefore, to make make the Apple sprite fall, we must change only the value of the y coordinate by some amount, say -5.
- We will add a wait block to make it fall slowly.
- Since it should keep falling, we will add a forever block to make it continuous.
Script for Sensing the Monkey
Now we want to check if the Apple sprite touched the Monkey sprite. We will write this script while keeping the Apple sprite selected.
- To check if the Apple sprite touched the Monkey sprite, we will use the touching () ? block from the Sensing palette and drop it inside the space of an if () then block from the Control palette.
- Now, it touches the Monkey sprite, we want it to bounce off and glide to a random position. For that, we will use two pick random () to () blocks from the Operators palette for both the x and y coordinates and drop then inside the glide () secs to x: () y: () block.
Script for Sensing the Edge
- To sense whether Apple sprite reaches the lower edge of the stage or not, we will again use the touching () ? block and drop it inside the space of another if () then block.
- If the Apple sprite touches the edge, the game should stop. For that, we will use the stop all block from the Control palette to stop all the scripts.
And we are done. Maximize the stage and enjoy the game!
Saving the File
Save the file with the name Lets Play.
Before you move on to the next lesson, a small assignment awaits you!
You must upload the PictoBlox program you wrote in this activity to the website.
Submitting the assignment is a must in order to receive the certificate after completing the course.
Follow the steps below to upload your assignment:
- Click on Choose File.
- Select the image from the pop-up window that opens up.
- Once the image is selected, click on Upload Assignment.
The allowed file type is SB3 file generated from the PictoBlox program. The maximum file size allowed is 5 MB.