Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CMPartAidansCooler.h"
- #include "contraptions/managers/CMLevelManager.h"
- #include "cmcocos/util/CCOldTypes.h"
- NS_CC_BEGIN
- CMPartAidansCooler::CMPartAidansCooler(int id, CMLevel *level, int type, TmPointInt32 pos, int partProcessFlags, int partActionFlags, int state, int rot)
- : CMPartContainer(id,level,type,pos,partProcessFlags,partActionFlags,state,rot)
- {
- }
- void CMPartAidansCooler::onCreation(bool fromLoad)
- {
- mHandleBody = getBodyById(1);
- mWheelBody = getBodyById(2);
- mWheelCpBody = mWheelBody->mCpBody;
- mHandleCpBody = mHandleBody->mCpBody;
- mNormalCoolerSprite = static_cast<CMPartArtSpriteRect*>(getArtById(0))->mSprite;
- mFlippedCoolerSprite = static_cast<CMPartArtSpriteRect*>(getArtById(1))->mSprite;
- mNormalCoolerSprite->setVisible(!mFlippedX);
- mFlippedCoolerSprite->setVisible(mFlippedX);
- if (mFlippedX)
- mLevel->addArtToList(getArtById(1));
- else
- mLevel->addArtToList(getArtById(0));
- CMPart::onCreation(fromLoad);
- }
- void CMPartAidansCooler::postPhysicsUpdate(int time, int levelFrame)
- {
- // Keep wheel from rotating forever
- if (mWheelCpBody->w != 0)
- {
- if (mWheelCpBody->w > -INT32_HALF && mWheelCpBody->w < INT32_HALF)
- mWheelCpBody->w = 0;
- else
- mWheelCpBody->w = INT64_SHIFT_DOWN(mWheelCpBody->w * FLOAT_TO_INT64(0.98f));
- }
- // Give handle pivot a little friction too
- if (mHandleCpBody->w != 0)
- {
- if (mHandleCpBody->w > -(INT32_HALF>>2) && mHandleCpBody->w < (INT32_HALF>>2))
- mHandleCpBody->w = 0;
- else
- mHandleCpBody->w = INT64_SHIFT_DOWN(mHandleCpBody->w * FLOAT_TO_INT64(0.96f));
- }
- CMPart::postPhysicsUpdate(time,levelFrame);
- }
- void CMPartAidansCooler::flip()
- {
- for (int i=0;i<6;i++)
- getShapeById(i)->flip();
- mHandleBody->flipX();
- mWheelBody->flipX();
- cpPivotJoint *pivot = (cpPivotJoint*) getConstraintById(0)->mCpConstraint;
- pivot->anchr1.x = -pivot->anchr1.x;
- pivot->anchr2.x = -pivot->anchr2.x;
- pivot = (cpPivotJoint*) getConstraintById(1)->mCpConstraint;
- pivot->anchr1.x = -pivot->anchr1.x;
- pivot->anchr2.x = -pivot->anchr2.x;
- cpRotaryLimitJoint *limitJoint = (cpRotaryLimitJoint*) getConstraintById(2)->mCpConstraint;
- int temp = limitJoint->max;
- limitJoint->max = -limitJoint->min;
- limitJoint->min = -temp;
- mFlippedX = !mFlippedX;
- mInitFlippedX = mFlippedX;
- mScaleX = -mScaleX;
- mNormalCoolerSprite->setVisible(!mFlippedX);
- mFlippedCoolerSprite->setVisible(mFlippedX);
- if (mFlippedX)
- {
- mLevel->removeArtFromList(getArtById(0));
- mLevel->addArtToList(getArtById(1));
- }
- else
- {
- mLevel->removeArtFromList(getArtById(1));
- mLevel->addArtToList(getArtById(0));
- }
- updatePosAndRot();
- }
- NS_CC_END
Add Comment
Please, Sign In to add comment