summary refs log tree commit diff stats
path: root/src/components/animatable.h
blob: 1a678ba2713b1da774c06cf10495b89c6510020a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef SPRITE_RENDERABLE_H_D3AACBBF
#define SPRITE_RENDERABLE_H_D3AACBBF

#include "component.h"
#include "animation.h"
#include <string>

class AnimatableComponent : public Component {
public:

  /**
   * Constructor for initializing the animation set, because it is not default
   * constructible.
   */
  AnimatableComponent(
    AnimationSet animationSet) :
      animationSet(std::move(animationSet))
  {
  }

  /**
   * The animation set that this entity will use -- an object describing the
   * different animations that can be used to render the entity.
   *
   * @managed_by RealizingSystem
   */
  AnimationSet animationSet;

  /**
   * The name of the currently active animation.
   *
   * @managed_by AnimatingSystem
   */
  std::string animation;

  /**
   * For prototypes, the name of the original animation.
   *
   * @managed_by RealizingSystem
   */
  std::string origAnimation;

  /**
   * Helper method for accessing the currently active animation.
   */
  inline const Animation& getAnimation() const
  {
    return animationSet.getAnimation(animation);
  }

  /**
   * The frame of animation that is currently being rendered.
   *
   * @managed_by AnimatingSystem
   */
  size_t frame = 0;

  /**
   * The amount of time (in game frames) before the animation is advanced.
   *
   * @managed_by AnimatingSystem
   */
  size_t countdown = 0;

  /**
   * This option allows to give the sprite a "flickering" effect (as in, it is
   * not rendered in some frames).
   */
  bool flickering = false;

  /**
   * Used for the flickering effect.
   *
   * @managed_by AnimatingSystem
   */
  size_t flickerTimer = 0;

  /**
   * If enabled, this will prevent the sprite's animation from progressing (but
   * will not affect things such as placement on screen and flickering).
   */
  bool frozen = false;

  /**
   * If this flag is disabled, the entity will be ignored by the animating
   * system.
   *
   * @managed_by RealizingSystem
   */
  bool active = false;
};

#endif /* end of include guard: SPRITE_RENDERABLE_H_D3AACBBF */