forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya sube cuestas pero no las baja
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
// CAUTION!!!!! si no se gasta al final, quitar la referencia a la habitación
|
||||
|
||||
// Constructor
|
||||
Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Renderer *renderer, Asset *asset, Input *input, Room *room)
|
||||
{
|
||||
@@ -40,12 +38,15 @@ Player::Player(player_t ini, std::string tileset, std::string animation, SDL_Ren
|
||||
sprite->setHeight(16);
|
||||
|
||||
sprite->setFlip(ini.flip);
|
||||
sprite->setCurrentAnimation("walk");
|
||||
sprite->animate();
|
||||
|
||||
lastPosition = getRect();
|
||||
colliderBox = getRect();
|
||||
const SDL_Point p = {0, 0};
|
||||
colliderPoints.insert(colliderPoints.end(), {p, p, p, p, p, p, p, p});
|
||||
underFeet.insert(underFeet.end(), {p, p});
|
||||
feet.insert(feet.end(), {p, p});
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -236,6 +237,23 @@ void Player::move()
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba colisiones con rampas
|
||||
else
|
||||
{
|
||||
const tile_e slope = checkSlopes();
|
||||
// Se mueve hacia la derecha y cuesta hacia la derecha
|
||||
if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r)
|
||||
{ // Recoloca
|
||||
y = -h + room->getSlopeHeight(feet[1], t_slope_r);
|
||||
}
|
||||
|
||||
// Se mueve hacia la izquierda y cuesta hacia la izquierda
|
||||
if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l)
|
||||
{ // Recoloca
|
||||
y = -h + room->getSlopeHeight(feet[0], t_slope_l);
|
||||
}
|
||||
}
|
||||
|
||||
y += vy;
|
||||
if (checkWalls())
|
||||
{
|
||||
@@ -309,6 +327,12 @@ void Player::move()
|
||||
vy = 0.0f;
|
||||
}
|
||||
}
|
||||
// EXPERIMENTAL
|
||||
else if (checkSlopes())
|
||||
{
|
||||
state = s_standing;
|
||||
vy = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,16 +344,10 @@ void Player::move()
|
||||
// Establece la animación del jugador
|
||||
void Player::animate()
|
||||
{
|
||||
// Establece la animación
|
||||
if (vx != 0)
|
||||
{
|
||||
sprite->setCurrentAnimation("walk");
|
||||
sprite->animate();
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite->setCurrentAnimation("stand");
|
||||
}
|
||||
sprite->animate();
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado el salto al alcanzar la altura de inicio
|
||||
@@ -353,7 +371,8 @@ bool Player::isOnFloor()
|
||||
|
||||
for (auto f : underFeet)
|
||||
{
|
||||
onFloor |= ((room->getTile(f) == TILE_SOLID) || (room->getTile(f) == TILE_TRAVESSABLE));
|
||||
const tile_e tile = (room->getTile(f));
|
||||
onFloor |= (tile == t_wall || tile == t_passable || tile == t_slope_l || tile == t_slope_r);
|
||||
}
|
||||
|
||||
return onFloor;
|
||||
@@ -370,12 +389,41 @@ bool Player::checkWalls()
|
||||
|
||||
for (auto c : colliderPoints)
|
||||
{
|
||||
wall |= (room->getTile(c) == TILE_SOLID);
|
||||
wall |= (room->getTile(c) == t_wall);
|
||||
}
|
||||
|
||||
return wall;
|
||||
}
|
||||
|
||||
// Comprueba si el jugador está en una rampa
|
||||
tile_e Player::checkSlopes()
|
||||
{
|
||||
// Actualiza los puntos de colisión
|
||||
updateFeet();
|
||||
|
||||
// Comprueba si ha colisionado con una rampa
|
||||
bool slope_l = false;
|
||||
bool slope_r = false;
|
||||
|
||||
for (auto f : feet)
|
||||
{
|
||||
slope_l |= (room->getTile(f) == t_slope_l);
|
||||
slope_r |= (room->getTile(f) == t_slope_r);
|
||||
}
|
||||
|
||||
if (slope_l)
|
||||
{
|
||||
return t_slope_l;
|
||||
}
|
||||
|
||||
if (slope_r)
|
||||
{
|
||||
return t_slope_r;
|
||||
}
|
||||
|
||||
return t_empty;
|
||||
}
|
||||
|
||||
// Obtiene algunos parametros del jugador
|
||||
player_t Player::getSpawnParams()
|
||||
{
|
||||
@@ -425,6 +473,9 @@ void Player::updateFeet()
|
||||
|
||||
underFeet[0] = {p.x, p.y + h};
|
||||
underFeet[1] = {p.x + 7, p.y + h};
|
||||
|
||||
feet[0] = {p.x, p.y + h - 1};
|
||||
feet[1] = {p.x + 7, p.y + h - 1};
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
|
||||
Reference in New Issue
Block a user