15 #ifndef __CC_SIMPLE_OBSTACLE_H__
16 #define __CC_SIMPLE_OBSTACLE_H__
18 #include "CUObstacle.h"
24 #pragma mark Simple Obstacle
57 #pragma mark BodyDef Methods
68 return (_body !=
nullptr ? _body->GetType() : _bodyinfo.type);
81 if (_body !=
nullptr) {
82 _body->SetType(value);
84 _bodyinfo.type = value;
98 if (_body !=
nullptr) {
99 return Vec2(_body->GetPosition().x,_body->GetPosition().y);
101 return Vec2(_bodyinfo.position.x,_bodyinfo.position.y);
122 if (_body !=
nullptr) {
123 _body->SetTransform(b2Vec2(x,y),_body->GetAngle());
125 _bodyinfo.position.Set(x,y);
134 virtual float getX()
const override {
135 return (_body !=
nullptr ? _body->GetPosition().x : _bodyinfo.position.x);
143 virtual void setX(
float value)
override {
144 if (_body !=
nullptr) {
145 _body->SetTransform(b2Vec2(value,_body->GetPosition().y),_body->GetAngle());
147 _bodyinfo.position.x = value;
156 virtual float getY()
const override {
157 return (_body !=
nullptr ? _body->GetPosition().y : _bodyinfo.position.y);
165 virtual void setY(
float value)
override {
166 if (_body !=
nullptr) {
167 _body->SetTransform(b2Vec2(_body->GetPosition().y,value),_body->GetAngle());
169 _bodyinfo.position.y = value;
181 return (_body !=
nullptr ? _body->GetAngle() : _bodyinfo.angle);
190 if (_body !=
nullptr) {
191 _body->SetTransform(_body->GetPosition(),value);
193 _bodyinfo.angle = value;
207 if (_body !=
nullptr) {
208 return Vec2(_body->GetLinearVelocity().x,_body->GetLinearVelocity().y);
210 return Vec2(_bodyinfo.linearVelocity.x,_bodyinfo.linearVelocity.y);
231 if (_body !=
nullptr) {
232 _body->SetLinearVelocity(b2Vec2(x,y));
234 _bodyinfo.linearVelocity.Set(x,y);
243 virtual float getVX()
const override {
244 if (_body !=
nullptr) {
245 return _body->GetLinearVelocity().x;
247 return _bodyinfo.linearVelocity.x;
256 virtual void setVX(
float value)
override {
257 if (_body !=
nullptr) {
258 _body->SetLinearVelocity(b2Vec2(value,_body->GetLinearVelocity().y));
260 _bodyinfo.linearVelocity.x = value;
269 virtual float getVY()
const override {
270 if (_body !=
nullptr) {
271 return _body->GetLinearVelocity().y;
273 return _bodyinfo.linearVelocity.y;
282 virtual void setVY(
float value)
override {
283 if (_body !=
nullptr) {
284 _body->SetLinearVelocity(b2Vec2(_body->GetLinearVelocity().x,value));
286 _bodyinfo.linearVelocity.y = value;
298 return (_body !=
nullptr ? _body->GetAngularVelocity() : _bodyinfo.angularVelocity);
307 if (_body !=
nullptr) {
308 _body->SetAngularVelocity(value);
310 _bodyinfo.angularVelocity = value;
325 return (_body !=
nullptr ? _body->IsActive() : _bodyinfo.active);
339 if (_body !=
nullptr) {
340 _body->SetActive(value);
342 _bodyinfo.active = value;
357 return (_body !=
nullptr ? _body->IsAwake() : _bodyinfo.awake);
371 if (_body !=
nullptr) {
372 _body->SetAwake(value);
374 _bodyinfo.awake = value;
389 return (_body !=
nullptr ? _body->IsSleepingAllowed() : _bodyinfo.allowSleep);
403 if (_body !=
nullptr) {
404 _body->SetSleepingAllowed(value);
406 _bodyinfo.allowSleep = value;
427 return (_body !=
nullptr ? _body->IsBullet() : _bodyinfo.bullet);
447 if (_body !=
nullptr) {
448 _body->SetBullet(value);
450 _bodyinfo.bullet = value;
462 return (_body !=
nullptr ? _body->IsFixedRotation() : _bodyinfo.fixedRotation);
473 if (_body !=
nullptr) {
474 _body->SetFixedRotation(value);
476 _bodyinfo.fixedRotation = value;
489 return (_body !=
nullptr ? _body->GetGravityScale() : _bodyinfo.gravityScale);
501 if (_body !=
nullptr) {
502 _body->SetGravityScale(value);
504 _bodyinfo.gravityScale = value;
522 return (_body !=
nullptr ? _body->GetLinearDamping() : _bodyinfo.linearDamping);
539 if (_body !=
nullptr) {
540 _body->SetLinearDamping(value);
542 _bodyinfo.linearDamping = value;
560 return (_body !=
nullptr ? _body->GetAngularDamping() : _bodyinfo.angularDamping);
577 if (_body !=
nullptr) {
578 _body->SetAngularDamping(value);
580 _bodyinfo.angularDamping = value;
586 #pragma mark FixtureDef Methods
596 virtual void setDensity(
float value)
override;
633 virtual void setSensor(
bool value)
override;
652 #pragma mark MassData Methods
663 if (_body !=
nullptr) {
664 return Vec2(_body->GetLocalCenter().x,_body->GetLocalCenter().y);
666 return Vec2(_massdata.center.x,_massdata.center.y);
688 if (_body !=
nullptr) {
689 _body->SetMassData(&_massdata);
702 return (_body !=
nullptr ? _body->GetInertia() : _massdata.I);
715 if (_body !=
nullptr) {
716 _body->SetMassData(&_massdata);
728 return (_body !=
nullptr ? _body->GetMass() : _massdata.mass);
740 if (_body !=
nullptr) {
741 _body->SetMassData(&_massdata);
750 if (_body !=
nullptr) {
751 _body->ResetMassData();
757 #pragma mark Physics Methods
765 virtual b2Body*
getBody()
const override {
return _body; }
814 virtual void update(
float delta)
override;
818 #pragma mark Render Snap
849 _posFact = (
unsigned long)(_posSnap >= 0 ? std::pow(10, snap) : 0);
884 _angFact = (
unsigned long)(_angSnap >= 0 ? std::pow(10, snap) : 0);
909 #pragma mark Initializers
910 CC_CONSTRUCTOR_ACCESS:
915 _posSnap = _angSnap = -1;
928 CCASSERT(_body ==
nullptr,
"You must deactive physics before deleting an object");
virtual void setInertia(float value)
Definition: CUObstacle.cpp:126
void setAngleSnap(unsigned int snap)
Definition: CUSimpleObstacle.h:882
virtual float getVY() const override
Definition: CUSimpleObstacle.h:269
virtual void setAngularDamping(float value) override
Definition: CUSimpleObstacle.h:576
virtual ~SimpleObstacle()
Definition: CUSimpleObstacle.h:927
virtual void setActive(bool value) override
Definition: CUSimpleObstacle.h:338
virtual void setBullet(bool value) override
Definition: CUSimpleObstacle.h:446
virtual void setFriction(float value)
Definition: CUObstacle.h:562
virtual void setCentroid(const Vec2 &value) override
Definition: CUSimpleObstacle.h:678
virtual void setAngularVelocity(float value) override
Definition: CUSimpleObstacle.h:306
void setPositionSnap(unsigned int snap)
Definition: CUSimpleObstacle.h:847
b2Body * _body
Definition: CUSimpleObstacle.h:43
virtual void setPosition(const Vec2 &value) override
Definition: CUSimpleObstacle.h:113
unsigned long _posFact
Definition: CUSimpleObstacle.h:48
virtual void setSleepingAllowed(bool value) override
Definition: CUSimpleObstacle.h:402
virtual bool isBullet() const override
Definition: CUSimpleObstacle.h:426
virtual void setFilterData(b2Filter value)
Definition: CUObstacle.h:638
virtual void setLinearVelocity(float x, float y) override
Definition: CUSimpleObstacle.h:230
virtual void setY(float value) override
Definition: CUSimpleObstacle.h:165
virtual void resetMass()
Definition: CUObstacle.h:713
virtual float getVX() const override
Definition: CUSimpleObstacle.h:243
virtual void setSensor(bool value)
Definition: CUObstacle.h:610
virtual void setLinearDamping(float value) override
Definition: CUSimpleObstacle.h:538
virtual float getY() const override
Definition: CUSimpleObstacle.h:156
virtual void setCentroid(const Vec2 &value)
Definition: CUObstacle.h:662
virtual void positionSceneNode()
Definition: CUObstacle.cpp:240
virtual void setVY(float value) override
Definition: CUSimpleObstacle.h:282
virtual void createFixtures()
Definition: CUSimpleObstacle.h:792
virtual float getAngularDamping() const override
Definition: CUSimpleObstacle.h:559
virtual b2Body * getBody() const override
Definition: CUSimpleObstacle.h:765
virtual float getGravityScale() const override
Definition: CUSimpleObstacle.h:488
virtual void setPosition(float x, float y) override
Definition: CUSimpleObstacle.h:121
virtual float getAngularVelocity() const override
Definition: CUSimpleObstacle.h:297
virtual bool isFixedRotation() const override
Definition: CUSimpleObstacle.h:461
virtual void releaseFixtures()
Definition: CUSimpleObstacle.h:799
virtual void setLinearVelocity(const Vec2 &value) override
Definition: CUSimpleObstacle.h:222
virtual void positionDebugNode()
Definition: CUObstacle.cpp:257
Definition: CUSimpleObstacle.h:36
virtual void setInertia(float value) override
Definition: CUSimpleObstacle.h:713
virtual bool isAwake() const override
Definition: CUSimpleObstacle.h:356
virtual void setFixedRotation(bool value) override
Definition: CUSimpleObstacle.h:472
virtual float getAngle() const override
Definition: CUSimpleObstacle.h:180
virtual void setX(float value) override
Definition: CUSimpleObstacle.h:143
virtual void setAngle(float value) override
Definition: CUSimpleObstacle.h:189
virtual b2BodyType getBodyType() const override
Definition: CUSimpleObstacle.h:67
virtual Vec2 getCentroid() const override
Definition: CUSimpleObstacle.h:662
virtual void deactivatePhysics(b2World &world)
Definition: CUObstacle.h:895
virtual bool activatePhysics(b2World &world)
Definition: CUObstacle.h:887
virtual void setVX(float value) override
Definition: CUSimpleObstacle.h:256
virtual void setDensity(float value)
Definition: CUObstacle.h:536
virtual void setMass(float value)
Definition: CUObstacle.cpp:142
virtual float getInertia() const override
Definition: CUSimpleObstacle.h:701
virtual bool isSleepingAllowed() const override
Definition: CUSimpleObstacle.h:388
int _angSnap
Definition: CUSimpleObstacle.h:50
virtual void setAwake(bool value) override
Definition: CUSimpleObstacle.h:370
virtual void setBodyType(b2BodyType value) override
Definition: CUSimpleObstacle.h:80
int _posSnap
Definition: CUSimpleObstacle.h:46
virtual Vec2 getPosition() const override
Definition: CUSimpleObstacle.h:97
Definition: CUObstacle.h:46
virtual void update(float delta)
Definition: CUObstacle.h:910
int getAngleSnap()
Definition: CUSimpleObstacle.h:866
virtual float getMass() const override
Definition: CUSimpleObstacle.h:727
unsigned long _angFact
Definition: CUSimpleObstacle.h:52
virtual bool isActive() const override
Definition: CUSimpleObstacle.h:324
virtual void setRestitution(float value)
Definition: CUObstacle.h:588
virtual void setMass(float value) override
Definition: CUSimpleObstacle.h:738
virtual float getLinearDamping() const override
Definition: CUSimpleObstacle.h:521
virtual void setGravityScale(float value) override
Definition: CUSimpleObstacle.h:500
virtual Vec2 getLinearVelocity() const override
Definition: CUSimpleObstacle.h:206
virtual void setCentroid(float x, float y) override
Definition: CUSimpleObstacle.h:686
virtual void resetMass() override
Definition: CUSimpleObstacle.h:748
virtual float getX() const override
Definition: CUSimpleObstacle.h:134
int getPositionSnap()
Definition: CUSimpleObstacle.h:832