Resuelto el bug de quedarse atascado en una rampa al caer

This commit is contained in:
2022-11-16 21:56:51 +01:00
parent 36c7063b3e
commit 60ea12f51d
2 changed files with 24 additions and 5 deletions

View File

@@ -99,6 +99,8 @@ Player::Player(player_t player)
#ifdef DEBUG
rx = {0, 0, 0, 0};
ry = {0, 0, 0, 0};
debugColor = {0, 255, 0};
debugPoint = {0, 0};
#endif
}
@@ -128,7 +130,7 @@ void Player::render()
SDL_RenderDrawPoint(renderer, underFeet[1].x, underFeet[1].y);
// Pinta rectangulo del jugador
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 192);
SDL_SetRenderDrawColor(renderer, debugColor.r, debugColor.g, debugColor.b, 192);
SDL_Rect rect = getRect();
SDL_RenderFillRect(renderer, &rect);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
@@ -144,6 +146,10 @@ void Player::render()
{
SDL_RenderFillRect(renderer, &ry);
}
// Pinta el punto de debug
SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
SDL_RenderDrawPoint(renderer, debugPoint.x, debugPoint.y);
}
#endif
}
@@ -293,14 +299,14 @@ void Player::checkState()
vy = 0.0f;
jumpCounter = 0;
fallCounter = 0;
/*if (!isOnFloor() && !isOnAutoSurface())
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope())
{
setState(s_falling);
vx = 0.0f;
vy = maxVY;
fallCounter++;
playFallSound();
}*/
}
}
else if (state == s_jumping)
@@ -373,6 +379,10 @@ void Player::move()
applyGravity(); // Aplica gravedad al jugador
checkState(); // Comprueba el estado del jugador
#ifdef DEBUG
debugColor = {0, 255, 0};
#endif
// Se mueve hacia la izquierda
if (vx < 0.0f)
{
@@ -544,11 +554,18 @@ void Player::move()
// Calcula la nueva posición
y = p - h;
setState(s_standing);
#ifdef DEBUG
debugColor = {255, 255, 0};
debugPoint = {(int)x + (w / 2), p};
#endif
}
else
{ // No está saltando y no hay colisón con una rampa
// Calcula la nueva posición
y += vy;
#ifdef DEBUG
debugColor = {255, 0, 0};
#endif
}
}
else

View File

@@ -89,8 +89,10 @@ public:
int maxFallHeight; // Altura maxima permitida de caída.
#ifdef DEBUG
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
SDL_Rect rx; // Rectangulo de desplazamiento para el modo debug
SDL_Rect ry; // Rectangulo de desplazamiento para el modo debug
color_t debugColor; // Color del recuadro de debug del jugador
SDL_Point debugPoint; // Punto para debug
#endif
// Comprueba las entradas y modifica variables