KDvoid CScrGame::ccTouchMoved ( CCTouch* pTouch, CCEvent* pEvent ) { CCPoint tLocation = pTouch->getLocation ( ); CCPoint tPrev = pTouch->getPreviousLocation ( ); CCPoint tDiff; if ( m_bTargetCtl ) { tDiff = ccpSub ( tLocation, tPrev ); for ( KDuint i = 0; i < 2; i++ ) { if ( m_uiPad[i][1]->getUserData ( ) == pTouch ) { const CCSize& tWinSize = CCDirector::sharedDirector ( )->getWinSize ( ); CCPoint tPoint = m_uiPad[i][2]->getPosition ( ); CCPoint tMove = ccpAdd ( tPoint, tDiff ); tMove = ccpClamp ( tMove, ccpSub ( m_uiPad[i][1]->getPosition ( ), ccpMid ( m_uiPad[i][2]->getContentSize ( ) ) ), ccpAdd ( m_uiPad[i][1]->getPosition ( ), ccpMid ( m_uiPad[i][2]->getContentSize ( ) ) ) ); m_uiPad[i][2]->setPosition ( tMove ); //tMove = ccpAdd ( ccp ( tWinSize.cx / 2 + ( i == 0 ? -30 : 30 ), tWinSize.cy / 2 ), // ccpMult ( ccpSub ( tPoint, tMove ), 1.5f ) ); tMove = ccpSub ( m_uiPad[i][2]->getPosition ( ), tPoint ); tPoint = ccp ( tWinSize.cx / 2 + ( i == 0 ? -60 : 60 ), tWinSize.cy / 2 ); tMove = ccpClamp ( ccpAdd ( ccpMult ( tMove, 2.0f ) , m_uiTarget[i][0]->getPosition ( ) ), ccpSub ( tPoint, ( m_uiPad[i][1]->getContentSize ( ) ) ), ccpAdd ( tPoint, ( m_uiPad[i][1]->getContentSize ( ) ) ) ); m_uiTarget[i][0]->setPosition ( tMove ); } } } if ( m_tWorldTouch.getID ( ) == pTouch->getID ( ) ) { tDiff = ccpSub ( tLocation, m_tWorldTouch.getLocation ( ) ); m_tWorldDelta.Y = kdFabsf ( tDiff.x ) > 10 ? tDiff.x * 0.2f : 0; m_tWorldDelta.X = kdFabsf ( tDiff.y ) > 20 ? tDiff.y * -0.2f : 0; } }
void GameLayer::processEvent(CCTouch *pTouch, CCEvent *pEvent) { if (this->_state == STATE_PLAY) { CCPoint delta = pTouch->getDelta(); CCPoint curPos = this->ship->getPosition(); curPos = ccpAdd(curPos, delta); curPos = ccpClamp(curPos, CCPointZero, ccp(winSize.width, winSize.height)); this->ship->setPosition(curPos); } }
void DaFeiJi::ccTouchesMoved(CCSet * touches, CCEvent *event) { if( _state == GAME_STATE::PLAY ) { CCSetIterator it = touches->begin(); CCTouch* touch = (CCTouch*)(*it); CCPoint start = touch->getLocation(); CCPoint delta = touch->getDelta(); CCPoint curPos = _ship->getPosition(); curPos= ccpAdd( curPos, delta ); curPos = ccpClamp(curPos, CCPoint(), CCPoint(_winSize.width, _winSize.height) ); _ship->setPosition( curPos ); } }
void Enemy::updateMovement(float dt) { //Point jumpForce = ccp(0.0f,600.0f); //Point getHitForce = ccp(0.0f, 310.0f); //float jumCutOff = 2000.0f; //Point forwardMove = ccp(4000.0f, 0.0f); Point gravity = ccp(0.0f, -950.0f); //if(_onGround && _stateJump) // _vVelocity = ccpAdd(_vVelocity, jumpForce); //else if(_stateJump && _vVelocity.y > jumCutOff) // _vVelocity.y = jumCutOff; //if(_stateHitAbove) //{ // _vVelocity = ccpSub(_vVelocity,getHitForce); // _stateHitAbove = false; //} //forwardMove.x = forwardMove.x*_vDirection.x; //Point forwardStep = ccpMult(forwardMove,dt); Point gravityStep = ccpMult(gravity,dt); ////if(_onGround) //gravityStep = gravityStep*0.01f; _vVelocity = ccpAdd(_vVelocity, gravityStep); //_vVelocity = ccp(_vVelocity.x*0.9f,_vVelocity.y); //if(_stateRun) // _vVelocity = ccpAdd(_vVelocity, forwardStep); const Point constVelocity = ccp(-50.0f,0.0f); if(_onGround) _vVelocity = ccpAdd(_vVelocity, constVelocity); Point minMovement = ccp(-50.0f, -150.0f); Point maxMovement = ccp(50.0f, 200.0f); //CCLOG(" velocity %f", _vVelocity.x); _vVelocity = ccpClamp(_vVelocity,minMovement,maxMovement); //CCLOG(" velocity %f", _vVelocity.x); //CCLOG(" stateRUn %d", _stateRun); CCPoint stepVelocity = ccpMult(_vVelocity,dt); _pDesiredPosition = ccpAdd(getPosition(),stepVelocity); //setPosition(_pDesiredPosition); }
void CCProgressTimer::setMidpoint(CCPoint midPoint) { m_tMidpoint = ccpClamp(midPoint, CCPoint::zero, ccp(1,1)); }