Adding the bomb effects

The player can now easily create a way through the maze. If something is in the way, just blow it up. That does make the game slightly easy. So let's add another challenge in the form of a points system and a way to get hurt when using the bomb.

Prepare for lift off

We need another sprite for an explosion effect to follow the detonation of the bomb. The size of this sprite doesn't have to be exact, but it's a good idea to keep it roughly the same size as a tile, 60 pixels wide and 60 pixels high.

We can draw this sprite in Scratch easily as follows:

  1. Click on the Paint new sprite icon.
  2. Select the Circle tool and draw a filled yellow circle. Press the Shift key while dragging the cursor to make it perfectly round.
  3. Next, switch to the Fill tool and select yellow for the foreground and orange for the background.
  4. Also, select the circular gradient option.
  5. Then, click the middle of the circle to fill it with a gradient, which is bright in the middle and gets darker towards the edges.
  6. Name the new sprite as explosion:
    Prepare for lift off

That completes our explosion graphic.

Engage thrusters

When the player places a bomb, he/she has to make sure that the cat will move out of the blast radius, or it will hurt and cost them points.

We will first create the explosion effect as follows, so that we can estimate our next step:

  1. Start again with copying the plain createMaze listener, without any size alterations.
  2. Then, start a new script with a when I receive <Kaboom> listener.
  3. When the explosion sprite receives this message, we will set the go to <hole> block.
  4. Then, add the set size to (0) % block to make it infinitely small.
  5. Reset the set <ghost> effect to (0) block to make the sprite solid.
  6. Then, add the show block to the sprite. At this point, it will not be visible, because its size is set to 0 percent.
  7. Then, add a repeat (20) loop to make the sprite grow in size.
  8. At each step, add the change size by (5) block. So by the end of the loop, it will be at 20*5 = 100 percent size.
  9. Set the change <ghost> effect by (5) block. This will slowly make the sprite transparent again as it grows until it becomes invisible.
  10. After the loop is done, add the hide block to hide the sprite again as follows:
    Engage thrusters

Note

There is a difference between the ghost effect and the show or hide blocks. The ghost effect can make a sprite invisible, but it will still play a part in the program. You, as a viewer, just can't see it, but the computer and other sprites can. When hiding a sprite, it is completely removed from the program. It can't be detected by anything or have any effect while hidden.

Now that the animation of the explosion is complete, we can go on to the points system. This will also function as the scoring system that determines whether the player loses or wins the game. Perform the following steps:

  1. First, click on the Make a variable button, select for all sprites, and then type points.
  2. Let's also create a variable called level to keep track of how many levels the player has completed.
  3. Both these variables may be visible on the stage. So check their checkboxes, as shown in the following screenshot:
    Engage thrusters
  4. In the Stage object, add a block to the existing script by adding the set <points> to (0) block when the Space bar key is pressed.
  5. Also add the set <level> to 0 block, as shown in the following screenshot:
    Engage thrusters
  6. Then, move on to the tileGenerator sprite. Here, set the change <level> by (1) and change <points> by (100) blocks, as shown in the following screenshot, each time a level is created:
    Engage thrusters
  7. Then go on to the cat sprite, which will get the most additions to its scripts.
  8. To change the points value, we will make a new block called changePoints.
  9. In this case, we will add an option to add a number to the function. This will be called number1 by default, which is fine. Refer to the following screenshot:
    Engage thrusters
  10. When the function runs, set the change <points> by number1 block. This is the value that we will add into the function each time we use it.
  11. Add an if () then statement to make a check.
  12. Check if points < 0.
  13. When that's the case, the sprite containing the function will show the say (No more points. Game over!) for 2 secs block.
  14. We will then set the stop <all> script to end the game, as shown in thefollowing screenshot:
    Engage thrusters

We will make use of the changePoints function in the startGame listener as follows:

  1. We will expand this script with a forever loop.
  2. In this loop, place an if () then statement.
  3. Check if the cat touches the explosion by setting the if touching <explosion> ? then block.
  4. If it does, set the changePoints (-10) block. This is where we tell the function the number it should use.
  5. After the function has completed, the cat will say Ouch! That hurt. Let's try again. in say () for (2) secs block.
  6. Then, we will call the findStartPosition function block to reset the cat to its starting position:
    Engage thrusters

A nice addition is to not only deduct points when the cat gets hit but also to pay a price when placing a bomb. That way the player can't place infinite bombs and blow up the entire level. Perform the following steps:

  1. First drag the define changePoints script to the bomb sprite to make a copy there. Unfortunately, the Scratch functions aren't universal across all sprites.
  2. Switch to the bomb sprite to add some blocks there to use the changePoints function.
  3. In the key press script, add a changePoints (-10) block to deduct ten points each time the player places a bomb:
    Engage thrusters

That's all we needed to do to create a points system and a hazard for the cat. If you wish, you can play around with the point values to change the difficulty of the game.

Objective complete – mini debriefing

With limited resources, this game has become more challenging. It's now possible to lose the game. We also keep track of how much the player has accomplished by showing the level number and number of points scored.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.205.21