Lesson 9: Fruit Catching Game

Lesson Description

In this activity, students will be using PictoBlox to program their own game! With Quarky’s switches, they will learn to control a sprite, set up the environment, choose sprites, and write scripts.

Introduction

In this lesson, we are going to make a game Catch the Fruit. The game aims to make the Monkey catch as many fruits as possible by controlling it using Quarky’s switches.

Coding Steps

Follow the steps below:

  1. Open PictoBlox App, go to My Space, and click on + button to create a new file.
  2. Connect Quarky to PictoBlox.
  3. Stage Setup:
    1. Add a new backdrop named Blue Sky. You can refer to the process of adding the backdrop from Lesson 1 Activity 2 Step 2.
    2. Add two new sprites named Monkey and Apple. You can refer to the process of adding the sprite from Lesson 1 Activity 2 Step 3.
    3. Delete the Tobi sprite by clicking on the sprite and selecting the delete option.
  4. Script for Bringing the Fruits: Time to add fruits to the game! We’re going to make our Monkey catch some apples.
    1. Select the Apple sprite by clicking its icon.
    2. Add a when flag clicked block.
    3. Add a hide block from the Looks palette. This will ensure that the Apple sprite is hidden from the stage when the game begins.
    4. Go to the Control palette and add a wait () seconds block and set the waiting time to “2” seconds.
    5. Add a set size to () % block from the Looks palette and write “80”.
    6. Go to the Control palette and add a repeat () Write “100” in the white space.
    7. Inside the repeat () block, drop a create clone of () block from the Events palette. This block will ensure that multiple Apples can appear on the stage.
    8. Add a wait () seconds block and set the waiting time to “1” second.
  5. Random Appearance: A clone of the Apple sprite should appear randomly anywhere from the top of the stage and then disappear if the Monkey has caught it. Follow the steps below to write the script:
    1. Go to the Events palette and add a when I start as clone hat block into the scripting area. All the blocks under this hat block will run only when a clone of the Apple sprite is created.
    2. Add an go to x: () y: () block below the when I start as clone block from the Motion block. In the first space, add a pick random () to () block from the Operators palette. In this block, write “-200” in the first space and “200” in the second. This block will ensure that the x coordinate of the starting position of the Apple clone can be any number between -200 and 200.
    3. In the second space of the go to x: () y: () block, write 150. This will fix the y coordinate of the starting position of the Apple clone to 150.
    4. Now, drop a show block from the Looks palette below the go to x: () y: ()
    5. Add a repeat until () block from the Control palette below the show In the space inside the block, drop a touching () ? block from the Sensing palette and select “edge” from the drop-down. This will ensure that all the blocks inside the repeat until () block will run only until the clone of the Apple sprite touches one of the edges of the stage, in our case, the bottom edge
    6. Add a change y by () block from the Motion palette inside the repeat block and write “-5” in the space. The minus sign indicates that the change in the value of the y coordinate of the clone will be in the downward direction.
    7. Add an if block below the change y by () block from the Control palette. In its space, drop a touching () ? block from the Sensing palette and select “Monkey” from the drop-down.
    8. Add a wait () seconds block inside the if block and set the waiting time to “1 seconds”.
    9. Add a delete this clone block from the Control palette below the wait () seconds block.
    10. Finally, add another delete this clone block below the repeat until () block.
    11. Test the Code. Apples should start falling down.
  6. Controlling the Movements Using Quarky:
    1. Go to the Sensors palette and add a is button () pressed ? block into the scripting area. The button, L, is set as the default option.
    2. To check if L is pressed, we’ll use an if Go to the Control palette and drop an if block into the scripting area. Drop the is button () pressed ? block in the white space of the if block.
    3. If L is pressed, then, according to our logic, Tobi should move left. Therefore, go to the Motion palette and drop a move () steps block inside the if block and write -10 in the space. The “-” sign means that the direction of movement is left.
    4. However, if R is pressed, then Tobi should move right. Therefore, add another if block below the first one and drop a is button () pressed ? block in the white space.
    5. Then, go to the Motion palette and drop a move () steps block inside the if block, and write 10 in the space.
    6. Add a forever block around the entire script.
    7. To add the finishing touch, add a when flag clicked block from the Events.
    8. Add set size to () % block from the Looks palette. We’re using this block to reduce the size of the sprite to “80%” of the original size.
    9. Add go to x: () y: () We’re using it to fix the position of the sprite at the beginning of the game.
    10. Test the Code.
  7. Changing the Costumes: Monkey sprite should be selected.

    1. Drop a when flag clicked block into the scripting area.
    2. Add a forever block below the when flag clicked block
    3. Add a next costume block inside the forever block.
    4. Add a wait () seconds block below the next costume block and set the waiting time between two costumes as “3 seconds”.
  8. Sensing and Catching the Fruits:
    1. Let’s start with sensing the Apple clone first. For that, we’re going to use an if block and a touching (). block. First, drop an if block into the scripting area. Then, drop a touching () ? block inside its space and select “Apple” from the drop-down.
    2. Go to the Sound palette and drop a play sound () until done block inside the if Select “Chomp” from the drop-down. Now, it’s time for the most important thing – tracking the score. Every time the Monkey catches an Apple, the score should increase. To keep track, we’re going to create a variable.
    3. Go to the Variables palette and make a new variable named Score by clicking the Make a Variable.
    4. Drop a change () by () block from the Variables palette below the play sound () until doneScore” is selected as the default option in the first drop-down. Write “1” in the second space.
    5. Drop a forever block above the if block.
    6. To start the game with zero, add a set () to () above the foreverScore” is selected as the default option in the first drop-down. Write “0” in the second space.
    7. Finally, add a when flag clicked block to complete the script.
    8. Enjoy your game!
  9. Save the file as Monkey Game.

Activity: Output

Make sure you finish and submit the assignment, as well as take the quizbefore moving on to the next lesson.

Table of Contents