# Implements IDamageArea

### Introduction

The IDamageArea interface creates a standard way to define that an entity can deal damage to other entities. It has built-in support for teams and damage over time.

### Setting Implements IDamageArea

To set an entity as a damage area, set the property on entity in the Properties tab.

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

A game which has entities implementing IDamageArea will also need entities which implement IDamageable.

### Example - Damaging Enemies with Bullets

For this example uses two entities:

1. Bullet - an entity which implements IDamageArea and is ICollidable
2. Enemy - an entity which implements IDamageable and is ICollidable

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

The GameScreen also has a list for each and a collision relationship with an event.

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

When the bullet and enemy collide, the ShouldTakeDamage method can be used to determine if the enemy should take damage from the bullet, as shown in the following code snippet.

```
void OnEnemyListVsBulletListCollisionOccurred (Entities.Enemy enemy, Entities.Bullet bullet)
{
    if(enemy.ShouldTakeDamage(bullet))
    {
        enemy.TakeDamage(bullet.DamageAmount);
    }
}
```

The ShouldTakeDamage method is available on the Enemy since it implements the IDamageable interface, but the enemy.TakeDamage and bullet.DamageAmount are not provided automatically and must be implemented in custom code.

### DamageDealer

The IDamageArea interface includes a DamageDealer property which can be used to store a reference to the damage dealer. This is typically used if the damage area is created by another entity, and that entity needs to be referenced upon collision. For example, in a multi-player game, each player may have a separate score. If an enemy is killed by a bullet, then the player who fired that bullet should be awarded points. For example, the following code could be used to assign the DamageDealer on a bullet created inside the Player class:

```
if(WasShootPressed)
{
  var bullet = Factories.BulletFactory.CreateNew(this.X, this.Y);
  bullet.XVelocity = 100;
  bullet.DamageDealer = this;
}
```
