diff options
author | Steph Enders <smenders@gmail.com> | 2022-12-17 11:04:20 -0500 |
---|---|---|
committer | Steph Enders <smenders@gmail.com> | 2022-12-17 11:04:20 -0500 |
commit | 8e101f8bfd995321ac08a16fea9a171b549a0ae4 (patch) | |
tree | 61c25c357c24381e653f2dd104463628fe2875e7 /src/Level.h | |
parent | f710faa0cc8862a8367dbbf89bf8c3cd44790b5d (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/Level.h')
-rw-r--r-- | src/Level.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Level.h b/src/Level.h index 7b25d0b..7c2c74b 100644 --- a/src/Level.h +++ b/src/Level.h @@ -39,8 +39,14 @@ static const char TREASURE_TKN = 't'; static const char ENEMY_TKN = 'e'; static const char BLANK_SPACE = '\0'; static const char WALL_SPACE = '#'; +static const char KEY_TKN_START = '1'; // inclusive (1, 2, 3, 4) +static const char KEY_TKN_END = '4'; // inclusive (1, 2, 3, 4) +static const char DOOR_TKN_START = 'a'; // inclusive (a, b, c, d) +static const char DOOR_TKN_END = 'd'; // inclusive (a, b, c, d) +static const char KEY_DOOR_MAPPING[4] = {'a', 'b', 'c', 'd'}; struct Pos { + char token; int id; int x; int y; @@ -54,6 +60,8 @@ public: ~Level() = default; void load(); bool playerCanStep(int dx, int dy) const; + bool tryDoor(int x, int y) const; + bool isDoor(int x, int y) const; int getEnemyIndex(int id); bool enemyCanStep(const Pos &pos, int dx, int dy) const; void reset(); @@ -64,8 +72,11 @@ public: std::vector<std::vector<char>> map; // source copy of map std::vector<sf::RectangleShape> displayMap; Pos player; + std::vector<char> heldKeys; std::vector<Pos> enemyPositions; std::vector<Pos> treasurePositions; + std::vector<Pos> doorPositions; + std::vector<Pos> keyPositions; private: int idCounter = 1; // defaults at 1 (player always 0) |