#include "../include/raylib-cpp.hpp"
#include "entities/entitybase.hpp"
#include <iostream>

struct player {
    float x;
    float y;
    float width;
    float height;
};

int main() {
    int screenWidth = 1920;
    int screenHeight = 1080;

    raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");

    SetTargetFPS(60);

        player Player;
        Player.x = 100.0f;
        Player.y = 100.0f;
        Player.width = 50.0f;
        Player.height = 50.0f;

        Camera2D camera = { 0 };
        camera.target = { Player.x, Player.y };
        camera.offset = { screenWidth/2.0f, screenHeight/2.0f };
        camera.rotation = 0.0f;
        camera.zoom = 1.0f;
        
        raylib::Texture logo("./src/assets/playersprite.png");
        Texture2D bg = LoadTexture("./src/assets/Dirt_01.png");
        // background.height = 1080;
        // background.width = 1920;
    
    while (!window.ShouldClose())
    {
        BeginDrawing();
        window.ClearBackground(BLACK);

        BeginMode2D(camera);

        if (IsKeyDown(KEY_S)) Player.y += 1;
        if (IsKeyDown(KEY_W)) Player.y -= 1;
        if (IsKeyDown(KEY_D)) Player.x += 1;
        if (IsKeyDown(KEY_A)) Player.x -= 1;

        camera.target = { Player.x, Player.y };

        if (IsKeyDown(KEY_Q)) camera.zoom += 0.1f;


        DrawText("Middle", 190, 200, 20, WHITE);

        // Infinite Background
        int bh = bg.height;
        int bw = bg.width;
        int offsetX = ((int)camera.target.x % bg.width);
        int offsetY = ((int)camera.target.y % bg.height);

        for (int i = -1; i <= GetScreenWidth() / bw + 1; i++) {
          for (int j = -1; j <= GetScreenHeight() / bh + 1; j++) {
            DrawTexture(
                bg,
                -offsetX + i * bw,
                -offsetY + j * bh,
                WHITE
            );
        }
    }

        logo.Draw(Player.x, Player.y);
        
        EndMode2D();
        EndDrawing();
    }

    // UnloadTexture() and CloseWindow() are called automatically.

    return 0;
}
