diff --git a/main.cpp b/main.cpp index 9e698ea..2946d07 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,7 @@ using std::string; using namespace fmt; using namespace std::chrono_literals; + int main() { using namespace ftxui; std::string reset_position; @@ -33,17 +34,38 @@ int main() { game_map.generate(); Matrix &walls = game_map.walls(); Room &start = game_map.room(0); + Room &bad_room = game_map.room(1); + Room &gold_room = game_map.room(game_map.room_count() - 1); + Point me = {.x=start.x+1, .y=start.y+1}; + Point enemy = {.x=bad_room.x+1, .y=bad_room.y+1}; + Point goal = {.x=gold_room.x+1, .y=gold_room.y+1}; + string dead_yet = "NOT DEAD"; + + bool show_paths = false; auto map = Renderer([&] { + game_map.set_target(me); + game_map.make_paths(); + Matrix &paths = game_map.paths(); + for(size_t x = 0; x < walls[0].size(); ++x) { for(size_t y = 0; y < walls.size(); ++y) { - const string tile = walls[y][x] == 1 ? "#" : "."; - c.DrawText(x*2, y*4, tile, Color::GrayDark); + string tile = walls[y][x] == 1 ? "#" : format("{}", paths[y][x]); + if(tile == "#") { + c.DrawText(x*2, y*4, tile, Color::GrayDark); + } else if(show_paths) { + int pnum = paths[y][x]; + c.DrawText(x*2, y*4, tile, Color::Palette16(pnum % 7 + 1)); + } else { + c.DrawText(x*2, y*4, ".", Color::GrayDark); + } } } + c.DrawText(enemy.x*2, enemy.y*4, "!", Color::Red); c.DrawText(me.x*2, me.y*4, "@", Color::Blue); + c.DrawText(goal.x*2, goal.y*4, "$", Color::Yellow); return canvas(c); }); @@ -53,7 +75,7 @@ int main() { hflow( vbox( gauge(0.5) | border, - text("STATUS") | border + text(dead_yet) | border ) | xflex_grow ), separator(), @@ -78,9 +100,20 @@ int main() { } if(game_map.inmap(x,y) && !game_map.iswall(x,y)) { + game_map.clear_target(me); me.x = x; me.y = y; } + + // move enemy here + bool found = game_map.neighbors(enemy, true); + + if(enemy.x == me.x && enemy.y == me.y) { + dead_yet = "YOU DIED!"; + } else if(goal.x == me.x && goal.y == me.y) { + dead_yet = "YOU WIN!"; + } + return true; }); diff --git a/map.hpp b/map.hpp index c791db2..c18282f 100644 --- a/map.hpp +++ b/map.hpp @@ -63,6 +63,10 @@ public: return m_rooms[at]; } + size_t room_count() { + return m_rooms.size(); + } + void make_room(size_t origin_y, size_t origin_x, size_t width, size_t height); void add_door(Room &room);