Cornell Cocos
Cornell Extensions to Cocos2d
All Classes Functions Variables Enumerations Enumerator Friends
CUBoxObstacle.h
1 //
2 // CUBoxObstacle.h
3 // Cornell Extensions to Cocos2D
4 //
5 // This class implements a rectangular physics object, and is the primary type of
6 // physics object to use.
7 //
8 // This file is based on the CS 3152 PhysicsDemo Lab by Don Holden, 2007
9 //
10 // Author: Walker White
11 // Version: 11/24/15
12 //
13 #ifndef __CU_BOX_OBSTACLE_H__
14 #define __CU_BOX_OBSTACLE_H__
15 
16 #include <Box2D/Collision/Shapes/b2PolygonShape.h>
17 #include "CUSimpleObstacle.h"
18 
19 
20 NS_CC_BEGIN
21 #pragma mark -
22 #pragma mark Box Obstacle
23 
33 class CC_DLL BoxObstacle : public SimpleObstacle {
34 private:
36  CC_DISALLOW_COPY_AND_ASSIGN(BoxObstacle);
37 
38 protected:
40  b2PolygonShape _shape;
42  b2Fixture* _geometry;
44  Size _dimension;
45 
46 
47 #pragma mark -
48 #pragma mark Scene Graph Methods
49 
57  void resize(const Size& size);
58 
66  virtual void resetDebugNode() override;
67 
68 
69 public:
70 #pragma mark -
71 #pragma mark Static Constructors
72 
77  static BoxObstacle* create();
78 
91  static BoxObstacle* create(const Vec2& pos);
92 
106  static BoxObstacle* create(const Vec2& pos, const Size& size);
107 
108 
109 #pragma mark -
110 #pragma mark Dimensions
111 
116  const Size& getDimension() const { return _dimension; }
117 
123  void setDimension(const Size& value) { resize(value); markDirty(true); }
124 
131  void setDimension(float width, float height) { setDimension(Size(width,height)); }
132 
138  float getWidth() const { return _dimension.width; }
139 
145  void setWidth(float value) { setDimension(value,_dimension.height); }
146 
152  float getHeight() const { return _dimension.height; }
153 
159  void setHeight(float value) { setDimension(_dimension.width,value); }
160 
161 
162 #pragma mark -
163 #pragma mark Physics Methods
164 
170  virtual void createFixtures() override;
171 
177  virtual void releaseFixtures() override;
178 
179 
180 #pragma mark -
181 #pragma mark Initializers
182 CC_CONSTRUCTOR_ACCESS:
183  /*
184  * Creates a new box object at the origin.
185  */
186  BoxObstacle(void) : SimpleObstacle(), _geometry(nullptr) { }
187 
193  virtual bool init() override { return init(Vec2::ZERO,Size::ZERO); }
194 
207  virtual bool init(const Vec2& pos) override { return init(pos,Size::ZERO); }
208 
222  virtual bool init(const Vec2& pos, const Size& size);
223 
224 };
225 
226 NS_CC_END
227 #endif /* defined(__CU_BOX_OBSTACLE_H__) */
float getWidth() const
Definition: CUBoxObstacle.h:138
b2PolygonShape _shape
Definition: CUBoxObstacle.h:40
void setDimension(const Size &value)
Definition: CUBoxObstacle.h:123
virtual bool init() override
Definition: CUBoxObstacle.h:193
virtual void createFixtures()
Definition: CUSimpleObstacle.h:792
virtual void releaseFixtures()
Definition: CUSimpleObstacle.h:799
Definition: CUSimpleObstacle.h:36
virtual void resetDebugNode()
Definition: CUObstacle.h:106
virtual bool init()
Definition: CUObstacle.h:982
Size _dimension
Definition: CUBoxObstacle.h:44
void setDimension(float width, float height)
Definition: CUBoxObstacle.h:131
void markDirty(bool value)
Definition: CUObstacle.h:758
virtual bool init(const Vec2 &pos) override
Definition: CUBoxObstacle.h:207
b2Fixture * _geometry
Definition: CUBoxObstacle.h:42
Definition: CUBoxObstacle.h:33
const Size & getDimension() const
Definition: CUBoxObstacle.h:116
float getHeight() const
Definition: CUBoxObstacle.h:152
void setWidth(float value)
Definition: CUBoxObstacle.h:145
void setHeight(float value)
Definition: CUBoxObstacle.h:159