CUGL 1.1
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 zlib 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 
78  MoveBy() { _delta = Vec2::ZERO; }
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 
141  static std::shared_ptr<MoveBy> alloc() {
142  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
143  return (result->init() ? result : nullptr);
144  }
145 
156  static std::shared_ptr<MoveBy> alloc(const Vec2& delta) {
157  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
158  return (result->init(delta) ? result : nullptr);
159  }
160 
172  static std::shared_ptr<MoveBy> alloc(const Vec2& delta, float time) {
173  std::shared_ptr<MoveBy> result = std::make_shared<MoveBy>();
174  return (result->init(delta,time) ? result : nullptr);
175  }
176 
177 #pragma mark Atributes
178 
186  const Vec2& getDelta() const { return _delta; }
187 
196  void setDelta(const Vec2& delta) { _delta = delta; }
197 
198 #pragma mark Animation Methods
199 
204  virtual std::shared_ptr<Action> clone() override;
205 
216  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
217 
218 #pragma mark Debugging Methods
219 
229  virtual std::string toString(bool verbose = false) const override;
230 };
231 
232 
233 #pragma mark -
234 #pragma mark MoveTo
235 
249 class MoveTo : public Action {
250 protected:
253 
254 public:
255 #pragma mark Constructors
256 
262  MoveTo() { _target = Vec2::ZERO; }
263 
267  ~MoveTo() { dispose(); }
268 
274  void dispose() { _target = Vec2::ZERO; }
275 
284  bool init() {
285  return init(Vec2(0.0, 0.0), 0.0f);
286  }
287 
297  bool init(const Vec2& target) {
298  return init(target,0.0f);
299  }
300 
311  bool init(const Vec2& target, float time);
312 
313 #pragma mark Static Constructors
314 
322  static std::shared_ptr<MoveTo> alloc() {
323  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
324  return (result->init() ? result : nullptr);
325  }
326 
336  static std::shared_ptr<MoveTo> alloc(const Vec2& target) {
337  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
338  return (result->init(target) ? result : nullptr);
339  }
340 
351  static std::shared_ptr<MoveTo> alloc(const Vec2& target, float time) {
352  std::shared_ptr<MoveTo> result = std::make_shared<MoveTo>();
353  return (result->init(target, time) ? result : nullptr);
354  }
355 
356 #pragma mark Attributes
357 
365  const Vec2& getTarget() const { return _target; }
366 
375  void setTarget(const Vec2& target) { _target = target; }
376 
377 #pragma mark Animation Methods
378 
383  virtual std::shared_ptr<Action> clone() override;
384 
394  virtual void load(const std::shared_ptr<Node>& target, Uint64* state) override;
395 
406  virtual void update(const std::shared_ptr<Node>& target, Uint64* state, float dt) override;
407 
408 #pragma mark Debugging Methods
409 
419  virtual std::string toString(bool verbose = false) const override;
420 };
421 
422 }
423 #endif /* __CU_MOVE_ACTION_H__ */
virtual std::shared_ptr< Action > clone() override
Definition: CUMoveAction.h:249
MoveBy()
Definition: CUMoveAction.h:78
static std::shared_ptr< MoveTo > alloc(const Vec2 &target)
Definition: CUMoveAction.h:336
Vec2 _delta
Definition: CUMoveAction.h:68
Definition: CUVec2.h:61
static std::shared_ptr< MoveBy > alloc(const Vec2 &delta, float time)
Definition: CUMoveAction.h:172
void setTarget(const Vec2 &target)
Definition: CUMoveAction.h:375
Definition: CUMoveAction.h:65
static std::shared_ptr< MoveTo > alloc()
Definition: CUMoveAction.h:322
const Vec2 & getTarget() const
Definition: CUMoveAction.h:365
static std::shared_ptr< MoveBy > alloc(const Vec2 &delta)
Definition: CUMoveAction.h:156
Definition: CUAction.h:70
virtual void load(const std::shared_ptr< Node > &target, Uint64 *state) override
static std::shared_ptr< MoveTo > alloc(const Vec2 &target, float time)
Definition: CUMoveAction.h:351
virtual std::string toString(bool verbose=false) const override
~MoveBy()
Definition: CUMoveAction.h:83
virtual std::string toString(bool verbose=false) const override
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
MoveTo()
Definition: CUMoveAction.h:262
bool init()
Definition: CUMoveAction.h:284
bool init()
Definition: CUMoveAction.h:99
~MoveTo()
Definition: CUMoveAction.h:267
Vec2 _target
Definition: CUMoveAction.h:252
virtual void update(const std::shared_ptr< Node > &target, Uint64 *state, float dt) override
void dispose()
Definition: CUMoveAction.h:90
void dispose()
Definition: CUMoveAction.h:274
bool init(const Vec2 &delta)
Definition: CUMoveAction.h:113
void setDelta(const Vec2 &delta)
Definition: CUMoveAction.h:196
bool init(const Vec2 &target)
Definition: CUMoveAction.h:297
Definition: CUAction.h:51
static const Vec2 ZERO
Definition: CUVec2.h:71
virtual std::shared_ptr< Action > clone() override
const Vec2 & getDelta() const
Definition: CUMoveAction.h:186
static std::shared_ptr< MoveBy > alloc()
Definition: CUMoveAction.h:141