diff --git a/assets/tiles.json b/assets/tiles.json index ae3ea79..40d0813 100644 --- a/assets/tiles.json +++ b/assets/tiles.json @@ -11,20 +11,20 @@ "foreground": [230, 20, 30], "background": [230, 20, 120], "collision": true, - "display": "\ua5b8" + "display": "█" }, "WALL_VINES": { "texture": "assets/wall_with_vines-256.png", "foreground": [40, 15, 125], "background": [200, 29, 75], "collision": false, - "display":"\u19f0" + "display":"#" }, "WALL_PILLAR": { "texture": "assets/wall_with_pillars-256.png", "foreground": [40, 15, 125], "background": [200, 29, 75], "collision": false, - "display":"\u16de" + "display":"%" } } diff --git a/gui.cpp b/gui.cpp index 7362927..19aabf4 100644 --- a/gui.cpp +++ b/gui.cpp @@ -14,12 +14,17 @@ namespace gui { $window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), $font{"./assets/text.otf"}, $text{$font}, + $map_display{$font}, $rayview($textures, RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT) { $window.setVerticalSyncEnabled(VSYNC); $window.setFramerateLimit(FRAME_LIMIT); - $text.setFillColor({255,255,255}); $text.setPosition({10,10}); + $text.setFillColor({255,255,255}); + $map_display.setPosition({10, SCREEN_HEIGHT-300}); + $map_display.setFillColor({255,255,255}); + $map_display.setLetterSpacing(0.5); + $map_display.setLineSpacing(0.9); $textures.load_tiles(); $textures.load_sprites(); } @@ -44,7 +49,7 @@ namespace gui { void FSM::MOVING(Event ) { if($camera.play_move($rayview)) { - System::plan_motion(*level.world, {size_t($camera.targetX), size_t($camera.targetY)}); + System::plan_motion(*$level.world, {size_t($camera.targetX), size_t($camera.targetY)}); run_systems(); state(State::IDLE); } @@ -95,7 +100,7 @@ namespace gui { Point move_to{size_t($camera.targetX), size_t($camera.targetY)}; - if(level.map->can_move(move_to) && !level.collision->occupied(move_to)) { + if($level.map->can_move(move_to) && !$level.collision->occupied(move_to)) { state(State::MOVING); } else { state(State::IDLE); @@ -153,10 +158,15 @@ namespace gui { void FSM::draw_gui() { sf::RectangleShape rect({SCREEN_WIDTH - RAY_VIEW_WIDTH, SCREEN_HEIGHT}); + sf::RectangleShape map_rect({SCREEN_WIDTH - RAY_VIEW_WIDTH - 10, 300}); rect.setPosition({0,0}); rect.setFillColor({50, 50, 50}); + + map_rect.setPosition({0, SCREEN_HEIGHT-300}); + map_rect.setFillColor({20, 20, 20}); $window.draw(rect); + $window.draw(map_rect); $text.setString( fmt::format("FPS\n" @@ -168,14 +178,18 @@ namespace gui { "VSync? {}\n" "FR Limit: {}\n" "Debug? {}\n\n" - "Hit R to reset.\n\n" "dir: {:>2.02},{:>2.02}\n" - "pos: {:>2.02},{:>2.02}", + "pos: {:>2.02},{:>2.02}\n\n", $stats.mean(), $stats.stddev(), $stats.min, $stats.max, $stats.n, VSYNC, FRAME_LIMIT, DEBUG_BUILD, $rayview.$dirX, $rayview.$dirY, $rayview.$posX, $rayview.$posY)); + $window.draw($text); + + std::wstring map = $level.map->tiles().minimap(int($rayview.$posX), int($rayview.$posY)); + $map_display.setString(map); + $window.draw($map_display); } void FSM::render() { @@ -199,18 +213,18 @@ namespace gui { } void FSM::generate_map() { - level = $levels.current(); - auto& player = level.world->get_the(); - auto& player_position = level.world->get(player.entity); + $level = $levels.current(); + auto& player = $level.world->get_the(); + auto& player_position = $level.world->get(player.entity); $player = player_position.location; - $rayview.set_level(level); + $rayview.set_level($level); } void FSM::run_systems() { - System::motion(level); - System::enemy_pathing(level); - System::collision(level); - System::death(level); + System::motion($level); + System::enemy_pathing($level); + System::collision($level); + System::death($level); } bool FSM::active() { diff --git a/gui.hpp b/gui.hpp index e9a118b..9b1531c 100644 --- a/gui.hpp +++ b/gui.hpp @@ -29,7 +29,7 @@ namespace gui { class FSM : public DeadSimpleFSM { public: - GameLevel level; + GameLevel $level; float $rotation = -30.0f; Point $player{0,0}; LevelManager $levels; @@ -37,6 +37,7 @@ namespace gui { CameraLOL $camera; sf::Font $font; sf::Text $text; + sf::Text $map_display; Stats $stats; TexturePack $textures; Raycaster $rayview; diff --git a/tilemap.cpp b/tilemap.cpp index 8987144..fa49345 100644 --- a/tilemap.cpp +++ b/tilemap.cpp @@ -73,3 +73,21 @@ bool TileMap::INVARIANT() { dbc::check(matrix::width($tile_ids) == $width, "$tile_ids has wrong width"); return true; } + +std::wstring TileMap::minimap(size_t x, size_t y) { + string result; + + for(matrix::box it{$tile_ids, x, y, 5}; it.next();) { + const TileCell &cell = $display[it.y][it.x]; + if(it.x == x && it.y == y) { + result += "@"; + } else { + result += cell.display; + } + + if(it.x == it.right - 1) result += "\n"; + } + + std::wstring_convert> $converter; + return $converter.from_bytes(result); +} diff --git a/tilemap.hpp b/tilemap.hpp index 495300b..e93d559 100644 --- a/tilemap.hpp +++ b/tilemap.hpp @@ -43,4 +43,5 @@ public: void dump(int show_x=-1, int show_y=-1); bool INVARIANT(); + std::wstring minimap(size_t x, size_t y); };