Trabajando en las colisiones con plataformas moviles

This commit is contained in:
2022-08-26 21:25:51 +02:00
parent dda1e049c6
commit 6b7c49aecd
7 changed files with 49 additions and 3 deletions

View File

@@ -185,6 +185,8 @@ void Game::renderDebugInfo()
//text = "checkCollision = " + std::to_string(checkCollision(p, r));
debugText->write(0, line += 6, text, -1);
text = std::to_string(map->getActorCollider(0)) + " " + std::to_string(map->getActorCollider(1));
debugText->write(0, line += 6, text, -1);
// Pinta mascaras
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 128);
SDL_Rect rect = player->sprite->getRect();

View File

@@ -530,4 +530,16 @@ int Map::getActorName(int index)
}
return -1;
}
// Devuelve el rectangulo de colisión
int Map::getActorCollider(int index)
{
int y = 0;
if (index != -1)
{
y = actors[index]->getCollider().y;
}
return y;
}

View File

@@ -100,6 +100,9 @@ public:
// Devuelve el nombre del actor a pàrtir de un índice
int getActorName(int index);
// Devuelve el rectangulo de colisión
int getActorCollider(int index);
};
#endif

View File

@@ -255,6 +255,13 @@ void Player::move()
vy = 0.0f;
y -= ((int)y + h) % tileSize;
}
// Tiene uno de los pies sobre una plataforma móvil
else if (isOnMovingPlatform())
{
state = standing;
vy = 0.0f;
y = SDKJSGHK - h-1;
}
// Tiene ambos pies sobre el vacío
else
{
@@ -308,12 +315,17 @@ bool Player::isOnFloor()
bool Player::isOnMovingPlatform()
{
bool onMovingPlatform = false;
SDKJSGHK = 0;
updateFeet();
for (auto f : underFeet)
{
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
if (onMovingPlatform)
{
SDKJSGHK = map->getActorCollider(map->actorCollision(f));
}
}
return onMovingPlatform;
}

View File

@@ -60,6 +60,8 @@ public:
JA_Sound sound_death; // Sonido al morir
JA_Sound sound_jump; // Sonido al saltar
int SDKJSGHK;
// Comprueba las entradas y modifica variables
void checkInput();