Simplify the color system by using a simple Values system for the dark to light.
This commit is contained in:
parent
3cb4fcfeb5
commit
581e5b4a60
2 changed files with 45 additions and 19 deletions
|
@ -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();
|
||||
|
|
|
@ -11,16 +11,23 @@
|
|||
|
||||
using std::string;
|
||||
|
||||
enum class Value {
|
||||
BLACK=0, DARK_DARK, DARK_MID,
|
||||
DARK_LIGHT, MID, LIGHT_DARK, LIGHT_MID,
|
||||
LIGHT_LIGHT, WHITE, TRANSPARENT
|
||||
};
|
||||
|
||||
|
||||
constexpr int FPS=30;
|
||||
constexpr int X_DIM = 1920 / 2;
|
||||
constexpr int Y_DIM = 1080 / 2;
|
||||
constexpr int TEXT_SIZE = 48;
|
||||
constexpr Value TEXT_COLOR = Value::LIGHT_LIGHT;
|
||||
constexpr int Y_LINES = 23;
|
||||
constexpr int X_ROWS = 48;
|
||||
const sf::Color OUTLINE(50, 200, 25);
|
||||
constexpr int THICKNESS=10;
|
||||
const sf::Color FILL = sf::Color::Transparent;
|
||||
|
||||
constexpr Value BOX_OUTLINE = Value::MID;
|
||||
constexpr int BOX_THICKNESS=10;
|
||||
constexpr Value BOX_FILL = Value::TRANSPARENT;
|
||||
|
||||
class SoundQuip {
|
||||
public:
|
||||
|
@ -64,12 +71,14 @@ public:
|
|||
void update_entities();
|
||||
void update_log(std::vector<string> &lines);
|
||||
|
||||
sf::RectangleShape box(int x, int y, int width, int height,
|
||||
sf::Color fill=FILL,
|
||||
sf::Color outline=OUTLINE,
|
||||
int thickness=THICKNESS);
|
||||
sf::Color value(Value level);
|
||||
|
||||
void write_text(int x, int y, string content, float size_mult=1.0f);
|
||||
sf::RectangleShape box(int x, int y, int width, int height,
|
||||
Value fill=BOX_FILL,
|
||||
Value outline=BOX_OUTLINE,
|
||||
int thickness=BOX_THICKNESS);
|
||||
|
||||
void write_text(int x, int y, string content, float size_mult=1.0f, Value color=TEXT_COLOR);
|
||||
|
||||
void Window_update();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue