#pragma once
#include <stdint.h>
#include <stdlib.h>

#define MIN_DIST 100

enum DoorType { None = 0, Up, Down, Left, Right };

struct DoorHitbox {
    int16_t x, y;
    uint16_t size;
    DoorType doorType;
    DoorHitbox() : x(0), y(0), size(0), doorType(None) {}
    DoorHitbox(int16_t x, int16_t y, uint16_t size, DoorType type)
        : x(x), y(y), size(size), doorType(type) {}
};

struct Hitbox {
    int16_t x, y;
    int16_t size;
    Hitbox() : x(0), y(0), size(0) {}
    Hitbox(int16_t x, int16_t y, int16_t size) : x(x), y(y), size(size) {}
};

struct Entity {
    int16_t x, y;
    Hitbox hitbox;
    int8_t hp;
    bool visible;

    Entity() : x(0), y(0), hitbox(0, 0, 32), hp(0), visible(false) {}
    Entity(int16_t x, int16_t y, int16_t size, int8_t hp)
        : x(x), y(y), hitbox(x, y, size), hp(hp), visible(true) {}

    void update_pos_enemy(uint16_t p_x, uint16_t p_y, uint8_t speed) {
        int16_t dx = (int16_t)p_x - (int16_t)x;
        int16_t dy = (int16_t)p_y - (int16_t)y;

        if (abs(dx) > abs(dy)) {
            x += (dx > 0) ? speed : -speed;
        } else {
            y += (dy > 0) ? speed : -speed;
        }
    }

    uint8_t is_in_range(uint16_t p_x, uint16_t p_y) {
        int16_t dx = (int16_t)p_x - (int16_t)x;
        int16_t dy = (int16_t)p_y - (int16_t)y;
        uint16_t dist = abs(dx) + abs(dy);
        return dist < MIN_DIST && dist > 0;
    }
};

struct Chest {
    int16_t x, y;
    bool opened;

    Chest() : x(0), y(0), opened(false) {}
    Chest(int16_t x, int16_t y) : x(x), y(y), opened(false) {}
};
