Adding a bomb item

We try to get the cat to the exit of the maze, but we soon run into a problem. Most likely, all the passageways are blocked and turn out to be dead ends. There is no way to reach the exit, because the cat can't move through walls.

How could we solve this issue? Let's make holes in the walls. We will add a bomb item that the player can use to blast holes in the walls. That way, they can always reach the exit.

Prepare for lift off

We draw another new sprite that resembles a classic cartoon-style bomb with a sparkly fuse. It's easier to draw the item a bit bigger than is needed and later, scale it down with a script.

This drawing can be made with the Scratch drawing tool, by performing the following steps:

  1. First, create a black-filled circle.
  2. Then, select the Fill tool.
  3. Select white color for the foreground and black for the background.
  4. Point and click on the upper-right of the circle to create a white highlight. This makes the circle look round.
  5. Then, select the Brush tool and make sure the color used for drawing is black and the line isn't too thin.
  6. Draw a short curve at the top of the ball to make a fuse.
  7. Then, change the color to yellow.
  8. Draw a dot at the tip of the fuse to light it.

The following is a nice looking bomb in just a few steps:

Prepare for lift off

We also need a way to make the holes in the walls. Since those are stamped onto the stage, we can't really remove any elements. They are just a drawing on the canvas. What we can do is stamp over them with white. For this, we create another sprite to use as a stamp. In this case, it is important that the sprite is exactly of the right size, so it will fit the maze segments.

We can create this sprite in an external image editor as we did for the tiles. What we need is the four-way crossroad tile without the black corners (tile11). We can easily copy and adapt this tile.

If we need to draw the tile with Scratch, we can follow the same procedure as described earlier for drawing the tiles:

  1. First, create a 60 x 60 pixels red outline.
  2. Then, fill the middle row and column with a white Rectangle option.
  3. When done, fill the red outline with the transparent color to remove it:
    Prepare for lift off

It might be easier to first fill the entire space with white and then draw invisible squares in the corners using the transparent color.

Once our hole stamp is done, we can start scripting. Let's not forget to name the bomb sprite as bomb and the hole stamp as hole.

Engage thrusters

Let's first write the scripts to place the bomb:

  1. We can copy the createMaze listener script from another sprite.
  2. To this script, add a set size to () % block as follows:
    Engage thrusters

I used 50 for the value, but if your sprite was drawn bigger or smaller, you might need another value. Just experiment until the bomb fits the maze.

Then, we add another keyboard control to place a bomb using the following steps:

  1. Start the script with a when <b> key pressed block.
  2. We will make the bomb sprite to go to the cat by setting the go to <cat> block.
  3. Then, set the show block to show the bomb sprite.
  4. We have a countdown to detonation with a few messages as follows:
    • say (3) for (1) secs
    • say (2) for (1) secs
    • say (1) for (1) secs

At this point, we need another message for the explosion event. For this, perform the following steps:

  1. Add a broadcast <> block and create a new message called createHole.
  2. Then, go on to make the say (KABOOOOM!) for (0.5) secs.
  3. When it has exploded, we can set the hide block to hide the bomb sprite again:
    Engage thrusters

The next step is to create scripts for the hole sprite. This will mainly respond to the createHole message we just added. Perform the following steps:

  1. First, copy a createMaze listener to this sprite as well but not the one we just edited for the bomb, because this sprite shouldn't change in size.
  2. Then, create a second script to receive the createHole message, starting with a when I receive <createHole> block.
  3. Set the go to <bomb> block.
  4. The hole will add a broadcast block to broadcast another message for later use. Name this new message kaboom.
  5. Then, set the wait 0.1 secs block to create a small delay for the effect.
  6. Add the show block to the sprite.
  7. Add the stamp block to stamp it onto the stage. Any black segments underneath the sprite will now be overwritten.
  8. Then, add the hide block to hide the sprite again:
    Engage thrusters

If placed correctly, the bomb item should now blow holes into the black walls. Once the walls are removed, the cat is free to move on.

Objective complete – mini debriefing

We just created a sprite item to be used by the player and a functional effect to make the item work. Stamping over the stage can be an easy and effective way to change the level design. It can be used as a player instrument, as in this case. However, you could also use it for automated changes and challenges in the game, such as opening and closing doors and throwing temporary hazardous effects into the level.

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

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