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
- Download the exported entity file from here: https://github.com/vchelaru/FlatRedBall/raw/NetStandard/Samples/Platformer/DealingDamage/Enemy.entz
- In Glue, right-click on the Entities folder
- Select Import Entity
- 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)
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:
- Select the Enemy entity
- Select the Quick Actions tab
- Click the Add Enemy List to GameScreen button – this creates a list of enemies which we’ll use to create collision relationships later
- Click the Add Enemy Factory button – this allows us to create enemies in code and Tiled maps.
To add an enemy to your Level1:
- Drag+drop the Enemy entity onto Level1
- Select Enemy1 and click on the Variables tab
- Set X to 160
- Set Y to -160
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:
- Expand GameScreen
- Expand the Objects folder
- Drag+drop the EnemyList onto the SolidCollision object
If we run the game now, the enemy will fall and land in the level next to the player.