#include <stdio.h>
#include <stdlib.h>

class Entity : public Rectangle {
  public:
    Color color = BLACK;
    Sprite2D sprite;
    int frame = 0;
    float x_velocity, y_velocity;

    Entity(void) {
        this->width  = 20;
        this->height = 20;

        this->sprite.texture = &entity_texture;
        this->sprite.width  = this->sprite.texture->width;
        this->sprite.height = this->sprite.texture->height;
    }

    void draw(void) {
        DrawSprite2D(
            this->sprite,
            frame,
            this->x,
            this->y,
            WHITE
        );
    }
};

Entity player; // entity is initialized before the texture is loaded

class Enemy : public Entity {
  public:
    bool is_agrod = false;

    Enemy(void) {
        this->x = 800 + (rand() % 500);
        if (rand() % 2) {
            this->y = SIDE_WALK1 + (rand() % SIDE_WALK1_W);
        } else {
            this->y = SIDE_WALK2 + (rand() % SIDE_WALK2_W);
        }

        this->color = RED;
        this->sprite.texture = &enemy_texture;
        this->sprite.width  = this->sprite.texture->width;
        this->sprite.height = this->sprite.texture->height;
    }

};

class Obstacle : public Entity {
  public:
    static constexpr float speed = 1.0f;

    Obstacle(void) {
        this->width  = 85;
        this->height = 45;
        this->x = -100;
        this->y = -100;

        this->color = BROWN;
    }

    void regen(void) {
        const int y_area = GAME_HEIGHT - (SIDE_WALK1 + SIDE_WALK1_W) - SIDE_WALK2_W;
        const double unit = (double)1 / (double)radical_number_generator.range_max;

        this->x = GAME_WIDTH + 10;
        this->y = (SIDE_WALK1 + SIDE_WALK1_W/2)
                + y_area * (unit * radical_number_generator())
        ;

        this->sprite.texture = &obstacle_texture;
        this->sprite.width  = this->sprite.texture->width;
        this->sprite.height = this->sprite.texture->height;
    }
};