In this Lesson, Students will be adding a Pirate enemy to Patrol the Maze. If the Player bumps into the Pirate, they will be sent back to the start. Open the following template. Hover Mouse below to reveal template link.
Step 1: Programming Movement
The Pirate Captain will serve as an enemy inside of the Maze. The Player will need to find a way to get past him in order to get the Treasure.
To Start, we will want to set up a Forever Loop, so that the Enemy continues to “patrol” while we are playing the Game
Inside of the Forever, we will need to place two “Glide 1 Seconds to X: Y:” blocks from the Motion section. This piece of code will cause the Sprite to “Glide” towards the coordinates that we specify.
Because we are using two glide blocks, the Pirate will move to the first position, and then to the second position. Since we have these blocks inside of a loop, the Pirate will continue moving between these two points until the game stops.
Change the numbers inside to match the numbers shown in the image to the side.
Step 2: Programming Collision
Now that our Enemy is patrolling the maze, we will need to program what is meant to happen when it collides with the player. This code will be added on Sprite1, not the Pirate Captain.