#include "DangerousRacers/Player.h"

#include <iostream>

Player::Player(const float x, const float y) : AnimatedSprite(x, y, "assets/car-animated.png", 2, 3) {
    sprite.setOrigin(sprite.getLocalBounds().width / 2, sprite.getLocalBounds().height / 2);
    sprite.setScale(2.f, 2.f);
}

void Player::setInvincibility(const float time) {
    invincibilityTimer = time;

    // if (isInvincible()) sprite.setColor({255, 255, 255, 128});
}

void Player::render(sf::RenderWindow &window) {
    AnimatedSprite::render(window);
}

void Player::update(const float deltaTime) {
    AnimatedSprite::update(deltaTime);
    invincibilityTimer -= deltaTime;
    // if (invincibilityTimer <= 0.f && sprite.getColor().a != 255)
    //     sprite.setColor({255, 255, 255, 255});

    if (invincibilityTimer > 0.f) {
        sprite.setColor({255, 255, 255, static_cast<sf::Uint8>(255 * std::tanf(invincibilityTimer + 3))});
        // std::cout << std::tanf(invincibilityTimer + 3) << "\n";
    }
    else if (sprite.getColor().a != 255)
        sprite.setColor({255, 255, 255, 255});
}
