Simplify the color system by using a simple Values system for the dark to light.

This commit is contained in:
Zed A. Shaw 2024-09-19 11:44:34 -04:00
parent 3cb4fcfeb5
commit 581e5b4a60
2 changed files with 45 additions and 19 deletions

View file

@ -17,6 +17,19 @@ using namespace fmt;
using namespace nlohmann;
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) {
auto audio = data["audio"];
json::string_t file_name = audio[file_key].template get<string>();
@ -41,6 +54,10 @@ void SFMLBackend::Window_update() {
window.display();
}
sf::Color SFMLBackend::value(Value level) {
return VALUES.at(int(level));
}
void SFMLBackend::handle_events() {
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::Text text;
text.setFont(font);
text.setString(content);
text.setCharacterSize(TEXT_SIZE * size_mult);
text.setFillColor(sf::Color(100, 250, 50));
text.setFillColor(value(color));
text.setPosition(position);
window.draw(text);
}
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));
box.setPosition(translate(x,y));
box.setOutlineColor(outline);
box.setOutlineColor(value(outline));
box.setOutlineThickness(thickness);
box.setFillColor(fill);
box.setFillColor(value(fill));
window.draw(box);
return box;
}
@ -116,15 +133,15 @@ void SFMLBackend::update_entities() {
window.draw(face_sprite);
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;
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::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 {}",
game.hit_points, game.rounds,
@ -135,10 +152,10 @@ void SFMLBackend::update_entities() {
string time = fmt::format("{:%r}", fmt::localtime(t));
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);
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);
Window_update();