#ifndef ENEMY_H
#define ENEMY_H

#include <cpctelera.h>
#include "Actor.h"
#include "GameTypes.h"
#include "Interrupt.h"
#include "Object.h"
#include "sprites/EnemySprites.h"
#include "Map.h"
#include "Utility.h"

#define ENEMY_TYPE_BUG 1
#define ENEMY_TYPE_FISH 2
#define ENEMY_TYPE_OCTOPUS 3
#define ENEMY_TYPE_CRAB 4
#define ENEMY_TYPE_MOTH 5
#define ENEMY_TYPE_SNAIL 6
#define ENEMY_TYPE_SNAKE 7
#define ENEMY_TYPE_SCORPION 8
#define ENEMY_TYPE_LAND_BUG 9
#define ENEMY_TYPE_PLANT1 10
#define ENEMY_TYPE_PLANT2 11

// Enemy object and state.
typedef struct Enemy Enemy;

struct Enemy
{
    // Actor properties
    Object object;
    u8 health;

    // Enemy properties
    u8 type;
    u8 stunned;
    u8 redraw;
    u8 collision;
    u8 logicFlag;
};

// TODO real value, Maximum number of enemies that can be loaded from a map.
#define MAX_ENEMY_COUNT 15

// The enemy entities on the map.
extern Enemy mapEnemies[MAX_ENEMY_COUNT];

// The number of enemies on the map.
extern u8 mapEnemyCount;

// Draws all the level enemies (where in view) on the screen.
void drawEnemies();

// Draw an individual enemy on the screen.
void drawEnemy(Enemy* enemy);

// Initialises the enemies in the 
void initEnemies(u8* mapEnemyArray, u8 arraySize);

// Run enemy logic, performing enemy actions and moving.
void logicEnemies(u8 playerX, u8 playerY);

// Processes a cell that the enemy currently occupies.
u8 processEnemyCell(u8 x, u8 y, u8 enemyType);

// Damages an enemy by reducing its health and potentially destroying the enemy if it has no health.
void damageEnemy(Enemy* enemy);

// Destroys the enemy and clears it from the screen.
void destroyEnemy(Enemy* enemy);

// Checks for any enemy collisions and redraws and updates the backgrounds (this is to prevent leftovers on screen).
void checkEnemyCollisions();

// Redraws on the screen any enemies that have collided.
void drawColidedEnemies();

#endif