#include <game/agame/player.hpp>
#include <window/window.hpp>
#include <cmath>
#include <game/input.hpp>
#include <game/gamemanager.hpp>

namespace Game::AGame {
    void Player::start() {
        //mSound = Object::Sound("../resources/example.wav", Object::Format::WAV);
        //mSound.play();
        mZIndex = 100;
        Game::GameManager::setSharedData("gameStage", 1);
        Game::GameManager::setSharedData("gameScore", 0);

        int w, h;
        SDL_GetWindowSizeInPixels(Window::Window::getSDLWindowBackend(), &w, &h);

        mTransform.scaleX = 8.f;
        mTransform.scaleY = 8.f;

        mTransform.x -= mTex->getWidth() * mTransform.adjustedScaleX() / 2.f;
        mTransform.y -= mTex->getHeight() * mTransform.adjustedScaleY() / 2.f;

        LOG("W: " << w << " H: " << h);
        //mSound.~Sound();
    }

    void Player::update(float deltaTime) {
        //mTransform.rotation += 1.f; // Rotate clockwise for testing
        //mTransform.scaleX = 1.f + 1.f * std::sin(RUNNING_TIME() / 0.5f); // Pulsate scale for testing
        //mTransform.scaleY = 1.f + 0.5f * std::cos(RUNNING_TIME() / 0.5f); // Pulsate scale for testing
        //Object::Camera::getInstance().move(1.f, 0.f);

        // Simple movement
        if (Input::isKeyPressed(SDL_SCANCODE_W)) { mTransform.y -= mSpeed * deltaTime; }
        if (Input::isKeyPressed(SDL_SCANCODE_S)) { mTransform.y += mSpeed * deltaTime; }
        if (Input::isKeyPressed(SDL_SCANCODE_A)) { mTransform.x -= mSpeed * deltaTime; mIsFlipped = false; }
        if (Input::isKeyPressed(SDL_SCANCODE_D)) { mTransform.x += mSpeed * deltaTime; mIsFlipped = true; }
        mSpeed = Input::isKeyPressed(SDL_SCANCODE_LSHIFT) ? 400.f : 200.f;
    }
}