#include "nodes/player.h"

Player::Player() : Node()
{
    name = "Player";

    sprite = new Sprite("./resources/img/mario.png");
    hammer = new Sprite("./resources/img/hammer.png");
    hammer->localPosition = Vec2(-20, 0);

    addChild(sprite);
    addChild(hammer);

    printf("%p\n", sprite->parent);
    printf("%p\n", hammer->parent);

    worldPosition = Vec2(50, 50);
}

void Player::update()
{
    Node::update();
    move();
}

void Player::pollInputs() {
    Node::pollInputs();
}

void Player::free() {
    std::free(sprite);
    std::free(hammer);
    Node::free();
}

void Player::move()
{
    const Uint8* key_states = SDL_GetKeyboardState(nullptr);
    if(key_states[SDL_SCANCODE_RIGHT])
    {
        worldPosition.x += 1;
    }
    if (key_states[SDL_SCANCODE_LEFT])
    {
        worldPosition.x -= 1;
    }
    if (key_states[SDL_SCANCODE_UP])
    {
        worldPosition.y -= 1;
    }
    if (key_states[SDL_SCANCODE_DOWN])
    {
        worldPosition.y += 1;
    }

    if (key_states[SDL_SCANCODE_Q])
    {
        sprite->angle -= 0.05;
    }
    if (key_states[SDL_SCANCODE_E])
    {
        sprite->angle += 0.05;
    }

    if (key_states[SDL_SCANCODE_R])
    {
        sprite->scale += Vec2(0.05, 0.05);
    }
    if (key_states[SDL_SCANCODE_F])
    {
        sprite->scale -= Vec2(0.05, 0.05);
    }
}