|
|
@ -17,6 +17,19 @@ using namespace fmt; |
|
|
|
using namespace nlohmann; |
|
|
|
using namespace nlohmann; |
|
|
|
using std::string; |
|
|
|
using std::string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::array<sf::Color, 10> VALUES{ |
|
|
|
|
|
|
|
sf::Color{1, 4, 2}, // black
|
|
|
|
|
|
|
|
sf::Color{9, 29, 16}, // dark dark
|
|
|
|
|
|
|
|
sf::Color{14, 50, 26}, // dark mid
|
|
|
|
|
|
|
|
sf::Color{0, 109, 44}, // dark light
|
|
|
|
|
|
|
|
sf::Color{63, 171, 92}, // mid
|
|
|
|
|
|
|
|
sf::Color{161, 217, 155}, // light dark
|
|
|
|
|
|
|
|
sf::Color{199, 233, 192}, // light mid
|
|
|
|
|
|
|
|
sf::Color{229, 245, 224}, // light light
|
|
|
|
|
|
|
|
sf::Color{255, 255, 255}, // white
|
|
|
|
|
|
|
|
sf::Color::Transparent, // white
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
void SoundQuip::load(json &data, const char *file_key, bool loop) { |
|
|
|
void SoundQuip::load(json &data, const char *file_key, bool loop) { |
|
|
|
auto audio = data["audio"]; |
|
|
|
auto audio = data["audio"]; |
|
|
|
json::string_t file_name = audio[file_key].template get<string>(); |
|
|
|
json::string_t file_name = audio[file_key].template get<string>(); |
|
|
@ -41,6 +54,10 @@ void SFMLBackend::Window_update() { |
|
|
|
window.display(); |
|
|
|
window.display(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::Color SFMLBackend::value(Value level) { |
|
|
|
|
|
|
|
return VALUES.at(int(level)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::handle_events() { |
|
|
|
void SFMLBackend::handle_events() { |
|
|
|
sf::Event event; |
|
|
|
sf::Event event; |
|
|
|
|
|
|
|
|
|
|
@ -85,25 +102,25 @@ sf::Vector2f translate(int x, int y) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SFMLBackend::write_text(int x, int y, string content, float size_mult) { |
|
|
|
void SFMLBackend::write_text(int x, int y, string content, float size_mult, Value color) { |
|
|
|
sf::Vector2f position = translate(x,y); |
|
|
|
sf::Vector2f position = translate(x,y); |
|
|
|
sf::Text text; |
|
|
|
sf::Text text; |
|
|
|
text.setFont(font); |
|
|
|
text.setFont(font); |
|
|
|
text.setString(content); |
|
|
|
text.setString(content); |
|
|
|
text.setCharacterSize(TEXT_SIZE * size_mult); |
|
|
|
text.setCharacterSize(TEXT_SIZE * size_mult); |
|
|
|
text.setFillColor(sf::Color(100, 250, 50)); |
|
|
|
text.setFillColor(value(color)); |
|
|
|
text.setPosition(position); |
|
|
|
text.setPosition(position); |
|
|
|
window.draw(text); |
|
|
|
window.draw(text); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape SFMLBackend::box(int x, int y, int width, int height, |
|
|
|
sf::RectangleShape SFMLBackend::box(int x, int y, int width, int height, |
|
|
|
sf::Color fill, sf::Color outline, int thickness) |
|
|
|
Value fill, Value outline, int thickness) |
|
|
|
{ |
|
|
|
{ |
|
|
|
sf::RectangleShape box(translate(width, height)); |
|
|
|
sf::RectangleShape box(translate(width, height)); |
|
|
|
box.setPosition(translate(x,y)); |
|
|
|
box.setPosition(translate(x,y)); |
|
|
|
box.setOutlineColor(outline); |
|
|
|
box.setOutlineColor(value(outline)); |
|
|
|
box.setOutlineThickness(thickness); |
|
|
|
box.setOutlineThickness(thickness); |
|
|
|
box.setFillColor(fill); |
|
|
|
box.setFillColor(value(fill)); |
|
|
|
window.draw(box); |
|
|
|
window.draw(box); |
|
|
|
return box; |
|
|
|
return box; |
|
|
|
} |
|
|
|
} |
|
|
@ -116,15 +133,15 @@ void SFMLBackend::update_entities() { |
|
|
|
window.draw(face_sprite); |
|
|
|
window.draw(face_sprite); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape stats_box = box(X_ROWS/4 + 4, 2, |
|
|
|
sf::RectangleShape stats_box = box(X_ROWS/4 + 4, 2, |
|
|
|
X_ROWS - X_ROWS/4 - 5, Y_LINES/2); |
|
|
|
X_ROWS - X_ROWS/4 - 5, Y_LINES/2, Value::DARK_DARK); |
|
|
|
|
|
|
|
|
|
|
|
constexpr int hp_box_len = 45; |
|
|
|
constexpr int hp_box_len = 45; |
|
|
|
int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len); |
|
|
|
int current_hp = (float(game.hit_points) / float(game.starting_hp)) * float(hp_box_len); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape hp_bar = box(2, 21, current_hp, 2, |
|
|
|
sf::RectangleShape hp_bar = box(2, 21, current_hp, 2, |
|
|
|
sf::Color(100, 250, 50)); |
|
|
|
Value::LIGHT_MID, Value::LIGHT_MID, 0); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape hp_box = box(2, 21, hp_box_len, 2); |
|
|
|
sf::RectangleShape hp_box = box(2, 21, hp_box_len, 2, Value::TRANSPARENT); |
|
|
|
|
|
|
|
|
|
|
|
string status = fmt::format("HP {}\nRounds {}\nStreaks {}\nDeaths {}", |
|
|
|
string status = fmt::format("HP {}\nRounds {}\nStreaks {}\nDeaths {}", |
|
|
|
game.hit_points, game.rounds, |
|
|
|
game.hit_points, game.rounds, |
|
|
@ -135,10 +152,10 @@ void SFMLBackend::update_entities() { |
|
|
|
string time = fmt::format("{:%r}", fmt::localtime(t)); |
|
|
|
string time = fmt::format("{:%r}", fmt::localtime(t)); |
|
|
|
write_text(2, 14, time, 2.0f); |
|
|
|
write_text(2, 14, time, 2.0f); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape start_btn = box(27, 16, 8, 3); |
|
|
|
sf::RectangleShape start_btn = box(27, 16, 8, 3, Value::DARK_MID); |
|
|
|
write_text(29, 16, "START", 1.0f); |
|
|
|
write_text(29, 16, "START", 1.0f); |
|
|
|
|
|
|
|
|
|
|
|
sf::RectangleShape done_btn = box(37, 16, 8, 3); |
|
|
|
sf::RectangleShape done_btn = box(37, 16, 8, 3, Value::DARK_MID); |
|
|
|
write_text(39, 16, "DONE", 1.0f); |
|
|
|
write_text(39, 16, "DONE", 1.0f); |
|
|
|
|
|
|
|
|
|
|
|
Window_update(); |
|
|
|
Window_update(); |
|
|
|