summaryrefslogtreecommitdiff
path: root/src/SfmlUtils.h
diff options
context:
space:
mode:
authorSteph Enders <smenders@gmail.com>2022-12-17 11:04:20 -0500
committerSteph Enders <smenders@gmail.com>2022-12-17 11:04:20 -0500
commit8e101f8bfd995321ac08a16fea9a171b549a0ae4 (patch)
tree61c25c357c24381e653f2dd104463628fe2875e7 /src/SfmlUtils.h
parentf710faa0cc8862a8367dbbf89bf8c3cd44790b5d (diff)
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
Diffstat (limited to 'src/SfmlUtils.h')
-rw-r--r--src/SfmlUtils.h38
1 files changed, 37 insertions, 1 deletions
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