Make it so the canvas for the map view is calculated based on the font size, which will allow for zooming.
This commit is contained in:
parent
9f1e9717a0
commit
02a45d890f
3 changed files with 33 additions and 18 deletions
24
gui.cpp
24
gui.cpp
|
@ -50,18 +50,30 @@ sf::Color GUI::color(Value val) {
|
||||||
return VALUES[size_t(val)];
|
return VALUES[size_t(val)];
|
||||||
}
|
}
|
||||||
|
|
||||||
GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y),
|
GUI::GUI() :
|
||||||
$canvas(VIEW_PORT_X * 2, VIEW_PORT_Y * 4),
|
$game_map(GAME_MAP_X, GAME_MAP_Y),
|
||||||
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
||||||
$screen(SCREEN_X, SCREEN_Y),
|
$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");
|
int res = $hit_buf.loadFromFile("./assets/hit.wav");
|
||||||
dbc::check(res, "failed to load hit.wav");
|
dbc::check(res, "failed to load hit.wav");
|
||||||
$hit_sound.setBuffer($hit_buf);
|
$hit_sound.setBuffer($hit_buf);
|
||||||
|
|
||||||
$font.loadFromFile("./assets/text.otf");
|
|
||||||
|
|
||||||
$ui_text.setFont($font);
|
$ui_text.setFont($font);
|
||||||
$ui_text.setPosition(0,0);
|
$ui_text.setPosition(0,0);
|
||||||
$ui_text.setCharacterSize(UI_FONT_SIZE);
|
$ui_text.setCharacterSize(UI_FONT_SIZE);
|
||||||
|
@ -74,7 +86,7 @@ void GUI::create_renderer() {
|
||||||
auto player = $world.get<Player>();
|
auto player = $world.get<Player>();
|
||||||
|
|
||||||
$map_view = Renderer([&] {
|
$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);
|
return canvas($canvas);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
9
gui.hpp
9
gui.hpp
|
@ -17,16 +17,14 @@
|
||||||
using std::string;
|
using std::string;
|
||||||
using ftxui::Canvas, ftxui::Component, ftxui::Screen;
|
using ftxui::Canvas, ftxui::Component, ftxui::Screen;
|
||||||
|
|
||||||
constexpr int GAME_MAP_X = 60;
|
constexpr int GAME_MAP_X = 90;
|
||||||
constexpr int GAME_MAP_Y = 30;
|
constexpr int GAME_MAP_Y = 90;
|
||||||
constexpr int VIEW_PORT_X = 30;
|
|
||||||
constexpr int VIEW_PORT_Y = 15;
|
|
||||||
constexpr int GAME_MAP_POS = 600;
|
constexpr int GAME_MAP_POS = 600;
|
||||||
constexpr int SCREEN_X = 40;
|
constexpr int SCREEN_X = 40;
|
||||||
constexpr int SCREEN_Y = 30;
|
constexpr int SCREEN_Y = 30;
|
||||||
constexpr int VIDEO_X = 1600;
|
constexpr int VIDEO_X = 1600;
|
||||||
constexpr int VIDEO_Y = 900;
|
constexpr int VIDEO_Y = 900;
|
||||||
constexpr int MAP_FONT_SIZE=60;
|
constexpr int MAP_FONT_SIZE=90;
|
||||||
constexpr int UI_FONT_SIZE=30;
|
constexpr int UI_FONT_SIZE=30;
|
||||||
|
|
||||||
enum class Value {
|
enum class Value {
|
||||||
|
@ -52,6 +50,7 @@ class GUI {
|
||||||
DinkyECS::World $world;
|
DinkyECS::World $world;
|
||||||
sf::Texture $font_texture;
|
sf::Texture $font_texture;
|
||||||
std::unordered_map<wchar_t, sf::Sprite> $sprites;
|
std::unordered_map<wchar_t, sf::Sprite> $sprites;
|
||||||
|
Point $view_port = {0,0};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GUI();
|
GUI();
|
||||||
|
|
|
@ -25,15 +25,19 @@ void System::enemy_pathing(DinkyECS::World &world, Map &game_map, Player &player
|
||||||
|
|
||||||
void System::motion(DinkyECS::World &world, Map &game_map) {
|
void System::motion(DinkyECS::World &world, Map &game_map) {
|
||||||
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
world.system<Position, Motion>([&](const auto &ent, auto &position, auto &motion) {
|
||||||
|
// don't process entities that don't move
|
||||||
|
if(motion.dx != 0 || motion.dy != 0) {
|
||||||
Point move_to = {
|
Point move_to = {
|
||||||
position.location.x + motion.dx,
|
position.location.x + motion.dx,
|
||||||
position.location.y + motion.dy
|
position.location.y + motion.dy
|
||||||
};
|
};
|
||||||
motion = {0,0}; // clear it after getting it
|
motion = {0,0}; // clear it after getting it
|
||||||
|
|
||||||
|
// 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)) {
|
if(game_map.inmap(move_to.x, move_to.y) && !game_map.iswall(move_to.x,move_to.y)) {
|
||||||
position.location = move_to;
|
position.location = move_to;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue