#include "const.h"
#include "player.h"

// Constructor
Player::Player(SDL_Renderer *renderer, LTexture *texture)
{
	init(renderer, texture);
}

// Destructor
Player::~Player()
{
	delete sprite;
	sprite = nullptr;
}

// Inicializa todas las variables
void Player::init(SDL_Renderer *renderer, LTexture *texture)
{
	rect = {0, 0, 16, 24};
	
	can_jump = false;
	enabled = false;
	jump_pressed_before = false;
	jump_pressed_now = false;
	for (Uint8 i = 0; i < 6; i++)
		key[i] = false;
	standing = false;
	was_on_background = false;
	
	coins = 0;
	cooldown = 0;
	jumpforce = 0;
	respawn_x = 0;
	respawn_y = 0;
	speed_x = 0;
	speed_y = 0;
	
	sprite = new AnimatedSprite();
	sprite->setTexture(texture);
	sprite->setRenderer(renderer);
	sprite->setSpriteClip(rect);
	
	sound_coin = 0;
	sound_death = 0;
	sound_jump = 0;
	
	active_animation = 0;
	direction = 0;
	lifes = 0;
	respawn_direction = 0;
}

// Resetea ciertas variables
void Player::reset()
{
}

// Actualiza todas las variables
void Player::update()
{
	sprite->setPosX(rect.x);
	sprite->setPosY(rect.y);
}

// Dibuja el objeto
void Player::render()
{
	sprite->render();
}