예제 #1
0
파일: Level.cpp 프로젝트: chung1991/mf2507
void Level::updateLeaves(float dt) {
    GameModel* gameModel = GameModel::getInstance();
    for (auto iter = this->drowningLeaves->begin(); iter != this->drowningLeaves->end(); iter++) {
        Leaf* drowningLeaf = (Leaf*) *iter;
        if (drowningLeaf->getDrowning()) {
            if (drowningLeaf->getCurrentDrownDuration() != -1) {
                drowningLeaf->setCurrentDrownDuration(drowningLeaf->getCurrentDrownDuration() - dt);
                if (drowningLeaf->getCurrentDrownDuration() < 0) {
                    drowningLeaf->setCurrentDrownDuration(-1);
                    
                    DataEvent* dataEvent = new DataEvent();
                    dataEvent->setEventCode(EVT_LEAF_DROWN);
                    dataEvent->setArgumentReference(drowningLeaf);
                    gameModel->fireEvent(dataEvent);
                    
                    this->leaves->removeObjectForKey(drowningLeaf->getPositionIndex());
                    this->drowningLeaves->eraseObject(drowningLeaf);
                    
                    if (this->leaves->count() == 1) {
                        this->done = true;
                    }
                    break;
                }
            }
            drowningLeaf->play(SPRITE_TYPE_MAIN, FRAME_LEAF_FALL);
        }
    }
}
예제 #2
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;
            }
        }
    }
}
예제 #3
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;
            }
        }
    }
}