diff --git a/data/map/01.map b/data/map/01.map index 95577fe..0e5cdee 100644 --- a/data/map/01.map +++ b/data/map/01.map @@ -28,4 +28,19 @@ x2=15 y2=11 [/moving platform] +[moving platform] +tileset=moving_platform.png +animation=moving_platform.ani +width=16 +height=8 +x=19 +y=14 +vx=0 +vy=0.3 +x1=19 +y1=14 +x2=19 +y2=21 +[/moving platform] + [/actors] \ No newline at end of file diff --git a/data/map/01.tmx b/data/map/01.tmx index 5aa40cf..fa2dce2 100644 --- a/data/map/01.tmx +++ b/data/map/01.tmx @@ -19,9 +19,9 @@ 0,263,264,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,295,296,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,239,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,257,258,257,258,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,239,240,0,0,0,0,0,0,615,616,0,0,0,0,0,0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,257,258,257,258,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,0,101,102,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,289,290,289,290,0,0,0,0,577,578,579,580,581,582,0,0,0,0,0,0,0,0,583,584,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,615,616,69,70,0,0,0,93,94,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,189,190,0,0,0,0,0,0,0,0,0,0,189,190,101,102,0,0,0,125,126,0,0,0,0,0,0, diff --git a/source/game.cpp b/source/game.cpp index 1107b91..f2cad46 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -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(); diff --git a/source/map.cpp b/source/map.cpp index 88daed7..dddbba0 100644 --- a/source/map.cpp +++ b/source/map.cpp @@ -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; } \ No newline at end of file diff --git a/source/map.h b/source/map.h index cdc99db..2975372 100644 --- a/source/map.h +++ b/source/map.h @@ -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 diff --git a/source/player.cpp b/source/player.cpp index b51d5dc..cfdb47a 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -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; } diff --git a/source/player.h b/source/player.h index 0698102..c1a046d 100644 --- a/source/player.h +++ b/source/player.h @@ -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();