示例#1
0
void ChapterScene::onTouchEnded(Touch* touch, Event* event) {
    GameModel* gameModel = GameModel::getInstance();
    this->updatePageAuto();
    
    Point point = this->convertTouchToNodeSpace(touch);
    bool moveTooFar = false;
    float dx = point.x - this->firstPoint.x;
    float dy = point.y - this->firstPoint.y;
    if (abs(dx) > CONF_TOUCH_RANGE || abs(dy) > CONF_TOUCH_RANGE) {
        moveTooFar = true;
    }
    point = point - this->chapterLayer->getPosition();
    
    for (int i = 0; i < this->chapterLayer->getChildren().size(); i++) {
        Face* chapterFace = dynamic_cast<Face*>(this->chapterLayer->getChildren().at(i));
        if (chapterFace != NULL) {
            RectBody* chapterBody = new RectBody(chapterFace->getContentSize().width, chapterFace->getContentSize().height);
            chapterBody->setPosition(chapterFace->getPosition());
            
            if (chapterBody->contains(point)) {
                if (!moveTooFar && chapterFace->getTag() != -1) {
                    if (!gameModel->checkLevelRequireSocial(i + 1)) {
                        this->shareLayer->show(TXT_REQUIRE_SHARE);
                        GameEvent* gameEvent = new GameEvent();
                        gameEvent->setEventCode(EVT_SHOW_SHARE_REQUIRED);
                        this->fireEvent(gameEvent);
                    } else {
                        DataEvent* gameEvent = new DataEvent();
                        gameEvent->setEventCode(EVT_START_PLAY);
                        gameEvent->setArgumentInt(chapterFace->getTag());
                        this->fireEvent(gameEvent);
                        
                        this->_eventDispatcher->removeEventListener(this->touchListener);
                    }
                }
                this->flash(chapterFace);
                break;
            }
        }
    }
}
示例#2
0
void LevelScene::onTouchEnded(Touch* touch, Event* event) {
    if (this->dialogLayer->isVisible()) {
        return;
    }
    
    this->updatePageAuto();
    
    Point point = this->convertTouchToNodeSpace(touch);
    bool moveTooFar = false;
    float dx = point.x - this->firstPoint.x;
    float dy = point.y - this->firstPoint.y;
    if (abs(dx) > CONF_TOUCH_RANGE || abs(dy) > CONF_TOUCH_RANGE) {
        moveTooFar = true;
    }
    point = point - this->levelLayer->getPosition();
    
    for (int i = 0; i < this->levelLayer->getChildren().size(); i++) {
        CSprite* levelFace = dynamic_cast<CSprite*>(this->levelLayer->getChildren().at(i));
        if (levelFace != NULL) {
            RectBody* levelBody = new RectBody(levelFace->getContentSize().width, levelFace->getContentSize().height);
            levelBody->setPosition(levelFace->getPosition());
            
            if (levelBody->contains(point)) {
                if (!moveTooFar && levelFace->getTag() != -1) {
                    DataEvent* gameEvent = new DataEvent();
                    gameEvent->setEventCode(EVT_START_LEVEL);
                    gameEvent->setArgumentInt(levelFace->getTag());
                    this->fireEvent(gameEvent);
                    
                    this->_eventDispatcher->removeEventListener(this->touchListener);
                }
                break;
            }
        }
    }
}