Las plataformas horizontales ya no empujan ni se queda pegado al suelo
This commit is contained in:
@@ -34,7 +34,7 @@ Player::Player(SDL_Renderer *renderer, Asset *asset, Input *input, Map *map)
|
|||||||
maxVX = 1.5f;
|
maxVX = 1.5f;
|
||||||
maxVY = 4.0f;
|
maxVY = 4.0f;
|
||||||
|
|
||||||
state = standing;
|
state = s_standing;
|
||||||
jumpPressed = false;
|
jumpPressed = false;
|
||||||
key.insert(key.end(), {0, 0, 0, 0, 0, 0});
|
key.insert(key.end(), {0, 0, 0, 0, 0, 0});
|
||||||
const SDL_Point p = {0, 0};
|
const SDL_Point p = {0, 0};
|
||||||
@@ -99,18 +99,19 @@ void Player::checkInput()
|
|||||||
|
|
||||||
if (input->checkInput(INPUT_UP, REPEAT_TRUE))
|
if (input->checkInput(INPUT_UP, REPEAT_TRUE))
|
||||||
{
|
{
|
||||||
if (state == standing)
|
if (state == s_standing)
|
||||||
{
|
{
|
||||||
if (!jumpPressed)
|
if (!jumpPressed)
|
||||||
{
|
{
|
||||||
jumpStrenght = 2.0f;
|
jumpStrenght = 2.0f;
|
||||||
vy -= jumpStrenght;
|
vy -= jumpStrenght;
|
||||||
state = jumping;
|
state = s_jumping;
|
||||||
|
isOn = f_none;
|
||||||
jumpPressed = true;
|
jumpPressed = true;
|
||||||
JA_PlaySound(sound_jump);
|
JA_PlaySound(sound_jump);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (state == jumping)
|
else if (state == s_jumping)
|
||||||
{
|
{
|
||||||
if (jumpPressed)
|
if (jumpPressed)
|
||||||
{
|
{
|
||||||
@@ -127,9 +128,9 @@ void Player::checkInput()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
jumpPressed = false;
|
jumpPressed = false;
|
||||||
if (state == jumping)
|
if (state == s_jumping)
|
||||||
{
|
{
|
||||||
state = falling;
|
state = s_falling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +139,7 @@ void Player::checkInput()
|
|||||||
void Player::addGravity()
|
void Player::addGravity()
|
||||||
{
|
{
|
||||||
// *** Falta ver pq la gravedad empuja al muñeco hacia abajo en los tiles atravesables
|
// *** Falta ver pq la gravedad empuja al muñeco hacia abajo en los tiles atravesables
|
||||||
if (state != standing)
|
if (state != s_standing)
|
||||||
{
|
{
|
||||||
vy = std::min(vy += gravity, maxVY);
|
vy = std::min(vy += gravity, maxVY);
|
||||||
}
|
}
|
||||||
@@ -227,12 +228,12 @@ void Player::move()
|
|||||||
if (vy > 0.0f)
|
if (vy > 0.0f)
|
||||||
{
|
{
|
||||||
y -= ((int)y + h) % tileSize;
|
y -= ((int)y + h) % tileSize;
|
||||||
state = standing;
|
state = s_standing;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
y += tileSize - ((int)y % tileSize);
|
y += tileSize - ((int)y % tileSize);
|
||||||
state = falling;
|
state = s_falling;
|
||||||
}
|
}
|
||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
}
|
}
|
||||||
@@ -253,14 +254,14 @@ void Player::move()
|
|||||||
// Tiene uno de los pies sobre una superficie
|
// Tiene uno de los pies sobre una superficie
|
||||||
if (isOnFloor())
|
if (isOnFloor())
|
||||||
{
|
{
|
||||||
state = standing;
|
state = s_standing;
|
||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
y -= ((int)y + h) % tileSize;
|
y -= ((int)y + h) % tileSize;
|
||||||
}
|
}
|
||||||
// Tiene ambos pies sobre el vacío
|
// Tiene ambos pies sobre el vacío
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
state = falling;
|
state = s_falling;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,14 +270,14 @@ void Player::move()
|
|||||||
// Si está cayendo
|
// Si está cayendo
|
||||||
if (going_down2)
|
if (going_down2)
|
||||||
{
|
{
|
||||||
state = falling;
|
state = s_falling;
|
||||||
// Si está alineado con el tile mira el suelo (para que no lo mire si está
|
// Si está alineado con el tile mira el suelo (para que no lo mire si está
|
||||||
// dentro de un tile atravesable y lo deje a medias)
|
// dentro de un tile atravesable y lo deje a medias)
|
||||||
if (tile_aligned2)
|
if (tile_aligned2)
|
||||||
{
|
{
|
||||||
if (isOnFloor())
|
if (isOnFloor())
|
||||||
{
|
{
|
||||||
state = standing;
|
state = s_standing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,9 +288,9 @@ void Player::move()
|
|||||||
if (isOnMovingPlatform())
|
if (isOnMovingPlatform())
|
||||||
{
|
{
|
||||||
// Detener la caída y alinearlo con la plataforma
|
// Detener la caída y alinearlo con la plataforma
|
||||||
state = standing;
|
state = s_standing;
|
||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
y = -h + map->getActorCollider(hookedOnMovingPlatform).y;
|
y = map->getActorCollider(hookedOnMovingPlatform).y - h;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,7 +299,7 @@ void Player::move()
|
|||||||
if (hookedOnMovingPlatform != -1)
|
if (hookedOnMovingPlatform != -1)
|
||||||
{
|
{
|
||||||
// Dejarlo alineado con la plataforma
|
// Dejarlo alineado con la plataforma
|
||||||
state = standing;
|
state = s_standing;
|
||||||
vy = 0.0f;
|
vy = 0.0f;
|
||||||
y = map->getActorCollider(hookedOnMovingPlatform).y - h;
|
y = map->getActorCollider(hookedOnMovingPlatform).y - h;
|
||||||
x += map->getActorIncX(hookedOnMovingPlatform);
|
x += map->getActorIncX(hookedOnMovingPlatform);
|
||||||
@@ -314,13 +315,10 @@ void Player::move()
|
|||||||
// Anima al jugador
|
// Anima al jugador
|
||||||
void Player::animate()
|
void Player::animate()
|
||||||
{
|
{
|
||||||
if (state != standing)
|
if (state != s_standing)
|
||||||
{
|
|
||||||
// if (abs(vy) > 1.0f)
|
|
||||||
{
|
{
|
||||||
sprite->setCurrentAnimation("jump");
|
sprite->setCurrentAnimation("jump");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (abs(vx) < 0.50f)
|
if (abs(vx) < 0.50f)
|
||||||
@@ -339,6 +337,11 @@ void Player::animate()
|
|||||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||||
bool Player::isOnFloor()
|
bool Player::isOnFloor()
|
||||||
{
|
{
|
||||||
|
if (isOn == f_platform)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool onFloor = false;
|
bool onFloor = false;
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
@@ -347,6 +350,16 @@ bool Player::isOnFloor()
|
|||||||
{
|
{
|
||||||
onFloor |= ((map->getTile(f) == wall) || (map->getTile(f) == passable));
|
onFloor |= ((map->getTile(f) == wall) || (map->getTile(f) == passable));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onFloor)
|
||||||
|
{
|
||||||
|
isOn = f_wall;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isOn = f_none;
|
||||||
|
}
|
||||||
|
|
||||||
return onFloor;
|
return onFloor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,6 +369,12 @@ bool Player::isOnMovingPlatform()
|
|||||||
bool onMovingPlatform = false;
|
bool onMovingPlatform = false;
|
||||||
hookedOnMovingPlatform = -1;
|
hookedOnMovingPlatform = -1;
|
||||||
|
|
||||||
|
// Si esta sobre el suelo, no puede estar tambien sobre una plataforma movil
|
||||||
|
if (isOn == f_wall)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
updateFeet();
|
updateFeet();
|
||||||
|
|
||||||
for (auto f : underFeet)
|
for (auto f : underFeet)
|
||||||
@@ -367,6 +386,11 @@ bool Player::isOnMovingPlatform()
|
|||||||
if (!onMovingPlatform)
|
if (!onMovingPlatform)
|
||||||
{
|
{
|
||||||
hookedOnMovingPlatform = -1;
|
hookedOnMovingPlatform = -1;
|
||||||
|
isOn = f_none;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isOn = f_platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
return onMovingPlatform;
|
return onMovingPlatform;
|
||||||
|
|||||||
@@ -14,9 +14,16 @@
|
|||||||
|
|
||||||
enum e_state
|
enum e_state
|
||||||
{
|
{
|
||||||
standing,
|
s_standing,
|
||||||
jumping,
|
s_jumping,
|
||||||
falling
|
s_falling
|
||||||
|
};
|
||||||
|
|
||||||
|
enum e_floor
|
||||||
|
{
|
||||||
|
f_none,
|
||||||
|
f_wall,
|
||||||
|
f_platform
|
||||||
};
|
};
|
||||||
|
|
||||||
// The player
|
// The player
|
||||||
@@ -40,6 +47,7 @@ public:
|
|||||||
e_border border; // Indica en qué borde de la pantalla está el jugador
|
e_border border; // Indica en qué borde de la pantalla está el jugador
|
||||||
SDL_Point lastPosition; // Posición anterior
|
SDL_Point lastPosition; // Posición anterior
|
||||||
int hookedOnMovingPlatform; // Índice de la plataforma movil a la que está enganchado
|
int hookedOnMovingPlatform; // Índice de la plataforma movil a la que está enganchado
|
||||||
|
e_floor isOn; // Indica sobre que tipo de suelo se encuentra
|
||||||
|
|
||||||
// Variables que afectan a la inercia del movimiento
|
// Variables que afectan a la inercia del movimiento
|
||||||
bool jumpPressed; // Indica si esta pulsada la tecla de salto
|
bool jumpPressed; // Indica si esta pulsada la tecla de salto
|
||||||
|
|||||||
2
todo.md
2
todo.md
@@ -1,6 +1,6 @@
|
|||||||
## TAREAS
|
## TAREAS
|
||||||
(A) Plataformas moviles verticales: se ha de enganchar a la vy para no verse afectado por la gravedad {cm:2022-08-29}
|
(A) Plataformas moviles verticales: se ha de enganchar a la vy para no verse afectado por la gravedad {cm:2022-08-29}
|
||||||
(A) Plataformas moviles horizontales: que no te empujen
|
(A) Plataformas moviles horizontales: que no te empujen {cm:2022-08-29}
|
||||||
(B) Plantearse hasta cuanto puede estar fuera el personaje de una plataforma. Ahora mismo con un pixel se aguanta dentro
|
(B) Plantearse hasta cuanto puede estar fuera el personaje de una plataforma. Ahora mismo con un pixel se aguanta dentro
|
||||||
(A) Colisiones más alla del mapa. Si al otro lado del mapa hay una pared, ahora mismo hace cosas raras
|
(A) Colisiones más alla del mapa. Si al otro lado del mapa hay una pared, ahora mismo hace cosas raras
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user