diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/direction.h | 13 | ||||
| -rw-r--r-- | src/game.cpp | 5 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/map.cpp | 8 | ||||
| -rw-r--r-- | src/map.h | 3 | ||||
| -rw-r--r-- | src/mirror_system.cpp | 29 | ||||
| -rw-r--r-- | src/mirror_system.h | 22 | ||||
| -rw-r--r-- | src/sprite.h | 10 | ||||
| -rw-r--r-- | src/system.h | 1 |
9 files changed, 93 insertions, 0 deletions
| diff --git a/src/direction.h b/src/direction.h index 432f7a9..325bcaf 100644 --- a/src/direction.h +++ b/src/direction.h | |||
| @@ -65,6 +65,19 @@ inline Direction oppositeDirection(Direction value) { | |||
| 65 | } | 65 | } |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | inline Direction directionMirroredVertically(Direction value) { | ||
| 69 | switch (value) { | ||
| 70 | case Direction::up: return Direction::down; | ||
| 71 | case Direction::up_right: return Direction::down_right; | ||
| 72 | case Direction::right: return Direction::right; | ||
| 73 | case Direction::down_right: return Direction::up_right; | ||
| 74 | case Direction::down: return Direction::up; | ||
| 75 | case Direction::down_left: return Direction::up_left; | ||
| 76 | case Direction::left: return Direction::left; | ||
| 77 | case Direction::up_left: return Direction::down_left; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 68 | inline Direction directionFacingPoint(vec2i point) { | 81 | inline Direction directionFacingPoint(vec2i point) { |
| 69 | double theta = atan2(-point.y(), point.x()); | 82 | double theta = atan2(-point.y(), point.x()); |
| 70 | theta /= M_PI; | 83 | theta /= M_PI; |
| diff --git a/src/game.cpp b/src/game.cpp index 7e3c88f..bedd934 100644 --- a/src/game.cpp +++ b/src/game.cpp | |||
| @@ -76,6 +76,11 @@ void Game::loadMap(std::string filename) { | |||
| 76 | if (!p.enclosureZone.empty()) { | 76 | if (!p.enclosureZone.empty()) { |
| 77 | getSprite(spriteId).enclosureZone = p.enclosureZone; | 77 | getSprite(spriteId).enclosureZone = p.enclosureZone; |
| 78 | } | 78 | } |
| 79 | if (p.mirrorType != MirrorType::None) { | ||
| 80 | getSprite(spriteId).mirrorType = p.mirrorType; | ||
| 81 | getSprite(spriteId).mirrorAxis = p.mirrorAxis; | ||
| 82 | getSprite(spriteId).mirroredSpriteId = getSpriteByAlias(p.spriteToMirror); | ||
| 83 | } | ||
| 79 | } | 84 | } |
| 80 | 85 | ||
| 81 | for (const Trigger& t : map_->getTriggers()) { | 86 | for (const Trigger& t : map_->getTriggers()) { |
| diff --git a/src/main.cpp b/src/main.cpp index d0220fc..772fff8 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
| @@ -14,6 +14,7 @@ | |||
| 14 | #include "script_system.h" | 14 | #include "script_system.h" |
| 15 | #include "effect_system.h" | 15 | #include "effect_system.h" |
| 16 | #include "behaviour_system.h" | 16 | #include "behaviour_system.h" |
| 17 | #include "mirror_system.h" | ||
| 17 | 18 | ||
| 18 | void loop(Renderer& renderer, std::mt19937& rng) { | 19 | void loop(Renderer& renderer, std::mt19937& rng) { |
| 19 | Game game(renderer, rng); | 20 | Game game(renderer, rng); |
| @@ -22,6 +23,7 @@ void loop(Renderer& renderer, std::mt19937& rng) { | |||
| 22 | game.emplaceSystem<InputSystem>(); | 23 | game.emplaceSystem<InputSystem>(); |
| 23 | game.emplaceSystem<BehaviourSystem>(); | 24 | game.emplaceSystem<BehaviourSystem>(); |
| 24 | game.emplaceSystem<CharacterSystem>(); | 25 | game.emplaceSystem<CharacterSystem>(); |
| 26 | game.emplaceSystem<MirrorSystem>(); | ||
| 25 | game.emplaceSystem<AnimationSystem>(); | 27 | game.emplaceSystem<AnimationSystem>(); |
| 26 | game.emplaceSystem<CameraSystem>(); | 28 | game.emplaceSystem<CameraSystem>(); |
| 27 | game.emplaceSystem<MessageSystem>(); | 29 | game.emplaceSystem<MessageSystem>(); |
| diff --git a/src/map.cpp b/src/map.cpp index 8d0ada6..32203e5 100644 --- a/src/map.cpp +++ b/src/map.cpp | |||
| @@ -111,6 +111,14 @@ Map::Map(std::string_view name) : name_(name) { | |||
| 111 | p.enclosureZone = property.getStringValue(); | 111 | p.enclosureZone = property.getStringValue(); |
| 112 | } else if (property.getName() == "movementSpeed") { | 112 | } else if (property.getName() == "movementSpeed") { |
| 113 | p.movementSpeed = property.getIntValue(); | 113 | p.movementSpeed = property.getIntValue(); |
| 114 | } else if (property.getName() == "mirror") { | ||
| 115 | if (property.getStringValue() == "vertical") { | ||
| 116 | p.mirrorType = MirrorType::Vertical; | ||
| 117 | } | ||
| 118 | } else if (property.getName() == "mirrorAxis") { | ||
| 119 | p.mirrorAxis = property.getIntValue(); | ||
| 120 | } else if (property.getName() == "mirrorSprite") { | ||
| 121 | p.spriteToMirror = property.getStringValue(); | ||
| 114 | } | 122 | } |
| 115 | } | 123 | } |
| 116 | 124 | ||
| diff --git a/src/map.h b/src/map.h index 1167290..eb926c7 100644 --- a/src/map.h +++ b/src/map.h | |||
| @@ -32,6 +32,9 @@ struct Prototype { | |||
| 32 | int movementSpeed = -1; | 32 | int movementSpeed = -1; |
| 33 | std::string enclosureZone; | 33 | std::string enclosureZone; |
| 34 | bool masked = false; | 34 | bool masked = false; |
| 35 | MirrorType mirrorType = MirrorType::None; | ||
| 36 | int mirrorAxis = 0; | ||
| 37 | std::string spriteToMirror; | ||
| 35 | }; | 38 | }; |
| 36 | 39 | ||
| 37 | struct Trigger { | 40 | struct Trigger { |
| diff --git a/src/mirror_system.cpp b/src/mirror_system.cpp new file mode 100644 index 0000000..b506e59 --- /dev/null +++ b/src/mirror_system.cpp | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #include "mirror_system.h" | ||
| 2 | #include "game.h" | ||
| 3 | #include "transform_system.h" | ||
| 4 | #include "animation_system.h" | ||
| 5 | #include "vector.h" | ||
| 6 | #include "sprite.h" | ||
| 7 | |||
| 8 | void MirrorSystem::tick(double dt) { | ||
| 9 | for (int spriteId : game_.getSprites()) { | ||
| 10 | Sprite& sprite = game_.getSprite(spriteId); | ||
| 11 | if (!sprite.paused) { | ||
| 12 | switch (sprite.mirrorType) { | ||
| 13 | case MirrorType::None: break; | ||
| 14 | case MirrorType::Vertical: { | ||
| 15 | Sprite& mirroredSprite = game_.getSprite(sprite.mirroredSpriteId); | ||
| 16 | |||
| 17 | vec2i mirroredLoc = mirroredSprite.loc; | ||
| 18 | mirroredLoc.y() = 2 * sprite.mirrorAxis - mirroredLoc.y(); | ||
| 19 | |||
| 20 | game_.getSystem<TransformSystem>().moveSprite(spriteId, mirroredLoc); | ||
| 21 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, mirroredSprite.animationName); | ||
| 22 | game_.getSystem<AnimationSystem>().setSpriteDirection(spriteId, directionMirroredVertically(mirroredSprite.dir)); | ||
| 23 | |||
| 24 | break; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| diff --git a/src/mirror_system.h b/src/mirror_system.h new file mode 100644 index 0000000..5549dc4 --- /dev/null +++ b/src/mirror_system.h | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | #ifndef MIRROR_SYSTEM_H_0BA755A8 | ||
| 2 | #define MIRROR_SYSTEM_H_0BA755A8 | ||
| 3 | |||
| 4 | #include "system.h" | ||
| 5 | |||
| 6 | class Game; | ||
| 7 | |||
| 8 | class MirrorSystem : public System { | ||
| 9 | public: | ||
| 10 | |||
| 11 | static constexpr SystemKey Key = SystemKey::Mirror; | ||
| 12 | |||
| 13 | explicit MirrorSystem(Game& game) : game_(game) {} | ||
| 14 | |||
| 15 | void tick(double dt) override; | ||
| 16 | |||
| 17 | private: | ||
| 18 | |||
| 19 | Game& game_; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #endif /* end of include guard: MIRROR_SYSTEM_H_0BA755A8 */ | ||
| diff --git a/src/sprite.h b/src/sprite.h index 6538c1d..2ab306d 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
| @@ -48,6 +48,11 @@ enum class BehaviourType { | |||
| 48 | Path | 48 | Path |
| 49 | }; | 49 | }; |
| 50 | 50 | ||
| 51 | enum class MirrorType { | ||
| 52 | None, | ||
| 53 | Vertical | ||
| 54 | }; | ||
| 55 | |||
| 51 | struct Movement { | 56 | struct Movement { |
| 52 | vec2i pos; | 57 | vec2i pos; |
| 53 | Direction dir; | 58 | Direction dir; |
| @@ -123,6 +128,11 @@ public: | |||
| 123 | vec2i pathfindingDestination; | 128 | vec2i pathfindingDestination; |
| 124 | bool cardinalDirectionsOnly = false; | 129 | bool cardinalDirectionsOnly = false; |
| 125 | std::deque<PathfindingInstruction> path; | 130 | std::deque<PathfindingInstruction> path; |
| 131 | |||
| 132 | // Mirror | ||
| 133 | MirrorType mirrorType = MirrorType::None; | ||
| 134 | int mirroredSpriteId = -1; | ||
| 135 | int mirrorAxis = 0; | ||
| 126 | }; | 136 | }; |
| 127 | 137 | ||
| 128 | #endif /* end of include guard: SPRITE_H_70503825 */ | 138 | #endif /* end of include guard: SPRITE_H_70503825 */ |
| diff --git a/src/system.h b/src/system.h index c0b0637..a129b3b 100644 --- a/src/system.h +++ b/src/system.h | |||
| @@ -7,6 +7,7 @@ enum class SystemKey { | |||
| 7 | Input, | 7 | Input, |
| 8 | Behaviour, | 8 | Behaviour, |
| 9 | Character, | 9 | Character, |
| 10 | Mirror, | ||
| 10 | Animation, | 11 | Animation, |
| 11 | Camera, | 12 | Camera, |
| 12 | Message, | 13 | Message, |
