Example #1
0
void LevelScene::onTouchMoved(Touch* touch, Event* event) {
    Point point = this->convertTouchToNodeSpace(touch);
    
    Point vectorMove = Point::ZERO;
    if (!this->isMoved) {
        vectorMove = point - this->firstPoint;
    } else {
        vectorMove = point - this->movePoint;
    }
    this->updateLevelLayer(vectorMove);
    this->movePoint = point;
    this->isMoved = true;
    
    // update flash
    {
        Point point = this->convertTouchToNodeSpace(touch);
        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());
            }
        }
    }
}
Example #2
0
void ChapterScene::onTouchMoved(Touch* touch, Event* event) {
    Point point = this->convertTouchToNodeSpace(touch);

    Point vectorMove = Point::ZERO;
    if (!this->isMoved) {
        vectorMove = point - this->firstPoint;
    } else {
        vectorMove = point - this->movePoint;
    }
    this->updateChapterLayer(vectorMove);
    this->movePoint = point;
    this->isMoved = true;
    
    // update flash
    {
        Point point = this->convertTouchToNodeSpace(touch);
        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) {
                this->flashOff(chapterFace);
                RectBody* chapterBody = new RectBody(chapterFace->getContentSize().width, chapterFace->getContentSize().height);
                chapterBody->setPosition(chapterFace->getPosition());
                
                if (chapterBody->contains(point)) {
                    this->flashOn(chapterFace);
                }
            }
        }
    }
}
Example #3
0
void Level::checkTouchLeaf(Point point) {
    if (this->hanged || this->done) {
        return;
    }
    
    if (this->frog->getJumping()) {
        return;
    }
    
    __Array* allLeavesKey = this->getLeaves()->allKeys();
    for (int i = 0; i < allLeavesKey->count(); i++) {
        __Integer* key = (__Integer*) allLeavesKey->getObjectAtIndex(i);
        Leaf* leaf = (Leaf*) this->getLeaves()->objectForKey(key->getValue());
        if (leaf->getDrowning()) {
            continue;
        }
        
        RectBody* leafBody = (RectBody*) leaf->getBody();
        if (CPointUtil::isPointInRectangle(point, leaf->getPosition(), leafBody->getWidth(), leafBody->getHeight())) {
            ViewDirection willingDirection = this->checkJumpable(leaf);
            if (willingDirection != VIEW_NONE) {
                this->frog->setViewDirection(willingDirection);
                this->frogJump(leaf);
            }
            break;
        }
    }
}
Example #4
0
void Leaf::initBody() {
    CSprite* leafSprite = new CSprite(SPRITE_TYPE_MAIN);
    leafSprite->initWithIdentifier(FRAME_LEAF_IDLE);
    leafSprite->bind(CStringUtil::getPattern(FRAME_LEAF_IDLE));

    ActionInterval* drownAction = (ActionInterval*) leafSprite->getAction(FRAME_LEAF_FALL, false);
    this->drownDuration = drownAction->getDuration();
    this->getSprites()->pushBack(leafSprite);

    RectBody* rectBody = new RectBody(leafSprite->getContentSize().width, leafSprite->getContentSize().height);
    rectBody->setAnchorPoint(Point(0.5, 0.5));
    CC_SAFE_RETAIN(rectBody);
    this->body = rectBody;
}
Example #5
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;
            }
        }
    }
}
Example #6
0
bool LevelScene::onTouchBegan(Touch* touch, Event* event) {
    Point point = this->convertTouchToNodeSpace(touch);
    
    this->isMoved = false;
    this->isTouched = false;
    RectBody* chapterLayerBody = new RectBody(this->levelLayer->getContentSize().width, this->levelLayer->getContentSize().height);
    chapterLayerBody->setPosition(this->levelLayer->getPosition() + Point(chapterLayerBody->getWidth() / 2, chapterLayerBody->getHeight() / 2));
    
    if (chapterLayerBody->contains(point)) {
        this->isTouched = true;
        this->firstPoint = point;
        
        // update flash
        {
            Point point = this->convertTouchToNodeSpace(touch);
            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());
                }
            }
        }
        return true;
    }
    return false;
}
Example #7
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;
            }
        }
    }
}
Example #8
0
bool ChapterScene::onTouchBegan(Touch* touch, Event* event) {
    if (this->shareLayer->isVisible() ||
        this->chapterMoving) {
        return false;
    }
    Point point = this->convertTouchToNodeSpace(touch);
    
    this->isMoved = false;
    this->isTouched = false;
    RectBody* chapterLayerBody = new RectBody(this->chapterLayer->getContentSize().width, this->chapterLayer->getContentSize().height);
    chapterLayerBody->setPosition(this->chapterLayer->getPosition() + Point(chapterLayerBody->getWidth() / 2, chapterLayerBody->getHeight() / 2));
    
    if (chapterLayerBody->contains(point)) {
        this->isTouched = true;
        this->firstPoint = point;
        
        // update flash
        {
            Point point = this->convertTouchToNodeSpace(touch);
            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) {
                    this->flashOff(chapterFace);
                    RectBody* chapterBody = new RectBody(chapterFace->getContentSize().width, chapterFace->getContentSize().height);
                    chapterBody->setPosition(chapterFace->getPosition());
                    
                    if (chapterBody->contains(point)) {
                        this->flashOn(chapterFace);
                    }
                }
            }
        }
        return true;
    }
    return false;
}