Adding the enemy

Adding enemies is a great way to add game complexity and fun. Let's add an enemy that moves towards the player. Go ahead and add an enemy to the screen. I sized the enemy 30, 30 and named the sprite Enemy. This is what your layout should look like:

Adding the enemy

Next, we need to go to our event sheet and add an Every tick event.

Adding the enemy

Once you have an event sheet that looks like the preceding screenshot, you can add an action for the Enemy sprite, such as Rotate toward position. Type Player.X in the X box and Player.Y in the Y box. This sets the position to the player's X and Y locations, and it is shown in the following screenshot:

Adding the enemy

Once you have done that, add another action. This time, we need to move the enemy forward. Navigate to Add action | Enemy | Move forward, as shown in the following screenshot:

Adding the enemy

We do have to move the enemy forward a certain distance. In this case, we will set the distance to 1. You can set the distance to another number if you wish.

Adding the enemy

Your event sheet should look like the following screenshot. Now, the enemy constantly rotates towards the position of the player, while constantly moving the enemy forward. Run the game and try it out.

Adding the enemy
..................Content has been hidden....................

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