Ejemplo n.º 1
0
void ChapterScene::updatePageAuto() {
    GameModel* gameModel = GameModel::getInstance();
    int chapterSize = gameModel->getMapData()->getLevelSize();
    float distance = this->chapterLayerOffset.x - this->chapterLayer->getPosition().x;
    float result = distance / (this->chapterLayer->getContentSize().width / chapterSize);
    int page = floor(result);
    float redundant = result - page;
    if (redundant > 0.5f) {
        page++;
    }
    page++;
    if (page < 1) {
        page = 1;
    } else if (page > chapterSize) {
        page = chapterSize;
    }
    this->updatePage(page);
}
Ejemplo n.º 2
0
void ChapterScene::createLayersContent() {
    GameModel* gameModel = GameModel::getInstance();
    Size displayResolutionSize = gameModel->getDisplayResolutionSize();
    
    Face* backgroundFace = new Face();
    backgroundFace->initWithFile(ANI_BACKGROUND);
    backgroundFace->setScale(CONF_FAKE_1);
    backgroundFace->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height / 2);
    this->backgroundLayer->addChild(backgroundFace);
    
    Face* chapterTitle = new Face();
    chapterTitle->initWithSpriteFrameName(ANI_CHAPTER_TITLE);
    chapterTitle->setPosition(displayResolutionSize.width / 2, displayResolutionSize.height - chapterTitle->getContentSize().height / 2 - 20);
    this->mainLayer->addChild(chapterTitle);
    
    UGMenu* mainMenu = UGMenu::create();
    mainMenu->setPosition(Point::ZERO);
    this->mainLayer->addChild(mainMenu);
    
    MenuItemSprite* backButton = Utils::createButton((char*) TXT_BACK, 16, ANI_BUTTON, ANI_BUTTON);
    backButton->setCallback(CC_CALLBACK_1(ChapterScene::backButtonClick, this));
    backButton->setPosition(gameModel->getDisplayResolutionSize().width / 2, 20 + backButton->getContentSize().height / 2);
    mainMenu->addChild(backButton);
    this->nodes->setObject(backButton, NODE_BUTTON_BACK);
    
    // create chapters
    this->chapterLayer = UGLayerColor::create();
    float totalChapterSize = gameModel->getMapData()->getLevelSize();
    float distancePerChapter = CONF_DISTANCE_PER_CHAPTER;
    float totalChapterWidth = (totalChapterSize - 1) * distancePerChapter;
    
    Face* chapterTemp = new Face();
    chapterTemp->initWithSpriteFrameName(ANI_BOX_CHAPTER);
    this->chapterTempSize = chapterTemp->getContentSize();
    
    this->chapterLayer->setContentSize(Size(totalChapterWidth + this->chapterTempSize.width, displayResolutionSize.height / 2));
    this->chapterLayer->setPosition(displayResolutionSize.width / 2 - this->chapterTempSize.width / 2, displayResolutionSize.height / 2 - this->chapterLayer->getContentSize().height / 2);
    this->chapterLayerOffset = this->chapterLayer->getPosition();
    this->mainLayer->addChild(this->chapterLayer);
    
    float posX = this->chapterTempSize.width / 2;
    float posY = this->chapterLayer->getContentSize().height / 2;
    for (int i = 0; i < totalChapterSize; i++) {
        Face* levelBox = new Face();
        if (!gameModel->checkLevelLock(i + 1)) {
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER);
            levelBox->setTag(i + 1);
            {
                int chapter = gameModel->getMapData()->getChapter(i + 1);
                int chapterLevel = gameModel->getMapData()->getChapterLevel(i + 1);
                char mapPath[200];
                sprintf(mapPath, DOC_BG_MAP, chapter, chapterLevel);
                
                SpriteFrameCache* sfc = SpriteFrameCache::getInstance();
                sfc->addSpriteFramesWithFile(mapPath);
                char bg1Path[200];
                sprintf(bg1Path, ANI_MAP, chapter, chapterLevel, 1);

                Face* chapterThumb = new Face();
                chapterThumb->initWithSpriteFrameName(bg1Path);
                chapterThumb->setPosition(levelBox->getContentSize().width / 2, levelBox->getContentSize().height / 2 - 10);
                chapterThumb->setTextureRect(Rect(0, 0, 160, 115));
                levelBox->addChild(chapterThumb);
                
                string levelName = gameModel->getMapData()->getLevelName(i + 1);
                char levelNameChar[200];
                sprintf(levelNameChar, "%s", levelName.data());
                Label* levelNameLabel = Label::createWithBMFont(FONT_GAME_SMALL, levelNameChar);
                levelNameLabel->setPosition(chapterThumb->getPosition() + Point(0, chapterThumb->getContentSize().height / 2 + 12));
                levelBox->addChild(levelNameLabel);
            }
        } else {
            levelBox->setTag(-1);
            levelBox->initWithSpriteFrameName(ANI_BOX_CHAPTER_LOCK);
        }
        
        levelBox->setPosition(posX, posY);
        posX = posX + distancePerChapter;
        this->chapterLayer->addChild(levelBox);
    }
    
    // add parent button for share layer
    this->shareLayer->getParentButtons()->pushBack((MenuItemSprite*) this->nodes->objectForKey(NODE_BUTTON_BACK));
}