Name: Moving Enemies Animated
Description: Here one or more enemies try to chase the player by following them.
Need for Pattern: Having a following enemy is a way to increase the challenge of the player to reach goals and to collect food. It also gives a sense of movement and excitement to the game.
Related Game Patterns: Add Animatd Enemy [required], Add Moving Enemies Patrolling [related]
Links to other Computing Patterns: , Change Listener, Systems Dynamics
This game mechanic works well when you have enough time to run away from these enemies or somehow get rid of them by shooting or jumping on them. This tutorial assumes you have already added a static enemy pattern.
As with static enemies, we need to edit out tilemap and add a new colour of tile to our tilemap and place one in a location. In this case be sure to change your design to add some black blocks.
Now follow the same kind of pattern for creating a static enemy but change the final blocks. I’ve chosen a small meteorite from the Gallery here. Having a small follower looks good.
Add a set to follow block from our Sprite section a set followingEnemy to follow mySprite with speed 40. Set this been to follow mySprite which is your player sprite.
In the block above I’ve changed the speed of the bee to be slower at 40 than the default 100 as in this example the player just has to run away from the meteorite.
Test your game to check that your changes have the desired behaviour and that there are no side effects.
To check that you are making the most of this pattern you can ask yourself the following questions:
This Game Pattern is one of many allowing you to make improvements to your platform game and to learn coding and wider computing concepts. Find more on the Game Pattern page.
This pattern may make your game much more challenging. To balance it out a potential next step may be to add the jump on enemies pattern to your game if you haven’t already.