|
|
@ -48,16 +48,25 @@ sf::Color GUI::color(Value val) { |
|
|
|
GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y), |
|
|
|
GUI::GUI() : $game_map(GAME_MAP_X, GAME_MAP_Y), |
|
|
|
$canvas(GAME_MAP_X * 2, GAME_MAP_Y * 4), |
|
|
|
$canvas(GAME_MAP_X * 2, GAME_MAP_Y * 4), |
|
|
|
$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(GAME_MAP_X, GAME_MAP_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"); |
|
|
|
$font.loadFromFile("./assets/text.otf"); |
|
|
|
$text.setFont($font); |
|
|
|
|
|
|
|
$text.setCharacterSize(30); |
|
|
|
$ui_text.setFont($font); |
|
|
|
$text.setFillColor(color(Value::LIGHT_DARK)); |
|
|
|
$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(); |
|
|
|
$game_map.generate(); |
|
|
|
$player.location = $game_map.place_entity(0); |
|
|
|
$player.location = $game_map.place_entity(0); |
|
|
|
$enemy.location = $game_map.place_entity(1); |
|
|
|
$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 x = 0; x < walls[0].size(); ++x) { |
|
|
|
for(size_t y = 0; y < walls.size(); ++y) { |
|
|
|
for(size_t y = 0; y < walls.size(); ++y) { |
|
|
|
string tile = walls[y][x] == 1 ? "#" : format("{}", paths[y][x]); |
|
|
|
string tile = walls[y][x] == 1 ? WALL_TILE : format("{}", paths[y][x]); |
|
|
|
if(tile == "#") { |
|
|
|
if(tile == WALL_TILE) { |
|
|
|
$canvas.DrawText(x*2, y*4, tile); |
|
|
|
$canvas.DrawText(x*2, y*4, tile); |
|
|
|
} else if($show_paths) { |
|
|
|
} else if($show_paths) { |
|
|
|
//int pnum = paths[y][x];
|
|
|
|
//int pnum = paths[y][x];
|
|
|
|
$canvas.DrawText(x*2, y*4, tile); |
|
|
|
$canvas.DrawText(x*2, y*4, tile); |
|
|
|
} else { |
|
|
|
} 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($enemy.location.x*2, $enemy.location.y*4, ENEMY_TILE); |
|
|
|
$canvas.DrawText($player.location.x*2, $player.location.y*4, "@"); |
|
|
|
$canvas.DrawText($player.location.x*2, $player.location.y*4, PLAYER_TILE); |
|
|
|
$canvas.DrawText($goal.x*2, $goal.y*4, "$"); |
|
|
|
$canvas.DrawText($goal.x*2, $goal.y*4, "$"); |
|
|
|
|
|
|
|
|
|
|
|
return canvas($canvas); |
|
|
|
return canvas($canvas); |
|
|
@ -105,7 +114,7 @@ void GUI::create_renderer() { |
|
|
|
) | xflex_grow |
|
|
|
) | xflex_grow |
|
|
|
), |
|
|
|
), |
|
|
|
separator(), |
|
|
|
separator(), |
|
|
|
hbox($map_view->Render()), |
|
|
|
hbox(), |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
@ -158,39 +167,45 @@ void GUI::handle_events() { |
|
|
|
|
|
|
|
|
|
|
|
void GUI::burn() { |
|
|
|
void GUI::burn() { |
|
|
|
for(int i = 0; i < 20; ++i) { |
|
|
|
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 x = Random::rand_int(-10,10); |
|
|
|
int y = Random::rand_int(-10,10); |
|
|
|
int y = Random::rand_int(-10,10); |
|
|
|
$text.setPosition({(float)x,(float)y}); |
|
|
|
draw_screen(false, x, y); |
|
|
|
$window.draw($text); |
|
|
|
|
|
|
|
$window.display(); |
|
|
|
|
|
|
|
std::this_thread::sleep_for(2ms); |
|
|
|
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) { |
|
|
|
void GUI::draw_screen(bool clear, float map_off_x, float map_off_y) { |
|
|
|
text.setPosition({x,y}); |
|
|
|
if(clear) $window.clear(); |
|
|
|
window.clear(); |
|
|
|
$window.draw($ui_text); |
|
|
|
window.draw(text); |
|
|
|
$map_text.setPosition(GAME_MAP_POS+map_off_x, map_off_y); |
|
|
|
window.display(); |
|
|
|
$window.draw($map_text); |
|
|
|
|
|
|
|
$window.display(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GUI::shake() { |
|
|
|
void GUI::shake() { |
|
|
|
for(int i = 0; i < 10; ++i) { |
|
|
|
for(int i = 0; i < 10; ++i) { |
|
|
|
int x = Random::rand_int(-10,10); |
|
|
|
int x = Random::rand_int(-10,10); |
|
|
|
int y = 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); |
|
|
|
std::this_thread::sleep_for(1ms); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GUI::render_scene() { |
|
|
|
void GUI::render_scene() { |
|
|
|
|
|
|
|
Render($map_screen, $map_view->Render()); |
|
|
|
Render($screen, $document->Render()); |
|
|
|
Render($screen, $document->Render()); |
|
|
|
|
|
|
|
|
|
|
|
std::string $screenout = $screen.ToString(); |
|
|
|
std::string $screenout = $screen.ToString(); |
|
|
|
std::wstring utf8 = $converter.from_bytes($screenout); |
|
|
|
std::wstring main_screen_utf8 = $converter.from_bytes($screenout); |
|
|
|
$text.setString(utf8); |
|
|
|
$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) { |
|
|
|
if($shake_it) { |
|
|
|
shake(); |
|
|
|
shake(); |
|
|
@ -202,7 +217,7 @@ void GUI::render_scene() { |
|
|
|
$burn_baby_burn = false; |
|
|
|
$burn_baby_burn = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
draw_screen($window, $text, 0, 0); |
|
|
|
draw_screen(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int GUI::main() { |
|
|
|
int GUI::main() { |
|
|
|