# Enemy Entity

### Introduction

This tutorial covers how to add an Enemy to your project. To speed up the process we'll be importing an existing entity rather than building a new one ourselves. Once imported, we will modify the entity so it has the functionality we'll need for this tutorial - specifically adding the ability for the enemy to take damage.

### Importing Enemy Entity

To import the entity

1. Download the exported entity file from here: <https://github.com/vchelaru/FlatRedBall/raw/NetStandard/Samples/Platformer/DealingDamage/Enemy.entz>
2. In Glue, right-click on the Entities folder
3. Select **Import Entity**

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-3e2a052edd25c2f2eb940944d49b674148465906%2F2021-04-img_607e09e77abbf.png?alt=media)
4. Navigate to the location where you saved the Enemy file earlier and click OK

We now have a fully-functional enemy which has:

* Collision shape named AxisAlignedRectangle
* Sprite displaying a walking animation
* Platformer values so that it can collide with solid collision
* EnemyInput object which will keep the enemy from moving (does not use the gamepad or keyboard)

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-0b92e46e137e88204c22eef828bdad0a1d37efe1%2F2021-04-img_607e0a6f79d2f.png?alt=media)

### Adding EnemyList to GameScreen

We will add a list to our GameScreen and an instance of our Enemy to Level1 so we can see the enemy in game. To add an enemy list to GameScreen:

1. Select the **Enemy** entity
2. Select the **Quick Actions** tab
3. Click the **Add Enemy List to GameScreen** button - this creates a list of enemies which we'll use to create collision relationships later
4. Click the **Add Enemy Factory** button - this allows us to create enemies in code and Tiled maps.

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-a430fa102e897323bdc75178bc79e9fe1069894d%2F2021-04-img_607e0b2c6c289.png?alt=media)

To add an enemy to your Level1:

1. Drag+drop the Enemy entity onto Level1\\

   <figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-b0d6880979242bcd13bc364292fe9b8f7121733e%2F2021-04-2021_April_19_171821.gif?alt=media" alt=""><figcaption></figcaption></figure>
2. Select **Enemy1** and click on the **Variables** tab
3. Set **X** to **160**
4. Set **Y** to **-160**

   ![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-4182f826ee3ea8b4cc64e73f1fd5bc60d765b095%2F2021-04-img_607e10dfcde24.png?alt=media)

Now we have an enemy in the game, but it falls through the level. We can fix this by telling the enemies to collide against our GameScreen's SolidCollision object:

1. Expand **GameScreen**
2. Expand the **Objects** folder
3. Drag+drop the **EnemyList** onto the **SolidCollision** object

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-f47442efd6dc840fe47d9362be1faef72e450a22%2F2021-04-2021_April_19_185117.gif?alt=media" alt=""><figcaption></figcaption></figure>

If we run the game now, the enemy will fall and land in the level next to the player.

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-5f91b51d76329fa11980c642a357365b958de47d%2F2021-04-img_607e1e1cb80cb.png?alt=media)
