Plataformas moviles completadas
This commit is contained in:
@@ -67,4 +67,10 @@ SDL_Rect &Actor::getCollider()
|
||||
actor_name_e Actor::getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int Actor::getIncX()
|
||||
{
|
||||
return sprite->getIncX();
|
||||
}
|
||||
@@ -65,6 +65,9 @@ public:
|
||||
|
||||
// Obtiene el nombre del actor
|
||||
actor_name_e getName();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,14 +21,12 @@ void ActorMovingPlatform::checkPath()
|
||||
if (sprite->getPosX() > p2.x || sprite->getPosX() < p1.x)
|
||||
{
|
||||
sprite->setVelX(sprite->getVelX() * (-1));
|
||||
//sprite->flip();
|
||||
}
|
||||
|
||||
// Comprueba los límites verticales
|
||||
if (sprite->getPosY() > p2.y || sprite->getPosY() < p1.y)
|
||||
{
|
||||
sprite->setVelY(sprite->getVelY() * (-1));
|
||||
//sprite->flip();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ private:
|
||||
// Comprueba si ha llegado al limite del recorrido para darse media vuelta
|
||||
void checkPath();
|
||||
|
||||
// Actualiza la variable
|
||||
void updateShift();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
ActorMovingPlatform(actor_t actor, SDL_Point p1, SDL_Point p2);
|
||||
|
||||
@@ -533,13 +533,25 @@ int Map::getActorName(int index)
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de colisión
|
||||
int Map::getActorCollider(int index)
|
||||
SDL_Rect Map::getActorCollider(int index)
|
||||
{
|
||||
int y = 0;
|
||||
SDL_Rect rect = {0, 0, 0, 0};
|
||||
if (index != -1)
|
||||
{
|
||||
y = actors[index]->getCollider().y;
|
||||
rect = actors[index]->getCollider();
|
||||
}
|
||||
|
||||
return y;
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Devuelve el desplazamiento relativo del actor
|
||||
int Map::getActorIncX(int index)
|
||||
{
|
||||
int shift = 0;
|
||||
if (index != -1)
|
||||
{
|
||||
shift = actors[index]->getIncX();
|
||||
}
|
||||
|
||||
return shift;
|
||||
}
|
||||
@@ -102,7 +102,10 @@ public:
|
||||
int getActorName(int index);
|
||||
|
||||
// Devuelve el rectangulo de colisión
|
||||
int getActorCollider(int index);
|
||||
SDL_Rect getActorCollider(int index);
|
||||
|
||||
// Devuelve el desplazamiento relativo del actor
|
||||
int getActorIncX(int index);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -356,4 +356,10 @@ void MovingSprite::undoMoveY()
|
||||
void MovingSprite::clearVel()
|
||||
{
|
||||
vx = vy = 0.0f;
|
||||
}
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int MovingSprite::getIncX()
|
||||
{
|
||||
return (int)x - (int)xPrev;
|
||||
}
|
||||
@@ -165,6 +165,9 @@ public:
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void clearVel();
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -198,8 +198,10 @@ void Player::move()
|
||||
lastPosition = {(int)x, (int)y};
|
||||
addGravity();
|
||||
|
||||
// Mueve en el eje X y comprueba colisiones con muros
|
||||
// Mueve en el eje X
|
||||
x += vx;
|
||||
|
||||
// Comprueba colisiones con muros
|
||||
if (checkMapCollisions())
|
||||
{
|
||||
// Recoloca
|
||||
@@ -215,6 +217,7 @@ void Player::move()
|
||||
vx = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
// Mueve en el eje Y y comprueba colisiones con muros
|
||||
y += vy;
|
||||
if (checkMapCollisions())
|
||||
@@ -260,17 +263,26 @@ void Player::move()
|
||||
}
|
||||
}
|
||||
|
||||
// Si cayendo toca una plataforma movil
|
||||
// Si está cayendo
|
||||
if (vy >= 0.0f)
|
||||
{
|
||||
state = falling;
|
||||
|
||||
if (isOnFloor())
|
||||
{
|
||||
state = standing;
|
||||
}
|
||||
|
||||
// Si no esta enganchado a una plataforma
|
||||
if (hookedOnMovingPlatform == -1)
|
||||
{
|
||||
// Si esta sobre una plataforma
|
||||
if (isOnMovingPlatform())
|
||||
{
|
||||
// Detener la caída y alinearlo con la plataforma
|
||||
state = standing;
|
||||
vy = 0.0f;
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform);
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform).y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +293,9 @@ void Player::move()
|
||||
// Dejarlo alineado con la plataforma
|
||||
state = standing;
|
||||
vy = 0.0f;
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform);
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform).y;
|
||||
x += map->getActorIncX(hookedOnMovingPlatform);
|
||||
isOnMovingPlatform();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,13 +347,14 @@ bool Player::isOnFloor()
|
||||
bool Player::isOnMovingPlatform()
|
||||
{
|
||||
bool onMovingPlatform = false;
|
||||
hookedOnMovingPlatform = -1;
|
||||
|
||||
updateFeet();
|
||||
|
||||
for (auto f : underFeet)
|
||||
{
|
||||
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
|
||||
hookedOnMovingPlatform = std::max(hookedOnMovingPlatform,(map->actorCollision(f)));
|
||||
hookedOnMovingPlatform = std::max(hookedOnMovingPlatform, (map->actorCollision(f)));
|
||||
}
|
||||
return onMovingPlatform;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user