From 8e101f8bfd995321ac08a16fea9a171b549a0ae4 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Sat, 17 Dec 2022 11:04:20 -0500 Subject: Support doors with keys Add initial support for doors and keys via pre-defined mappings: k || d ------ 1 -> a 2 -> b 3 -> c 4 -> d Any key can open any door of its mapping, but is spent once used. May require additional testing --- src/SfmlUtils.h | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/SfmlUtils.h') diff --git a/src/SfmlUtils.h b/src/SfmlUtils.h index dd63cd6..86d5f62 100644 --- a/src/SfmlUtils.h +++ b/src/SfmlUtils.h @@ -63,6 +63,14 @@ inline sf::RectangleShape create_square(sf::Color color, int x, int y) { return rect; } +inline sf::RectangleShape create_small_square(sf::Color color, int x, int y) { + sf::RectangleShape rect({SPRITE_SIZE - 4.f, SPRITE_SIZE - 4.f}); + rect.setFillColor(color); + auto pos = to_position_xy(x, y); + rect.setPosition({pos.x + 2.f, pos.y + 2.f}); + return rect; +} + inline sf::RectangleShape create_wall(int x, int y) { return create_square(WALL_COLOR, x, y); } @@ -79,6 +87,34 @@ inline sf::RectangleShape create_treasure(int x, int y) { return create_square(sf::Color::Yellow, x, y); } +inline sf::RectangleShape create_key(char t, int x, int y) { + switch (t) { + case '1': + return create_small_square(sf::Color::Blue, x, y); + case '2': + return create_small_square(sf::Color::Green, x, y); + case '3': + return create_small_square(sf::Color::Black, x, y); + case '4': + default: + return create_small_square(sf::Color::White, x, y); + } +} + +inline sf::RectangleShape create_door(char t, int x, int y) { + switch (t) { + case 'a': + return create_square(sf::Color::Blue, x, y); + case 'b': + return create_square(sf::Color::Green, x, y); + case 'c': + return create_square(sf::Color::Black, x, y); + case 'd': + default: + return create_square(sf::Color::White, x, y); + } +} + inline sf::Vector2f round(const sf::Vector2f vector) { return sf::Vector2f{std::round(vector.x), std::round(vector.y)}; } @@ -107,4 +143,4 @@ inline sf::Text write_text(const char *msg, unsigned int fontSize, return text; } -#endif // DNG_SFML_UTILS_H \ No newline at end of file +#endif // DNG_SFML_UTILS_H -- cgit v1.2.3-54-g00ecf