Añadida la animación de morir
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "player.h"
|
||||
|
||||
// Constructor
|
||||
Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map, Debug *debug, int *diamonds)
|
||||
Player::Player(player_t player, SDL_Renderer *renderer, Asset *asset, Input *input, Map *map, Debug *debug, int *diamonds)
|
||||
{
|
||||
this->asset = asset;
|
||||
this->renderer = renderer;
|
||||
@@ -19,14 +19,14 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map, Deb
|
||||
|
||||
w = 16;
|
||||
h = 24;
|
||||
x = 8 * map->getTileSize();
|
||||
y = 20 * map->getTileSize();
|
||||
vx = 0;
|
||||
vy = 0;
|
||||
x = player.x;
|
||||
y = player.y;
|
||||
vx = player.vx;
|
||||
vy = player.vy;
|
||||
lastPosition = {(int)x, (int)y};
|
||||
sprite->setRect({(int)x, (int)y, w, h});
|
||||
sprite->setCurrentAnimation("stand");
|
||||
sprite->setFlip(SDL_FLIP_NONE);
|
||||
sprite->setFlip(player.flip);
|
||||
|
||||
jumpStrenght = 2.0f;
|
||||
gravity = 0.3f;
|
||||
@@ -34,7 +34,7 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map, Deb
|
||||
maxVX = 1.5f;
|
||||
maxVY = 4.0f;
|
||||
|
||||
state = s_standing;
|
||||
state = player.state;
|
||||
living = l_alive;
|
||||
jumpPressed = false;
|
||||
key.insert(key.end(), {0, 0, 0, 0, 0, 0});
|
||||
@@ -61,6 +61,7 @@ Player::~Player()
|
||||
// Actualiza todas las variables
|
||||
void Player::update()
|
||||
{
|
||||
checkLivingState();
|
||||
checkInput();
|
||||
move();
|
||||
animate();
|
||||
@@ -87,6 +88,21 @@ void Player::render()
|
||||
// Comprueba las entradas y modifica variables
|
||||
void Player::checkInput()
|
||||
{
|
||||
if (living == l_dying)
|
||||
{ // Aplica fricción
|
||||
if (vx > 0.0f)
|
||||
{
|
||||
vx -= (accelX / 3);
|
||||
vx = std::max(vx, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
vx += (accelX / 3);
|
||||
vx = std::min(vx, 0.0f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE))
|
||||
{
|
||||
vx -= accelX;
|
||||
@@ -100,7 +116,7 @@ void Player::checkInput()
|
||||
sprite->setFlip(SDL_FLIP_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
{ // Aplica fricción
|
||||
if (vx > 0.0f)
|
||||
{
|
||||
vx -= accelX;
|
||||
@@ -333,7 +349,12 @@ void Player::move()
|
||||
// Anima al jugador
|
||||
void Player::animate()
|
||||
{
|
||||
if (state != s_standing)
|
||||
if (living == l_dying)
|
||||
{
|
||||
sprite->setCurrentAnimation("death");
|
||||
}
|
||||
|
||||
else if (state != s_standing)
|
||||
{
|
||||
sprite->setCurrentAnimation("jump");
|
||||
}
|
||||
@@ -531,6 +552,10 @@ void Player::checkLivingState()
|
||||
break;
|
||||
|
||||
case l_dying:
|
||||
if (sprite->animationIsCompleted())
|
||||
{
|
||||
living = l_dead;
|
||||
}
|
||||
break;
|
||||
|
||||
case l_dead:
|
||||
@@ -551,4 +576,19 @@ void Player::setLivingState(e_living value)
|
||||
e_living Player::getLivingState()
|
||||
{
|
||||
return living;
|
||||
}
|
||||
|
||||
// Obtiene algunos parametros del jugador
|
||||
player_t Player::getSpawnParams()
|
||||
{
|
||||
player_t params;
|
||||
|
||||
params.x = x;
|
||||
params.y = y;
|
||||
params.vx = vx;
|
||||
params.vy = vy;
|
||||
params.state = state;
|
||||
params.flip = sprite->getFlip();
|
||||
|
||||
return params;
|
||||
}
|
||||
Reference in New Issue
Block a user