|
|
@ -17,6 +17,7 @@ |
|
|
|
#include <fmt/core.h> |
|
|
|
#include <fmt/core.h> |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "gui.hpp" |
|
|
|
#include "gui.hpp" |
|
|
|
|
|
|
|
#include "rand.hpp" |
|
|
|
|
|
|
|
|
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
using namespace fmt; |
|
|
|
using namespace fmt; |
|
|
@ -36,6 +37,10 @@ std::array<sf::Color, 10> VALUES{ |
|
|
|
sf::Color::Transparent, // white
|
|
|
|
sf::Color::Transparent, // white
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Color GUI::color(int val) { |
|
|
|
|
|
|
|
return VALUES[size_t(val)]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sf::Color GUI::color(Value val) { |
|
|
|
sf::Color GUI::color(Value val) { |
|
|
|
return VALUES[size_t(val)]; |
|
|
|
return VALUES[size_t(val)]; |
|
|
|
} |
|
|
|
} |
|
|
@ -128,6 +133,7 @@ void GUI::handle_events() { |
|
|
|
$game_map.clear_target($player.location); |
|
|
|
$game_map.clear_target($player.location); |
|
|
|
$player.move({x, y}); |
|
|
|
$player.move({x, y}); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
$shake_it = true; |
|
|
|
$hit_sound.play(); |
|
|
|
$hit_sound.play(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -139,6 +145,7 @@ void GUI::handle_events() { |
|
|
|
|
|
|
|
|
|
|
|
if($enemy.location.x == $player.location.x && $enemy.location.y == $player.location.y) { |
|
|
|
if($enemy.location.x == $player.location.x && $enemy.location.y == $player.location.y) { |
|
|
|
$player.event(EntityEvent::HIT); |
|
|
|
$player.event(EntityEvent::HIT); |
|
|
|
|
|
|
|
$burn_baby_burn = true; |
|
|
|
} else if($goal.x == $player.location.x && $goal.y == $player.location.y) { |
|
|
|
} else if($goal.x == $player.location.x && $goal.y == $player.location.y) { |
|
|
|
$status_text = "YOU WIN!"; |
|
|
|
$status_text = "YOU WIN!"; |
|
|
|
} |
|
|
|
} |
|
|
@ -146,16 +153,53 @@ void GUI::handle_events() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void GUI::burn() { |
|
|
|
|
|
|
|
for(int i = 0; i < 20; ++i) { |
|
|
|
|
|
|
|
$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(); |
|
|
|
|
|
|
|
std::this_thread::sleep_for(2ms); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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::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); |
|
|
|
|
|
|
|
std::this_thread::sleep_for(1ms); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void GUI::render_scene() { |
|
|
|
void GUI::render_scene() { |
|
|
|
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 utf8 = $converter.from_bytes($screenout); |
|
|
|
$text.setString(utf8); |
|
|
|
$text.setString(utf8); |
|
|
|
$text.setPosition({0,0}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$window.clear(); |
|
|
|
if($shake_it) { |
|
|
|
$window.draw($text); |
|
|
|
shake(); |
|
|
|
$window.display(); |
|
|
|
$shake_it = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if($burn_baby_burn) { |
|
|
|
|
|
|
|
burn(); |
|
|
|
|
|
|
|
$burn_baby_burn = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
draw_screen($window, $text, 0, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int GUI::main() { |
|
|
|
int GUI::main() { |
|
|
|