Creating a bow and arrow

As noted, the sword is a very short ranged weapon, which poses a great risk to the player. If an enemy makes a sudden turn, which the knights do very often, they can easily hit the player before he/she has a chance to remove the enemy with the sword.

So as an alternative, we will also create a long range weapon that is much safer to use.

Prepare for lift off

We will create a bow and arrow. This will consist of two separate sprites. We will draw these sprites ourselves.

  1. We select the Paint a new sprite block.
  2. We select the brown color and the Ellipse tool.
  3. We draw a tall vertical oval shape.
  4. Next, we switch the color to transparent.
  5. Still using the Ellipse tool, we will take three bites out of the brown shape to form the limbs of the bow.
  6. Then, we will choose the light gray color.
  7. We select the Line tool and draw a straight vertical line connecting the tips of the bow limbs. This will be the bow string.
  8. When the drawing is complete, make sure it is centered properly on the costume center. For example, see the following image of how to position the costume center.
  9. We name this sprite as bow.
    Prepare for lift off

This completes the drawing of a bow. Drawing an arrow is very simple as given in the following steps:

  1. We again select the Paint a sprite block.
  2. We choose the dark gray color.
  3. With the Line tool selected, we draw a short horizontal line.
  4. We name this sprite arrow.
    Prepare for lift off

That's all we need to do. We are now ready to script these new sprites.

Engage thrusters

We will first place the bow sprite at a random place in the maze, just like we did with the sword. Because this is effectively the same sequence of instructions, we can easily copy the scripts from sword to bow:

  1. We drag both the createMaze and startGame listener from the sword to the bow to create copies.
  2. We just need to change the word to add to the items list from sword to bow.
    Engage thrusters

With that, the placement of the bow item is done. It can now be picked up by the cat. To use it, we will add scripts to the arrow sprite, which will be the active part of this weapon.

  1. Drag both the createMaze listener and the () key pressed script to arrow to make copies.
  2. First, we change the key to be pressed as a, for arrow.
  3. Then, we check using the if <items> contains <bow> block where sword has been replaced by bow.
  4. The following blocks remain the same until the instructions reach the wait 0.2 secs block. We don't need that, so we remove it from the script.
  5. We replace it with a repeat until () loop to check for collisions.
  6. We will check whether the arrow hits many different things, that is, if it is using the if touching <edge> or touching color <black>? or touching <Knight> or touching <Ghost2>? block.
  7. While the arrow hasn't touched any of the previously mentioned objects, it will repeatedly use the move 5 steps block. This will make it fly forward.
  8. Once it has touched an obstacle, we will use the hide block to hide the arrow. This block is already there.
    Engage thrusters

That completes our arrow functionality.

Objective complete – mini debriefing

The player now has two weapons to look for. Once either one of them is picked up and moved to the item list, it can be used by pressing the corresponding key.

When testing the game, we still notice a problem. The enemies won't actually be removed when hit by either of the new weapons. Only the bomb works completely as intended.

We will fix these final issues in the following step.

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

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