bool NDUIButton::processDragEnd( const CCPoint& kPrePos,const CCPoint& kEndPos ) { if (!NDUINode::processDragEnd(kPrePos,kEndPos)) { return false; } m_bIsDragingNow = false; CCPoint kPoint = ccp(kEndPos.x - kPrePos.x,kEndPos.y - kPrePos.y); CCSize kSize = CCDirector::sharedDirector()->getWinSize(); CCPoint kVector = ccp(kSize.width,kSize.height); float fDragDistance = kVector.getDistance() * 0.08f; float fDistance = kPoint.getDistance(); float fAngle = 0.0f; if (fDistance < fDragDistance) { return false; } kPoint = ccpNormalize(kPoint); fAngle = ccpToAngle(kPoint); float fLeftUp = ccpToAngle(ccp(-1.0f,-1.0f)); float fRightUp = ccpToAngle(ccp(1.0f,-1.0f)); float fRightBottom = ccpToAngle(ccp(1.0f,1.0f)); float fLeftBottom = ccpToAngle(ccp(-1.0f,1.0f)); TARGET_EVENT eDirEvent = TE_NONE; if (fAngle >= fLeftUp && fAngle < fRightUp) { eDirEvent = TE_TOUCH_BTN_DRAG_UP; } else if (fAngle >= fRightUp && fAngle < fRightBottom) { eDirEvent = TE_TOUCH_BTN_DRAG_RIGHT; } else if (fAngle >= fRightBottom && fAngle < fLeftBottom) { eDirEvent = TE_TOUCH_BTN_DRAG_DOWN; } else { eDirEvent = TE_TOUCH_BTN_DRAG_LEFT; } OnScriptUiEvent( eDirEvent ); OnScriptUiEvent(TE_TOUCH_BTN_END); }
void CGridView::onDraggingScrollEnded() { if( m_uCellsCount == 0 ) return; if( m_bAutoRelocate ) { CCPoint tOffset = getContentOffset(); unsigned int uRow = cellBeginRowFromOffset(tOffset); CCPoint tAPoint = cellPositionFromIndex(cellFirstIndexFromRow(uRow)); CCPoint tBPoint = CCPoint(0, tAPoint.y - m_tCellsSize.height); CCPoint tContentPoint = CCPoint(0, m_obContentSize.height); tOffset = tOffset - tContentPoint; tAPoint.x = 0; float fADistance = tOffset.getDistance(-tAPoint); float fBDistance = tOffset.getDistance(-tBPoint); if( fADistance < fBDistance ) { float fDuration = fabs(fADistance) / CGRIDVIEW_AUTO_RELOCATE_SPPED; setContentOffsetInDuration(-tAPoint + tContentPoint, fDuration); } else { float fDuration = fabs(fBDistance) / CGRIDVIEW_AUTO_RELOCATE_SPPED; setContentOffsetInDuration(-tBPoint + tContentPoint, fDuration); } } }
void SpellDiagramNode::ccTouchesEnded(CCSet* touches, CCEvent* event) { float slotRadius = 25.0f; for(CCSetIterator it = touches->begin(); it != touches->end(); it++) { CCTouch* touch = dynamic_cast<CCTouch*>(*it); if(touch == NULL) break; if( m_slotEquipMenu == NULL ) { CCPoint p = touch->getLocation(); p.x -= getPositionX(); p.y -= getPositionY(); for(int i=0; i< m_effectSlots.size(); i++) { CCPoint sp = m_effectSlots[i]->getPosition(); if( p.getDistance(sp) <= slotRadius ) { CCLog("touched effect %d", i); m_slotEquipMenu = RadialLayer::create(); createEffSlotMenu(m_slotEquipMenu, sp, i); return; } } for(int i=0; i< m_modSlots.size(); i++) { CCPoint sp = m_modSlots[i]->getPosition(); if( p.getDistance(sp) <= slotRadius ) { CCLog("touched mod %d", i); m_slotEquipMenu = RadialLayer::create(); createModSlotMenu(m_slotEquipMenu, sp, i); return; } } } } }
void GameWorld::GenerateLightningPointsList( CCPoint start, CCPoint end, int segment ) { std::vector<float> positions; CCPoint tangent = ccp( end.x - start.x, end.y - start.y ); CCPoint normal = ccpNormalize( ccp( tangent.y, -tangent.x ) ); float length = start.getDistance( end ); float prevDisplacement = 0; float sway = 320; float jag = 1/sway; int segments = 8;//length/80; for( int i = 0; i < segments; i++ ) { positions.push_back( float( arc4random() % 100 ) / 100.0 ); } std::sort (positions.begin(), positions.end() ); /** CCLOG("Start -----------------------------"); for( int i = 0; i < positions.size(); i++ ) { CCLOG("%d: %f ", i, positions[i]); } CCLOG("End -------------------------------"); /**/ CCPoint prevPoint = start; for( int i = 1; i < segments; i++ ) { float scale = ( length * jag ) * ( positions[i] - positions[i-1] ); float envelope = positions[i] > 0.95f ? 20 * (1 - (positions[i])) : 1; float displacement = ( arc4random() % int(sway) ) - (sway/2); displacement -= (displacement - prevDisplacement) * (1 - scale); displacement *= envelope; CCPoint nextPoint = ccp ( start.x + positions[i] * tangent.x + displacement * normal.x, start.y + positions[i] * tangent.y + displacement * normal.y ); m_LightningPoints->push_back( new LightningLine( prevPoint, nextPoint, segment ) ); prevPoint = nextPoint; prevDisplacement = displacement; } m_LightningPoints->push_back( new LightningLine( prevPoint, end, segment ) ); }
void GameWorld::DrawLightningLine( CCPoint start, CCPoint end, float thickness ) { const float ImageThickness = 40; float thicknessScale = thickness / ImageThickness; CCPoint tangent = ccp( end.x - start.x, end.y - start.y ); float rotation = float( atan2( tangent.y, tangent.x ) ); float trueRotationRad = -rotation * (180 / 3.14 ); CCSprite* pSegment = CCSprite::createWithTexture( m_pLightningSegmentBatch->getTexture() ); float lengthScale = start.getDistance( end ); pSegment->setPosition( start ); pSegment->setScaleX( lengthScale ); pSegment->setScaleY( thicknessScale ); pSegment->setRotation( trueRotationRad ); pSegment->setPosition( ccp( start.x + tangent.x/2, start.y + tangent.y/2 ) ); m_pLightningSegmentBatch->addChild(pSegment, 0); CCSprite* pStart = CCSprite::createWithTexture( m_pLightningEndBatch->getTexture() ); CCSprite* pEnd = CCSprite::createWithTexture( m_pLightningEndBatch->getTexture() ); pStart->setPosition( start ); pStart->setScaleX( thicknessScale ); pStart->setScaleY( thicknessScale ); pStart->setRotation( trueRotationRad ); m_pLightningEndBatch->addChild( pStart, 0 ); pEnd->setPosition( end ); pEnd->setScaleX( thicknessScale ); pEnd->setScaleY( thicknessScale ); pEnd->setRotation( trueRotationRad + 3.14 ); m_pLightningEndBatch->addChild( pEnd, 0 ); }
void StageMapLayer::MoveMyPlayerToSelectedIndex(float deltaTime) { const int StageMapPlayerActionTag = 37; const float speed = 100.f; // pixel per sec INT currentDestinationIndex = m_CurrentMyPlayerStageMapPointIndex+1; if( m_CurrentMyPlayerStageMapPointIndex < m_SelectedStageMapPointIndex ) { currentDestinationIndex = m_CurrentMyPlayerStageMapPointIndex+1; } else if( m_CurrentMyPlayerStageMapPointIndex > m_SelectedStageMapPointIndex) { currentDestinationIndex = m_CurrentMyPlayerStageMapPointIndex-1; } else { ASSERT_DEBUG( m_CurrentMyPlayerStageMapPointIndex == m_SelectedStageMapPointIndex); currentDestinationIndex = m_SelectedStageMapPointIndex; } if( currentDestinationIndex<=0 ) { currentDestinationIndex = 0; } else if( currentDestinationIndex >= m_StageMapPointList.size() ) { currentDestinationIndex = m_SelectedStageMapPointIndex = m_StageMapPointList.size()-1; } StageMapPoint* destinationStageMapPoint = m_StageMapPointList[currentDestinationIndex]; const CCPoint destination = destinationStageMapPoint->getPosition()+m_PlayerPositionOffset; if( m_CurrentMyPlayerStageMapPointIndex != m_SelectedStageMapPointIndex ) { StageMapPoint* currentStageMapPoint = m_StageMapPointList[m_CurrentMyPlayerStageMapPointIndex]; if( destinationStageMapPoint->getPositionX() - currentStageMapPoint->getPositionX() < 0 ) { if( m_MyPlayer->IsFlipX() == true ) { m_MyPlayer->FlipX(false); } } else if( destinationStageMapPoint->getPositionX() - currentStageMapPoint->getPositionX() > 0 ) { if( m_MyPlayer->IsFlipX() == false ) { m_MyPlayer->FlipX(true); } } } if( destination.getDistance(m_MyPlayer->getPosition()) >= speed*0.06f ) { m_MyPlayer->setPosition( m_MyPlayer->getPosition() + (destination-m_MyPlayer->getPosition()).normalize() * speed * deltaTime ); const float duration = destination.getDistance(m_MyPlayer->getPosition())/speed; CCMoveTo* moveAction = CCMoveTo::create(duration, destination); moveAction->setTag(StageMapPlayerActionTag); m_MyPlayer->stopActionByTag(StageMapPlayerActionTag); m_MyPlayer->runAction( moveAction ); } else { m_CurrentMyPlayerStageMapPointIndex = currentDestinationIndex; m_MyPlayer->setZOrder(destinationStageMapPoint->getZOrder()); if( m_CurrentMyPlayerStageMapPointIndex != m_SelectedStageMapPointIndex ) { this->MoveMyPlayerToSelectedIndex(deltaTime); } else { m_MyPlayer->stopActionByTag(ActionType_Animation); m_MyPlayer->AnimateIdle(); } } }