Skip to content
Snippets Groups Projects
Commit 9e6f29ea authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add victory condition

parent 9402eae2
No related branches found
No related tags found
No related merge requests found
...@@ -28,10 +28,9 @@ namespace demo { ...@@ -28,10 +28,9 @@ namespace demo {
using namespace fggl::entity::grid; using namespace fggl::entity::grid;
static void build_tileset(TileSet& tiles) { static void build_tileset(TileSet& tiles) {
fggl::entity::grid::FloorTile empty{fggl::entity::grid::FloorTile::IMPOSSIBLE, BLACK}; tiles.m_floors.push_back(FloorTile{FloorTile::IMPOSSIBLE, BLACK});
fggl::entity::grid::FloorTile ground{1, GREEN}; tiles.m_floors.push_back(FloorTile{1, GREEN});
tiles.m_floors.push_back(empty); tiles.m_floors.push_back(FloorTile{1, YELLOW_GREEN});
tiles.m_floors.push_back(ground);
fggl::entity::grid::WallTile noWall{}; fggl::entity::grid::WallTile noWall{};
tiles.m_walls.push_back(noWall); tiles.m_walls.push_back(noWall);
...@@ -82,6 +81,9 @@ namespace demo { ...@@ -82,6 +81,9 @@ namespace demo {
build_doorway(area, {10, 5}, false, 1); build_doorway(area, {10, 5}, false, 1);
build_doorway(area, {13, 5}, false, 1); build_doorway(area, {13, 5}, false, 1);
// set goal
area->setFloorAt(17, 5, 2);
build_room(area, {25, 5}, {3,3}); build_room(area, {25, 5}, {3,3});
// player // player
...@@ -273,6 +275,18 @@ namespace demo { ...@@ -273,6 +275,18 @@ namespace demo {
m_program.playing = false; m_program.playing = false;
m_program.m_currInstruction = 0; m_program.m_currInstruction = 0;
m_program.m_instructions.clear(); 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();
}
} }
} }
......
...@@ -68,6 +68,7 @@ namespace demo { ...@@ -68,6 +68,7 @@ namespace demo {
Program m_program; Program m_program;
void tickPlayer(); void tickPlayer();
void checkVictory();
inline void forward() { inline void forward() {
auto& cell = m_grid->entities().get<CellPos>(m_player); auto& cell = m_grid->entities().get<CellPos>(m_player);
......
...@@ -34,11 +34,14 @@ namespace fggl::scenes { ...@@ -34,11 +34,14 @@ namespace fggl::scenes {
void render(fggl::gfx::Graphics &gfx) override = 0; void render(fggl::gfx::Graphics &gfx) override = 0;
protected: protected:
inline auto input() -> input::Input & { inline auto input() -> input::Input & {
return *m_input; return *m_input;
} }
inline void returnToMenu() {
m_owner.change_state(m_previous);
}
private: private:
input::Input *m_input; input::Input *m_input;
std::string m_previous = "menu"; std::string m_previous = "menu";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment