void TestController::ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent)
{
    CCAction* delaytime = CCActionManager::sharedManager()->getActionByTag(99,this);
    if(delaytime != NULL)
        if(delaytime->isDone() == false)
        {
            CCSetIterator it = pTouches->begin();
            CCTouch* touch = (CCTouch*)(*it);
            CCPoint p1 =	m_tBeginPos;
            CCPoint p2 =	touch->locationInView(touch->view());
            float x = m_pItmeMenu->getPosition().x + (p2.x - p1.x) * 5;
            if(x>= 0)
                x = 0;
            else if(x <= -m_pItmeMenu->getContentSize().width)
                x = -m_pItmeMenu->getContentSize().width;
            CCMoveTo* move = CCMoveTo::actionWithDuration(1,CCPointMake(x,0));
            CCActionInterval* ease = CCEaseOut::actionWithAction(move,3.0);
            m_pItmeMenu->runAction(ease);
        }
}
Exemplo n.º 2
0
void GameScene::update(float delta)
{
    bool oldCrashed = m_Crashed;
    if (m_Started && !m_Paused)
    {
        if (!m_Crashed)
        {
            float deltaX = m_fForwordVelocity * delta;

            // move background
            m_pBackground1->setPositionX(m_pBackground1->getPositionX() + deltaX);
            m_pBackground2->setPositionX(m_pBackground1->getPositionX() + m_pBackground1->getContentSize().width);

            if (m_pBackground1->getPositionX() + m_pBackground1->getContentSize().width / 2 <= m_VisibleOrigin.x)
            {
                CCSprite *pTemp = m_pBackground1;
                m_pBackground1 = m_pBackground2;
                m_pBackground2 = pTemp;

                m_pBackground2->setPositionX(m_pBackground1->getPositionX() + m_pBackground1->getContentSize().width);
            }

            // move pillars
            for (int i = 0; i < 4; i++)
            {
                if (m_Pillars[i] != NULL)
                {
                    m_Pillars[i]->setPositionX(m_Pillars[i]->getPositionX() + deltaX);
                    float w = m_pPig->getContentSize().width * m_pPig->getScaleX(), h = m_pPig->getContentSize().height * m_pPig->getScaleY();
                    CCRect pigRect = CCRectMake(m_pPig->getPositionX() - w / 2, m_pPig->getPositionY() - h / 2, w, h);
                    if (m_Pillars[i]->boundingBox().intersectsRect(pigRect))
                    {
                        m_Crashed = true;
                        //m_Pillars[i]->setPositionX(m_pPig->getPositionX() + m_pPig->getContentSize().width * m_pPig->getScale() / 2 + 44);
                    }
                }
            }
        }

        // fall & rotate pig
        CCAction *pAction = m_pPig->getActionByTag(kTagRaise);
        if (!pAction || pAction->isDone())
        {
            m_fFallVelocity += -1400 * delta;
            m_fFallVelocity = MAX(m_fFallVelocity, m_fMaxVelocity);
            float posY = m_pPig->getPositionY() +m_fFallVelocity * delta;
            if (posY <= m_VisibleOrigin.y + m_GroundPosY + m_pPig->getContentSize().height / 2)
            {
                posY = m_VisibleOrigin.y + m_GroundPosY + m_pPig->getContentSize().height / 2;
                m_Crashed = true;
            }

            m_pPig->setPositionY(posY);
            float orgRotation = m_pPig->getRotation();
            float rotation = 0;
            if (orgRotation < -24)
            {
                rotation = orgRotation + delta * 10;
            }
            else if (orgRotation < -22)
            {
                rotation = orgRotation + delta * 30;
            }
            else if (orgRotation < -16)
            {
                rotation = orgRotation + delta * 60;
            }
            else
            {
                rotation = orgRotation + delta * 500;
            }

            rotation = MIN(rotation, 80);
            m_pPig->setRotation(rotation);
        }

        if (m_Crashed)
        {
            if (!oldCrashed)
            {
                m_pPig->stopAllActions();

                GameManager *gameManager = GameManager::getInstance();
                gameManager->addGoalToday();
                if (gameManager->getGoalsToday() >= 2 && m_CurrentScore >= 5 && gameManager->getRated() == false && gameManager->getLaterTS() != Util::getCurrentDays())
                {
                    showRateView();
                }
                else
                {
                    showOverView();
                }

                if (m_Sound)
                {
                    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(SFX_HIT);
                    scheduleOnce(schedule_selector(GameScene::playDieEffect), 0.5f);
                }
            }
        }
        else
        {
            if (m_pPig && m_Pillars[0] && m_pPig->getPositionX() > m_Pillars[0]->getPositionX() && m_LastPassedPillar != m_Pillars[0])
            {
                m_CurrentScore++;
                m_LastPassedPillar = m_Pillars[0];

                m_ScoreLabel->setString(CCString::createWithFormat("%d", m_CurrentScore)->getCString());
                if (m_Sound)
                {
                    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(SFX_POINT);
                }
            }
        }
    }
}