using System.Numerics;
using Raylib_cs;

namespace deleteme;

public class Game
{
    private Vector2 _playerPosition = Vector2.Zero;
    private float _speed = 800f;
    private Vector2 _playerSize;
    private float _playerScale = 0.5f;
    private Texture2D _playerTexture;
    
    public Game()
    {
        Raylib.SetConfigFlags(ConfigFlags.ResizableWindow);
        Raylib.InitWindow(1280,720,"Raylib");

        _playerPosition = new Vector2(Raylib.GetScreenWidth() / 2, Raylib.GetScreenHeight() / 2);
        _playerTexture = Raylib.LoadTexture("data/images/ship.png");
        _playerSize = new Vector2(_playerTexture.Width * _playerScale, _playerTexture.Height * _playerScale);
        
        while (!Raylib.WindowShouldClose())
        {
            Update();
            Draw();
        }
    }

    private void Draw()
    {
        Raylib.BeginDrawing();
        Raylib.ClearBackground(new(10,0,30,255));
    
        DrawPlayer();
        
        Raylib.DrawText($"{_playerSize} {_playerPosition}", 5,5,20,Color.RayWhite);
        
        Raylib.EndDrawing();
    }

    private void Update()
    {
        Input();
    }
    
    private void Input()
    {
        Vector2 newPos = _playerPosition;


        if (Raylib.IsKeyDown(KeyboardKey.D) && newPos.X < Raylib.GetScreenWidth() - _playerSize.X) newPos.X += _speed *  Raylib.GetFrameTime();
        if (Raylib.IsKeyDown(KeyboardKey.A) && !(newPos.X <= 0)) newPos.X -= _speed *  Raylib.GetFrameTime();
        
        if (Raylib.IsKeyDown(KeyboardKey.W) && !(newPos.Y <= 0)) newPos.Y -= _speed *  Raylib.GetFrameTime();
        if (Raylib.IsKeyDown(KeyboardKey.S) && newPos.Y < (Raylib.GetScreenHeight() - _playerSize.Y)) newPos.Y += _speed *  Raylib.GetFrameTime();

        _playerPosition = newPos;
    }

    private void DrawPlayer()
    {
        Raylib.DrawTextureEx(_playerTexture, _playerPosition, 0, _playerScale, Color.RayWhite);
    }
}