Now able to render the map at a different size from the rest of the UI and also only shake the map.
This commit is contained in:
parent
77945be4d7
commit
b8a0d9bbd1
3 changed files with 55 additions and 28 deletions
63
gui.cpp
63
gui.cpp
|
@ -48,16 +48,25 @@ sf::Color GUI::color(Value val) {
|
|||
GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y),
|
||||
$canvas(GAME_MAP_X * 2, GAME_MAP_Y * 4),
|
||||
$window(sf::VideoMode(VIDEO_X,VIDEO_Y), "Roguish"),
|
||||
$screen(SCREEN_X, SCREEN_Y)
|
||||
$screen(SCREEN_X, SCREEN_Y),
|
||||
$map_screen(GAME_MAP_X, GAME_MAP_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");
|
||||
$text.setFont($font);
|
||||
$text.setCharacterSize(30);
|
||||
$text.setFillColor(color(Value::LIGHT_DARK));
|
||||
|
||||
$ui_text.setFont($font);
|
||||
$ui_text.setPosition(0,0);
|
||||
$ui_text.setCharacterSize(UI_FONT_SIZE);
|
||||
$ui_text.setFillColor(color(Value::LIGHT_LIGHT));
|
||||
|
||||
$map_text.setFont($font);
|
||||
$map_text.setPosition(GAME_MAP_POS,0);
|
||||
$map_text.setCharacterSize(MAP_FONT_SIZE);
|
||||
$map_text.setFillColor(color(Value::LIGHT_DARK));
|
||||
|
||||
$game_map.generate();
|
||||
$player.location = $game_map.place_entity(0);
|
||||
$enemy.location = $game_map.place_entity(1);
|
||||
|
@ -77,20 +86,20 @@ void GUI::create_renderer() {
|
|||
|
||||
for(size_t x = 0; x < walls[0].size(); ++x) {
|
||||
for(size_t y = 0; y < walls.size(); ++y) {
|
||||
string tile = walls[y][x] == 1 ? "#" : format("{}", paths[y][x]);
|
||||
if(tile == "#") {
|
||||
string tile = walls[y][x] == 1 ? WALL_TILE : format("{}", paths[y][x]);
|
||||
if(tile == WALL_TILE) {
|
||||
$canvas.DrawText(x*2, y*4, tile);
|
||||
} else if($show_paths) {
|
||||
//int pnum = paths[y][x];
|
||||
$canvas.DrawText(x*2, y*4, tile);
|
||||
} else {
|
||||
$canvas.DrawText(x*2, y*4, ".");
|
||||
$canvas.DrawText(x*2, y*4, FLOOR_TILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$canvas.DrawText($enemy.location.x*2, $enemy.location.y*4, "!");
|
||||
$canvas.DrawText($player.location.x*2, $player.location.y*4, "@");
|
||||
$canvas.DrawText($enemy.location.x*2, $enemy.location.y*4, ENEMY_TILE);
|
||||
$canvas.DrawText($player.location.x*2, $player.location.y*4, PLAYER_TILE);
|
||||
$canvas.DrawText($goal.x*2, $goal.y*4, "$");
|
||||
|
||||
return canvas($canvas);
|
||||
|
@ -105,7 +114,7 @@ void GUI::create_renderer() {
|
|||
) | xflex_grow
|
||||
),
|
||||
separator(),
|
||||
hbox($map_view->Render()),
|
||||
hbox(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -158,39 +167,45 @@ void GUI::handle_events() {
|
|||
|
||||
void GUI::burn() {
|
||||
for(int i = 0; i < 20; ++i) {
|
||||
$text.setFillColor(color(i % VALUES.size()));
|
||||
$map_text.setFillColor(color(i % VALUES.size()));
|
||||
int x = Random::rand_int(-10,10);
|
||||
int y = Random::rand_int(-10,10);
|
||||
$text.setPosition({(float)x,(float)y});
|
||||
$window.draw($text);
|
||||
$window.display();
|
||||
draw_screen(false, x, y);
|
||||
std::this_thread::sleep_for(2ms);
|
||||
}
|
||||
|
||||
$text.setFillColor(color(Value::LIGHT_DARK));
|
||||
$map_text.setFillColor(color(Value::LIGHT_DARK));
|
||||
}
|
||||
|
||||
inline void draw_screen(sf::RenderWindow &window, sf::Text &text, float x=0, float y=0) {
|
||||
text.setPosition({x,y});
|
||||
window.clear();
|
||||
window.draw(text);
|
||||
window.display();
|
||||
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) {
|
||||
if(clear) $window.clear();
|
||||
$window.draw($ui_text);
|
||||
$map_text.setPosition(GAME_MAP_POS+map_off_x, map_off_y);
|
||||
$window.draw($map_text);
|
||||
$window.display();
|
||||
}
|
||||
|
||||
void GUI::shake() {
|
||||
for(int i = 0; i < 10; ++i) {
|
||||
int x = Random::rand_int(-10,10);
|
||||
int y = Random::rand_int(-10,10);
|
||||
draw_screen($window, $text, (float)x, (float)y);
|
||||
// add x/y back to draw screen
|
||||
draw_screen(true, x, y);
|
||||
std::this_thread::sleep_for(1ms);
|
||||
}
|
||||
}
|
||||
|
||||
void GUI::render_scene() {
|
||||
Render($map_screen, $map_view->Render());
|
||||
Render($screen, $document->Render());
|
||||
|
||||
std::string $screenout = $screen.ToString();
|
||||
std::wstring utf8 = $converter.from_bytes($screenout);
|
||||
$text.setString(utf8);
|
||||
std::wstring main_screen_utf8 = $converter.from_bytes($screenout);
|
||||
$ui_text.setString(main_screen_utf8);
|
||||
|
||||
std::string $map_screenout = $map_screen.ToString();
|
||||
std::wstring map_screen_utf8 = $converter.from_bytes($map_screenout);
|
||||
$map_text.setString(map_screen_utf8);
|
||||
|
||||
if($shake_it) {
|
||||
shake();
|
||||
|
@ -202,7 +217,7 @@ void GUI::render_scene() {
|
|||
$burn_baby_burn = false;
|
||||
}
|
||||
|
||||
draw_screen($window, $text, 0, 0);
|
||||
draw_screen();
|
||||
}
|
||||
|
||||
int GUI::main() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue