diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp index d3e659fdf07b7cf8d70e487237cf17d34550132e..cd23691de5e58efbd785e23638e574092e4711de 100644 --- a/demo/demo/grid.cpp +++ b/demo/demo/grid.cpp @@ -28,10 +28,9 @@ namespace demo { using namespace fggl::entity::grid; static void build_tileset(TileSet& tiles) { - fggl::entity::grid::FloorTile empty{fggl::entity::grid::FloorTile::IMPOSSIBLE, BLACK}; - fggl::entity::grid::FloorTile ground{1, GREEN}; - tiles.m_floors.push_back(empty); - tiles.m_floors.push_back(ground); + tiles.m_floors.push_back(FloorTile{FloorTile::IMPOSSIBLE, BLACK}); + tiles.m_floors.push_back(FloorTile{1, GREEN}); + tiles.m_floors.push_back(FloorTile{1, YELLOW_GREEN}); fggl::entity::grid::WallTile noWall{}; tiles.m_walls.push_back(noWall); @@ -82,6 +81,9 @@ namespace demo { build_doorway(area, {10, 5}, false, 1); build_doorway(area, {13, 5}, false, 1); + // set goal + area->setFloorAt(17, 5, 2); + build_room(area, {25, 5}, {3,3}); // player @@ -273,6 +275,18 @@ namespace demo { m_program.playing = false; m_program.m_currInstruction = 0; m_program.m_instructions.clear(); + checkVictory(); + } + } + + void GridScene::checkVictory() { + if ( !m_program.playing ) { + auto& botPos = m_grid->entities().get<CellPos>(m_player).pos; + auto gridCell = m_grid->floorAt(botPos.x, botPos.y); + if ( gridCell.colour == YELLOW_GREEN ) { + // a winner is you! + returnToMenu(); + } } } diff --git a/demo/include/grid.hpp b/demo/include/grid.hpp index 99d6b1160ef270d9a76bd1c94e2442835f1b97b9..91ffab3e5d6dd42825d8e06919e50b6a2d7447fc 100644 --- a/demo/include/grid.hpp +++ b/demo/include/grid.hpp @@ -68,6 +68,7 @@ namespace demo { Program m_program; void tickPlayer(); + void checkVictory(); inline void forward() { auto& cell = m_grid->entities().get<CellPos>(m_player); diff --git a/include/fggl/scenes/game.hpp b/include/fggl/scenes/game.hpp index 71a129f32115f9b188c011e5d4402afbf13064e9..1a451d3f35f0ec522784182cd081cfffd77531ae 100644 --- a/include/fggl/scenes/game.hpp +++ b/include/fggl/scenes/game.hpp @@ -34,11 +34,14 @@ namespace fggl::scenes { void render(fggl::gfx::Graphics &gfx) override = 0; protected: - inline auto input() -> input::Input & { return *m_input; } + inline void returnToMenu() { + m_owner.change_state(m_previous); + } + private: input::Input *m_input; std::string m_previous = "menu";