diff options
Diffstat (limited to 'src/systems/animating.cpp')
| -rw-r--r-- | src/systems/animating.cpp | 93 |
1 files changed, 56 insertions, 37 deletions
| diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index 634af67..8543ba2 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp | |||
| @@ -13,26 +13,29 @@ void AnimatingSystem::tick(double) | |||
| 13 | auto& sprite = game_.getEntityManager(). | 13 | auto& sprite = game_.getEntityManager(). |
| 14 | getComponent<AnimatableComponent>(entity); | 14 | getComponent<AnimatableComponent>(entity); |
| 15 | 15 | ||
| 16 | if (!sprite.isFrozen()) | 16 | if (sprite.active) |
| 17 | { | 17 | { |
| 18 | sprite.setCountdown(sprite.getCountdown() + 1); | 18 | if (!sprite.frozen) |
| 19 | } | 19 | { |
| 20 | 20 | sprite.countdown++; | |
| 21 | const Animation& anim = sprite.getAnimation(); | 21 | } |
| 22 | if (sprite.getCountdown() >= anim.getDelay()) | ||
| 23 | { | ||
| 24 | sprite.setFrame(sprite.getFrame() + 1); | ||
| 25 | sprite.setCountdown(0); | ||
| 26 | 22 | ||
| 27 | if (sprite.getFrame() >= anim.getFirstFrame() + anim.getNumFrames()) | 23 | const Animation& anim = sprite.getAnimation(); |
| 24 | if (sprite.countdown >= anim.getDelay()) | ||
| 28 | { | 25 | { |
| 29 | sprite.setFrame(anim.getFirstFrame()); | 26 | sprite.frame++; |
| 27 | sprite.countdown = 0; | ||
| 28 | |||
| 29 | if (sprite.frame >= anim.getFirstFrame() + anim.getNumFrames()) | ||
| 30 | { | ||
| 31 | sprite.frame = anim.getFirstFrame(); | ||
| 32 | } | ||
| 30 | } | 33 | } |
| 31 | } | ||
| 32 | 34 | ||
| 33 | if (sprite.isFlickering()) | 35 | if (sprite.flickering) |
| 34 | { | 36 | { |
| 35 | sprite.setFlickerTimer((sprite.getFlickerTimer() + 1) % 6); | 37 | sprite.flickerTimer = (sprite.flickerTimer + 1) % 6; |
| 38 | } | ||
| 36 | } | 39 | } |
| 37 | } | 40 | } |
| 38 | } | 41 | } |
| @@ -49,36 +52,52 @@ void AnimatingSystem::render(Texture& texture) | |||
| 49 | auto& sprite = game_.getEntityManager(). | 52 | auto& sprite = game_.getEntityManager(). |
| 50 | getComponent<AnimatableComponent>(entity); | 53 | getComponent<AnimatableComponent>(entity); |
| 51 | 54 | ||
| 52 | auto& transform = game_.getEntityManager(). | 55 | if (sprite.active) |
| 53 | getComponent<TransformableComponent>(entity); | ||
| 54 | |||
| 55 | double alpha = 1.0; | ||
| 56 | if (sprite.isFlickering() && (sprite.getFlickerTimer() < 3)) | ||
| 57 | { | 56 | { |
| 58 | alpha = 0.0; | 57 | auto& transform = game_.getEntityManager(). |
| 59 | } | 58 | getComponent<TransformableComponent>(entity); |
| 60 | 59 | ||
| 61 | Rectangle dstrect { | 60 | double alpha = 1.0; |
| 62 | static_cast<int>(transform.getX()), | 61 | if (sprite.flickering && (sprite.flickerTimer < 3)) |
| 63 | static_cast<int>(transform.getY()), | 62 | { |
| 64 | transform.getW(), | 63 | alpha = 0.0; |
| 65 | transform.getH()}; | 64 | } |
| 66 | 65 | ||
| 67 | const AnimationSet& aset = sprite.getAnimationSet(); | 66 | Rectangle dstrect { |
| 68 | game_.getRenderer().blit( | 67 | static_cast<int>(transform.x), |
| 69 | aset.getTexture(), | 68 | static_cast<int>(transform.y), |
| 70 | texture, | 69 | transform.w, |
| 71 | aset.getFrameRect(sprite.getFrame()), | 70 | transform.h}; |
| 72 | dstrect, | 71 | |
| 73 | alpha); | 72 | const AnimationSet& aset = sprite.animationSet; |
| 73 | game_.getRenderer().blit( | ||
| 74 | aset.getTexture(), | ||
| 75 | texture, | ||
| 76 | aset.getFrameRect(sprite.frame), | ||
| 77 | dstrect, | ||
| 78 | alpha); | ||
| 79 | } | ||
| 74 | } | 80 | } |
| 75 | } | 81 | } |
| 76 | 82 | ||
| 83 | void AnimatingSystem::initPrototype(id_type entity) | ||
| 84 | { | ||
| 85 | auto& sprite = game_.getEntityManager(). | ||
| 86 | getComponent<AnimatableComponent>(entity); | ||
| 87 | |||
| 88 | startAnimation(entity, sprite.origAnimation); | ||
| 89 | |||
| 90 | sprite.countdown = 0; | ||
| 91 | sprite.flickering = false; | ||
| 92 | sprite.flickerTimer = 0; | ||
| 93 | sprite.frozen = false; | ||
| 94 | } | ||
| 95 | |||
| 77 | void AnimatingSystem::startAnimation(id_type entity, std::string animation) | 96 | void AnimatingSystem::startAnimation(id_type entity, std::string animation) |
| 78 | { | 97 | { |
| 79 | auto& sprite = game_.getEntityManager(). | 98 | auto& sprite = game_.getEntityManager(). |
| 80 | getComponent<AnimatableComponent>(entity); | 99 | getComponent<AnimatableComponent>(entity); |
| 81 | 100 | ||
| 82 | sprite.setAnimation(animation); | 101 | sprite.animation = std::move(animation); |
| 83 | sprite.setFrame(sprite.getAnimation().getFirstFrame()); | 102 | sprite.frame = sprite.getAnimation().getFirstFrame(); |
| 84 | } | 103 | } |
