# Flea Enemy

<figure><img src="https://1055530831-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTLAKl9MnL4UmPhZlb3vF%2Fuploads%2FsPi9CwvTsW933oVUSVKF%2Fenemy_flea_0.png?alt=media&#x26;token=bd898052-5a38-4cfd-af02-6e64a13a0676" alt=""><figcaption></figcaption></figure>

## What the Flea does

This enemy is weak compared to the others in the game, and provides the player a health and/or damage increase after defeating it in battle. The Flea also moves erratically all over the screen, potentially forcing the player to fight it.

## How it works

```csharp
private void tmrPlayerMove_Tick(object sender, EventArgs e) {
    // randomly move flea
    if (fleaFlag == true) {
        enemyFlea.Move();
        enemyFlea.MoveRand();

        // check collision with enemies and walls
        if (HitAWall(enemyFlea)) {
            enemyFlea.MoveBack();
        }
        if (HitAChar(enemyFlea, enemyPoisonPacket)) {
            enemyFlea.MoveBack();
        }
        if (HitAChar(enemyFlea, enemyCheeto)) {
            enemyFlea.MoveBack();
        }
        if (HitAChar(enemyFlea, bossKoolaid)) {
            enemyFlea.MoveBack();
        }

        // update flea's picture box
        picEnemyFlea.Location = new Point((int)enemyFlea.Position.x, (int)enemyFlea.Position.y);
    }
}
```

### Random Movement

The flea's random movement is enabled through the same method that reads the player's inputs to move. So the flea will interact similarly to the player when contacting terrain and other enemies. The actual random movement of the flea is executed by the method below, which the code passes a randomly generated int between 0-31.

```csharp
public void MoveRand(int moveDir) {
    switch (moveDir) {
        case 0:
            MoveVector(new Vector2(-1, 0)); //west
            break;
        case 1:
            MoveVector(new Vector2(+1, 0)); //east
            break;
        case 2:
            MoveVector(new Vector2(0, -1)); //north
            break;
        case 3:
            MoveVector(new Vector2(0, +1)); //south
            break;
        case 4:
            MoveVector(new Vector2(-1, -1)); //nw
            break;
        case 5:
            MoveVector(new Vector2(+1, -1)); //ne
            break;
        case 6:
            MoveVector(new Vector2(-1, +1)); //sw
            break;
        case 7:
            MoveVector(new Vector2(+1, +1)); //se
            break;
        case 8:
            this.ResetMoveSpeed();
            break;
        default:
            break;
    }
}
```

The flea's movement functions very similarly to the player's, but instead of checking for a key input, a switch case is used to randomize the direction of the flea's movement. There is a 1 in 4 chance that the flea will pick a new move direction, a 1 in 32 chance that it will momentarily stop moving all together, and will otherwise continue moving in the last selected direction.

```csharp
Enemy enemyFlea = new Enemy(CreatePosition(picEnemyFlea), CreateCollider(picEnemyFlea, PADDING), 1);
```

### Lowered Strength

The Flea's strength is lowered through passing a smaller base strength multiplier in its instantiation, resulting in it dealing half as much damage to the player compared to the other enemies.

```csharp
public Enemy(Vector2 initPos, Collider collider, int strength=2) : base(initPos, collider, strength) { }
```

The Enemy constructor calls it's parent's constructor for the overloaded variables.

```csharp
public BattleCharacter(Vector2 initPos, Collider collider, int strength=2) : base(initPos, collider)
{
    MaxHealth = 20;
    _strength = strength;
    Health = MaxHealth;
}
```

So here you can see that the Flea's strength is modified from the default.&#x20;

### Player Buffs

For the flea's player movement and damage buffs, it must be defeated in battle. It's implementation is in the following if statement, within the method that updates after each attack.

```csharp
if (enemy.Health <= 0 enemy.name == "enemyFlea") {
    Random rand = new Random();
    int buffEffect = rand.Next(2);
    
    switch (buffEffect) {
        case 0:
            player.buffHealth();
            break;
        case 1:
            player.buffAttack();
            break;
        case 2:
            player.buffHealth();
            player.buffAttack();
            break;
    }
}
```

This if statement just randomly chooses to either increase the players health, damage, or both. The implementation of the buffs are below.

```csharp
public void buffHealth(int amount = 5) {
    MaxHealth += amount;
    Health += amount;
}

//increases strength
public void buffAttack(int amount = 1) {
    _strength += amount;
}
```

MaxHealth, Health, and \_strength are attributes of the Player() class, which are essential to the battle sequences. These two methods simply increase those values by a set amount.

When the player is given a strength boost, a message will appear on the screen to notify the player.

<figure><img src="https://1055530831-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTLAKl9MnL4UmPhZlb3vF%2Fuploads%2FI8kWJyhSNUHBR6vtplki%2Fimage.png?alt=media&#x26;token=a67ef135-9ace-4d18-a29a-749b423cf5d4" alt=""><figcaption></figcaption></figure>
