From 1c462ef3780b33468ed93dde3ab6178765807ffe Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 5 Mar 2021 20:50:51 -0500 Subject: 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. --- src/mirror_system.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/mirror_system.cpp (limited to 'src/mirror_system.cpp') 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 @@ +#include "mirror_system.h" +#include "game.h" +#include "transform_system.h" +#include "animation_system.h" +#include "vector.h" +#include "sprite.h" + +void MirrorSystem::tick(double dt) { + for (int spriteId : game_.getSprites()) { + Sprite& sprite = game_.getSprite(spriteId); + if (!sprite.paused) { + switch (sprite.mirrorType) { + case MirrorType::None: break; + case MirrorType::Vertical: { + Sprite& mirroredSprite = game_.getSprite(sprite.mirroredSpriteId); + + vec2i mirroredLoc = mirroredSprite.loc; + mirroredLoc.y() = 2 * sprite.mirrorAxis - mirroredLoc.y(); + + game_.getSystem().moveSprite(spriteId, mirroredLoc); + game_.getSystem().setSpriteAnimation(spriteId, mirroredSprite.animationName); + game_.getSystem().setSpriteDirection(spriteId, directionMirroredVertically(mirroredSprite.dir)); + + break; + } + } + } + } +} -- cgit 1.4.1