TurtleBrains  0.3.5
High quality, portable, C++ framework for rapid 2D game development.
tbx_basic_behaviors.hpp
1 
9 #ifndef TurtleBrains_BasicBehaviors_hpp
10 #define TurtleBrains_BasicBehaviors_hpp
11 
12 #include <turtle_brains/game/tb_entity_behavior_interface.hpp>
13 #include <turtle_brains/game/tb_game_timer.hpp>
14 
15 namespace TurtleBrainsExpress
16 {
17  namespace Behaviors
18  {
19 
25  {
26  public:
33  DelayBehavior(tbGame::Entity& entity, const tbGame::GameTimer& delayTimer);
34 
38  virtual ~DelayBehavior(void);
39 
43  virtual void OnSimulate(void) override;
44 
45  private:
46  tbGame::GameTimer mDelayTimer;
47  };
48 
49 
56  {
57  public:
63  explicit KillBehavior(tbGame::Entity& entity);
64 
68  virtual ~KillBehavior(void);
69 
73  virtual void OnSimulate(void) override;
74 
75  private:
76  };
77 
78 
84  {
85  public:
95  explicit FlickerForBehavior(tbGame::Entity& entity, const tbGame::GameTimer& flickerToggleTime,
96  const tbGame::GameTimer& forTimer, const bool visibleOnPop = true);
97 
101  virtual ~FlickerForBehavior(void);
102 
107  virtual void OnRemove(void) override;
108 
114  virtual void OnSimulate(void) override;
115 
116  private:
117  const tbGame::GameTimer mTimeBetweenFlickers;
118  tbGame::GameTimer mTimeRemaining;
119  tbGame::GameTimer mFlickerTimer;
120  const bool mIsVisibleOnPop;
121  };
122 
124  namespace Unstable
125  {
126 
127  template<typename Type> class SetVariableBehavior : public tbGame::EntityBehaviorInterface
128  {
129  public:
130  inline SetVariableBehavior(tbGame::Entity& entity, Type& variableReference, const Type setValue) :
131  tbGame::EntityBehaviorInterface(entity),
132  mVariableReference(variableReference),
133  mSetValue(setValue)
134  {
135  }
136 
137  inline virtual ~SetVariableBehavior(void)
138  {
139  }
140 
141  inline virtual void OnResume(void) override
142  {
143  mVariableReference = mSetValue;
144  mEntity.PopBehavior();
145  }
146 
147  inline virtual void OnSimulate(void) override
148  {
149  mVariableReference = mSetValue;
150  mEntity.PopBehavior();
151  }
152 
153  private:
154  Type& mVariableReference;
155  const Type mSetValue;
156  };
157 
158  }; /* namespace Unstable */
160 
161  }; /* namespace Behaviors */
162 }; /* namespace TurtleBrainsExpress */
163 
165 
166 #endif /* TurtleBrains_BasicBehaviors_hpp */
Definition: tb_entity.hpp:46
Definition: tbx_basic_behaviors.hpp:83
Definition: tbx_basic_behaviors.hpp:24
Definition: tb_entity_behavior_interface.hpp:24
virtual void OnSimulate(void) override
A collection of objects and functions to express games quickly.
virtual void OnSimulate(void) override
FlickerForBehavior(tbGame::Entity &entity, const tbGame::GameTimer &flickerToggleTime, const tbGame::GameTimer &forTimer, const bool visibleOnPop=true)
Definition: tbx_basic_behaviors.hpp:55
DelayBehavior(tbGame::Entity &entity, const tbGame::GameTimer &delayTimer)
Contains high-level objects to control the entities in game worlds.
This is the heart of TurtleBrains for game developers to create GameScenes and Entities to interact w...
Definition: tb_game_timer.hpp:25