CUGL 1.3
Cornell University Game Library
CUMoveAction.h
1 //
2 // CUMoveAction.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for the movement actions. Movement can specified
6 // as either the end target or the movement amount.
7 //
8 // These classes use our standard shared-pointer architecture.
9 //
10 // 1. The constructor does not perform any initialization; it just sets all
11 // attributes to their defaults.
12 //
13 // 2. All initialization takes place via init methods, which can fail if an
14 // object is initialized more than once.
15 //
16 // 3. All allocation takes place via static constructors which return a shared
17 // pointer.
18 //
19 // CUGL MIT License:
20 // This software is provided 'as-is', without any express or implied
21 // warranty. In no event will the authors be held liable for any damages
22 // arising from the use of this software.
23 //
24 // Permission is granted to anyone to use this software for any purpose,
25 // including commercial applications, and to alter it and redistribute it
26 // freely, subject to the following restrictions:
27 //
28 // 1. The origin of this software must not be misrepresented; you must not
29 // claim that you wrote the original software. If you use this software
30 // in a product, an acknowledgment in the product documentation would be
31 // appreciated but is not required.
32 //
33 // 2. Altered source versions must be plainly marked as such, and must not
34 // be misrepresented as being the original software.
35 //
36 // 3. This notice may not be removed or altered from any source distribution.
37 //
38 // Author: Sophie Huang and Walker White
39 // Version: 3/12/17
40 //
41 #ifndef __CU_MOVE_ACTION_H__
42 #define __CU_MOVE_ACTION_H__
43 
44 #include "CUAction.h"
45 
46 namespace cugl {
47 
48 #pragma mark -
49 #pragma mark MoveBy
50 
65 class MoveBy : public Action {
66 protected:
69 
70 public:
71 #pragma mark Constructors
72 
79 
83  ~MoveBy() { dispose(); }
84 
90  void dispose() { _delta = Vec2::ZERO; }
91 
99  bool init() {
100  return init(Vec2(0.0,0.0), 0.0f);
101  }
102 
113  bool init(const Vec2& delta) {
114  return init(delta,0.0f);
115  }
116 
128  bool init(const Vec2& delta, float time);
129 
130 #pragma mark Static Constructors
131 
139  static std::shared_ptr<MoveBy> alloc() {
140  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
141  return (result->init() ? result : nullptr);
142  }
143 
154  static std::shared_ptr<MoveBy> alloc(const Vec2& delta) {
155  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
156  return (result->init(delta) ? result : nullptr);
157  }
158 
170  static std::shared_ptr<MoveBy> alloc(const Vec2& delta, float time) {
171  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
172  return (result->init(delta,time) ? result : nullptr);
173  }
174 
175 #pragma mark Atributes
176 
184  const Vec2& getDelta() const { return _delta; }
185 
194  void setDelta(const Vec2& delta) { _delta = delta; }
195 
196 #pragma mark Animation Methods
197 
202  virtual std::shared_ptr<Action> clone() override;
203 
214  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
215 
216 #pragma mark Debugging Methods
217 
227  virtual std::string toString(bool verbose = false) const override;
228 };
229 
230 
231 #pragma mark -
232 #pragma mark MoveTo
233 
247 class MoveTo : public Action {
248 protected:
251 
252 public:
253 #pragma mark Constructors
254 
261 
265  ~MoveTo() { dispose(); }
266 
272  void dispose() { _target = Vec2::ZERO; }
273 
282  bool init() {
283  return init(Vec2(0.0, 0.0), 0.0f);
284  }
285 
295  bool init(const Vec2& target) {
296  return init(target,0.0f);
297  }
298 
309  bool init(const Vec2& target, float time);
310 
311 #pragma mark Static Constructors
312 
320  static std::shared_ptr<MoveTo> alloc() {
321  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
322  return (result->init() ? result : nullptr);
323  }
324 
334  static std::shared_ptr<MoveTo> alloc(const Vec2& target) {
335  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
336  return (result->init(target) ? result : nullptr);
337  }
338 
349  static std::shared_ptr<MoveTo> alloc(const Vec2& target, float time) {
350  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
351  return (result->init(target, time) ? result : nullptr);
352  }
353 
354 #pragma mark Attributes
355 
363  const Vec2& getTarget() const { return _target; }
364 
373  void setTarget(const Vec2& target) { _target = target; }
374 
375 #pragma mark Animation Methods
376 
381  virtual std::shared_ptr<Action> clone() override;
382 
392  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
393 
404  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
405 
406 #pragma mark Debugging Methods
407 
417  virtual std::string toString(bool verbose = false) const override;
418 };
419 
420 }
421 #endif /* __CU_MOVE_ACTION_H__ */
cugl::MoveTo::toString
virtual std::string toString(bool verbose=false) const override
cugl::Action
Definition: CUAction.h:70
cugl::MoveBy::init
bool init(const Vec2 &delta)
Definition: CUMoveAction.h:113
cugl::MoveTo::dispose
void dispose()
Definition: CUMoveAction.h:272
cugl::MoveTo::_target
Vec2 _target
Definition: CUMoveAction.h:250
cugl::Vec2::ZERO
static const Vec2 ZERO
Definition: CUVec2.h:71
cugl::MoveBy
Definition: CUMoveAction.h:65
cugl::MoveBy::_delta
Vec2 _delta
Definition: CUMoveAction.h:68
cugl::MoveTo::alloc
static std::shared_ptr< MoveTo > alloc(const Vec2 &target)
Definition: CUMoveAction.h:334
cugl::MoveBy::alloc
static std::shared_ptr< MoveBy > alloc(const Vec2 &delta, float time)
Definition: CUMoveAction.h:170
cugl::MoveTo::load
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
cugl::MoveBy::toString
virtual std::string toString(bool verbose=false) const override
cugl::MoveTo::~MoveTo
~MoveTo()
Definition: CUMoveAction.h:265
cugl::MoveTo::init
bool init()
Definition: CUMoveAction.h:282
cugl::MoveBy::alloc
static std::shared_ptr< MoveBy > alloc(const Vec2 &delta)
Definition: CUMoveAction.h:154
cugl::MoveTo::MoveTo
MoveTo()
Definition: CUMoveAction.h:260
cugl::MoveTo::alloc
static std::shared_ptr< MoveTo > alloc(const Vec2 &target, float time)
Definition: CUMoveAction.h:349
cugl::MoveTo::setTarget
void setTarget(const Vec2 &target)
Definition: CUMoveAction.h:373
cugl::MoveTo::alloc
static std::shared_ptr< MoveTo > alloc()
Definition: CUMoveAction.h:320
cugl::MoveBy::dispose
void dispose()
Definition: CUMoveAction.h:90
cugl::MoveBy::alloc
static std::shared_ptr< MoveBy > alloc()
Definition: CUMoveAction.h:139
cugl::MoveBy::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::Vec2
Definition: CUVec2.h:61
cugl::MoveBy::getDelta
const Vec2 & getDelta() const
Definition: CUMoveAction.h:184
cugl::MoveBy::setDelta
void setDelta(const Vec2 &delta)
Definition: CUMoveAction.h:194
cugl::MoveBy::init
bool init()
Definition: CUMoveAction.h:99
cugl::MoveBy::MoveBy
MoveBy()
Definition: CUMoveAction.h:78
cugl::MoveTo::clone
virtual std::shared_ptr< Action > clone() override
cugl::MoveBy::~MoveBy
~MoveBy()
Definition: CUMoveAction.h:83
cugl::MoveBy::clone
virtual std::shared_ptr< Action > clone() override
cugl::MoveTo::getTarget
const Vec2 & getTarget() const
Definition: CUMoveAction.h:363
cugl::MoveTo::update
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
cugl::MoveTo::init
bool init(const Vec2 &target)
Definition: CUMoveAction.h:295
cugl::MoveTo
Definition: CUMoveAction.h:247