diff --git a/gui.cpp b/gui.cpp index d7b341f..c89b38b 100644 --- a/gui.cpp +++ b/gui.cpp @@ -50,18 +50,30 @@ sf::Color GUI::color(Value val) { return VALUES[size_t(val)]; } -GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y), - $canvas(VIEW_PORT_X * 2, VIEW_PORT_Y * 4), +GUI::GUI() : + $game_map(GAME_MAP_X, GAME_MAP_Y), $window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"), $screen(SCREEN_X, SCREEN_Y), - $map_screen(VIEW_PORT_X, VIEW_PORT_Y) + $map_screen(0,0) { + $font.loadFromFile("./assets/text.otf"); + // calculate display size + sf::Glyph base_glyph = $font.getGlyph(L'█', MAP_FONT_SIZE, false); + auto bounds = base_glyph.bounds; + $view_port = { + size_t(std::ceil((VIDEO_X - GAME_MAP_POS) / bounds.width)), + size_t(std::ceil(VIDEO_Y / bounds.height)) + }; + + // set canvas to best size + $canvas = Canvas($view_port.x * 2, $view_port.y * 4); + + $map_screen = Screen($view_port.x, $view_port.y); + int res = $hit_buf.loadFromFile("./assets/hit.wav"); dbc::check(res, "failed to load hit.wav"); $hit_sound.setBuffer($hit_buf); - $font.loadFromFile("./assets/text.otf"); - $ui_text.setFont($font); $ui_text.setPosition(0,0); $ui_text.setCharacterSize(UI_FONT_SIZE); @@ -74,7 +86,7 @@ void GUI::create_renderer() { auto player = $world.get(); $map_view = Renderer([&] { - System::draw_map($world, $game_map, $canvas, VIEW_PORT_X, VIEW_PORT_Y); + System::draw_map($world, $game_map, $canvas, $view_port.x, $view_port.y); return canvas($canvas); }); diff --git a/gui.hpp b/gui.hpp index 6130543..2d037f4 100644 --- a/gui.hpp +++ b/gui.hpp @@ -17,16 +17,14 @@ using std::string; using ftxui::Canvas, ftxui::Component, ftxui::Screen; -constexpr int GAME_MAP_X = 60; -constexpr int GAME_MAP_Y = 30; -constexpr int VIEW_PORT_X = 30; -constexpr int VIEW_PORT_Y = 15; +constexpr int GAME_MAP_X = 90; +constexpr int GAME_MAP_Y = 90; constexpr int GAME_MAP_POS = 600; constexpr int SCREEN_X = 40; constexpr int SCREEN_Y = 30; constexpr int VIDEO_X = 1600; constexpr int VIDEO_Y = 900; -constexpr int MAP_FONT_SIZE=60; +constexpr int MAP_FONT_SIZE=90; constexpr int UI_FONT_SIZE=30; enum class Value { @@ -52,6 +50,7 @@ class GUI { DinkyECS::World $world; sf::Texture $font_texture; std::unordered_map $sprites; + Point $view_port = {0,0}; public: GUI(); diff --git a/systems.cpp b/systems.cpp index 95c09a1..f6dbfab 100644 --- a/systems.cpp +++ b/systems.cpp @@ -25,14 +25,18 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player void System::motion(DinkyECS::World &world, Map &game_map) { world.system([&](const auto &ent, auto &position, auto &motion) { - Point move_to = { - position.location.x + motion.dx, - position.location.y + motion.dy - }; - motion = {0,0}; // clear it after getting it + // don't process entities that don't move + if(motion.dx != 0 || motion.dy != 0) { + Point move_to = { + position.location.x + motion.dx, + position.location.y + motion.dy + }; + motion = {0,0}; // clear it after getting it - if(game_map.inmap(move_to.x, move_to.y) && !game_map.iswall(move_to.x,move_to.y)) { - position.location = move_to; + // avoid colision, but could this be a different system? + if(game_map.inmap(move_to.x, move_to.y) && !game_map.iswall(move_to.x,move_to.y)) { + position.location = move_to; + } } }); }