diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-03-05 20:50:51 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-03-05 20:50:51 -0500 |
commit | 1c462ef3780b33468ed93dde3ab6178765807ffe (patch) | |
tree | 6ee2f34ed3514c10d146c91b0e8e935cf9d1ccb6 /src/mirror_system.cpp | |
parent | 937875c4e1432b418f0f5051759e02c8d4c9ffa4 (diff) | |
download | tanetane-1c462ef3780b33468ed93dde3ab6178765807ffe.tar.gz tanetane-1c462ef3780b33468ed93dde3ab6178765807ffe.tar.bz2 tanetane-1c462ef3780b33468ed93dde3ab6178765807ffe.zip |
Added MirrorSystem
This is really just for letting one sprite mirror another's movement and animation. I tried doing it in the BehaviourSystem, but you get stuttering if you do it earlier in the loop than the CharacterSystem, so I ended up having to make a new system just for this thing that will not happen very often.
Diffstat (limited to 'src/mirror_system.cpp')
-rw-r--r-- | src/mirror_system.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
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 | } | ||