Esempio n. 1
0
    void Director::runWithScene(Scene *scene)
    {
        FZ_ASSERT( scene != NULL, "Scene must be non-NULL");
        FZ_ASSERT( p_runningScene == NULL, "You can't run an scene if another Scene is running. Use replaceScene or pushScene instead");

        pushScene(scene);
    }
Esempio n. 2
0
void CCDirector::runWithScene(CCScene *pScene)
{
	CCAssert(pScene != NULL, "running scene should not be null");
	CCAssert(m_pRunningScene == NULL, "m_pRunningScene should be null");

	pushScene(pScene);
	startAnimation();
}
Esempio n. 3
0
void CCDirector::runWithScene(CCScene *pScene)
{
	assert(pScene != NULL);
	assert(m_pRunningScene == NULL);

	pushScene(pScene);
	startAnimation();
}
Esempio n. 4
0
void Game::setCurrentScene(Scene *currentScene)
{
    if(!currentScene)
        return;
    if(m_sceneStack.size() > 0 && currentScene == m_sceneStack.top())
        return;

    if(m_sceneStack.isEmpty()){
        pushScene(currentScene);
        return;
    }

    int stackLevel = m_sceneStack.size();

    //we need to check the the currentScene is already on the stack
    //and remove it to put on top
    if(m_sceneStack.contains(currentScene)){
        int index = m_sceneStack.indexOf(currentScene);
        m_sceneStack.remove(index);
        //fix Scene Z in case of pushing a scene in the middle of
        //the stack to the top
        for(int i = index ; i< stackLevel -1; i++){
            m_sceneStack.at(i)->setZ(i);
        }
    }

    m_exitScene = m_sceneStack.pop();

    m_sceneStack.push(currentScene);
    currentScene->setZ(m_sceneStack.size());

    if(stackLevel != m_sceneStack.size())
        emit stackLevelChanged();

    if(currentScene->viewport()){
        currentScene->viewport()->setZ(m_sceneStack.size());
    }
    deactivateScene(m_exitScene);

    attachScene(currentScene);

    triggerExitAnimation(m_exitScene);
    if(!triggerEnterAnimation(currentScene)){
        activateScene(currentScene);
        if(m_exitScene)
            m_exitScene->setVisible(false);
        m_exitScene = NULL;
    }
}
Esempio n. 5
0
void CredditScene::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event) {
    
    auto target = static_cast<Sprite*>(event->getCurrentTarget());
    Point locationInNode = target->convertToNodeSpace(touch->getLocation());
    Size s = target->getContentSize();
    Rect rect = Rect(0, 0, s.width, s.height);
    
    if (target == bgc) {
        if (rect.containsPoint(locationInNode)) {
            auto director = Director::getInstance();
            auto scene = MainMenu::createScene();
            director->pushScene(scene);
        }
    }
}
Esempio n. 6
0
void StartScene::toHelp(){
	auto director = Director::getInstance();
	RenderTexture* renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height);
	renderTexture->begin();
	this->getParent()->visit();
	renderTexture->end();

	auto scene = pausePopup::createScene(renderTexture, "images/popupBg1.png");
	auto layer = pausePopup::create(renderTexture, "images/popupBg1.png");
	scene->addChild(layer, 1);

	layer->contentText = Label::createWithTTF("游戏介绍", "fonts/msyhbd.ttc", 20);
	layer->contentText->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 20 * 18);
	layer->menuSprite->addChild(layer->contentText);

	std::string str = "这是一款横版过关类游戏\n";
	str = str + "在游戏中你可以使用各种酷炫的技能消灭敌人,\n拾取强化道具,\n最后干掉boss,通过关卡!\n";
	str = str + "基本操作:\nW:跳\nD:前进(向右)\nA:后退(向左)\n点击右侧技能栏选择攻击技能\n";
	str = str + "点击屏幕进行攻击\n现在就开始你的战斗之旅吧!\n";

	auto infoLabel = Label::createWithTTF(str, "fonts/msyhbd.ttc", 20);
	infoLabel->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 20 * 19-infoLabel->getContentSize().width/2);
	layer->menuSprite->addChild(infoLabel);

	auto backLabel = Label::createWithTTF("返回游戏", "fonts/msyhbd.ttc", 15);
	backLabel->setColor(Color3B::BLACK);
	auto backItem = MenuItemLabel::create(backLabel, CC_CALLBACK_0(pausePopup::backToGame, layer));
	backItem->setPosition(backItem->getContentSize().width * 3 / 2, 0);

	layer->menu = Menu::create(backItem, NULL);

	layer->menu->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 12);
	layer->menuSprite->addChild(layer->menu, 10);


	//auto popupScene = Popup::createScene(renderTexture,"images/popupBg.png");
	//auto popup = Popup::create("images/popupBg.png");
	//this->addChild(popup, 10);
	//Action* popupAction = Sequence::create(ScaleTo::create(0.0f, 0.0f),
	//								ScaleTo::create(0.06f, 1.05f),
	//								ScaleTo::create(0.08f, 0.95f),
	//								ScaleTo::create(0.08f, 1.0f), NULL);
	//popup->runAction(popupAction);
	//Director::getInstance()->pause();
	director->pushScene(scene);
	//Director::getInstance()->replaceScene(popupScene);
}
Esempio n. 7
0
void StartScene::toHelp(){
	auto director = Director::getInstance();
	RenderTexture* renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height);
	renderTexture->begin();
	this->getParent()->visit();
	renderTexture->end();

	auto popup = Popup::createScene(renderTexture,"images/popupBg.png");
	//this->addChild(popup, 10);
	//Action* popupAction = Sequence::create(ScaleTo::create(0.0f, 0.0f),
	//	ScaleTo::create(0.06f, 1.05f),
	//	ScaleTo::create(0.08f, 0.95f),
	//	ScaleTo::create(0.08f, 1.0f), NULL);
	//popup->runAction(popupAction);
	director->pushScene(popup);
	auto str = String::create("±³¾°½éÉÜ£¬ÓÎÏ·²Ù×÷½éÉÜ");
	//popup->setContentText(str);
}
Esempio n. 8
0
MyGLWidget::MyGLWidget(QGLFormat * glf, QWidget *parent) :
        QGLWidget(*glf,parent), move(0.01f)
{


    light_diffuse = QVector4D(0.33, 0.33, 0.33, 1.0);
    light_ambient = QVector4D(0.2, 0.2, 0.2, 1.0);  /* light. */
    light_specular = QVector4D(0.0,0.0,0.0, 1.0);
    light_position1 = QVector4D(0.0, 1.0, 1.0, 0.0);  /* Infinite light location. */
    light_position2 = QVector4D(1.0, 1.0, -1.0, 0.0);
    light_position3 = QVector4D(-1.0, 1.0, -1.0, 0.0);

    setFocusPolicy(Qt::StrongFocus);
    setMouseTracking(true);
    setCursor( QCursor( Qt::CrossCursor ) );
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(animate()));
    timer->start(25);

    scene = new Scene();

    pushScene();
}
Esempio n. 9
0
void wyDirector::runWithScene(wyScene* scene) {
	if(scene != NULL && m_runningScene == NULL)
		pushScene(scene);
}
Esempio n. 10
0
void LevelListScene::_build()
{
    cocos2d::Vec2 visibleOrigin = cocos2d::Director::getInstance()->getVisibleOrigin();
    cocos2d::Size visibleSize = cocos2d::Director::getInstance()->getVisibleSize();
    
    //auto background = cocos2d::Sprite::create("background.png");
    //background->setAnchorPoint(cocos2d::Vec2::ZERO);
    //background->setPosition(cocos2d::Vec2::ZERO);
    //background->setOpacity(0);
    //addChild(background);
    //background->runAction(cocos2d::FadeIn::create(0.5));
    
    auto levelPack = _game->getLevelPack(_packIndex);
    const std::vector<LevelPackEntry>& entries = levelPack->getEntries();
    
    cocos2d::Rect menuRect(visibleOrigin.x + 100, visibleOrigin.y + 100, visibleSize.width - 200, visibleSize.height - 140);
    cocos2d::Size cellSize(menuRect.size.width / 5, menuRect.size.height / 5);
    cocos2d::Vec2 point(0, menuRect.size.height - cellSize.height);
    
    bool prevLevelCompleted = true;
    for (size_t i = 0; i + _startLevelIndex < entries.size() && i < 25; i++)
    {
        int levelIndex =_startLevelIndex + i;
        
        auto& record = _game->getHighscores()->getRecord(_packIndex, levelIndex);
        bool canStart = prevLevelCompleted || record.tried;
        
        auto button = cocos2d::ui::Button::create(canStart ? "slide-north-0001.png" : "floor.png", "", "", cocos2d::ui::Widget::TextureResType::PLIST);
        button->setAnchorPoint(cocos2d::Vec2(0.5f, 0.5f));
        button->setPosition(menuRect.origin + point + cocos2d::Vec2(cellSize) * 0.5f - cocos2d::Vec2(0, 100));
        button->setScale(0);
        button->setEnabled(canStart);
        button->addTouchEventListener([this, levelIndex](cocos2d::Ref* sender, cocos2d::ui::Widget::TouchEventType type)
        {
            if (type == cocos2d::ui::Widget::TouchEventType::ENDED)
            {
                auto director = cocos2d::Director::getInstance();
                director->pushScene(LevelScene::create(_game, _packIndex, _startLevelIndex + levelIndex));
            }
        });
        
        if (canStart)
        {
            auto buttonLabel = cocos2d::Label::createWithTTF(std::to_string(i + 1), "fonts/Marker Felt.ttf", 24);
            buttonLabel->setPosition(cocos2d::Vec2(button->getContentSize()) * 0.5f);
            buttonLabel->setAnchorPoint(cocos2d::Vec2(0.5f, 0.5f));
            buttonLabel->enableOutline(cocos2d::Color4B::BLACK, 2);
            button->addChild(buttonLabel);
        }
        
        addChild(button);
        
        if (record.completed)
        {
            auto star = cocos2d::Sprite::createWithSpriteFrameName("ic-chip.png");
            star->setPosition(cocos2d::Vec2(button->getContentSize().width - 10, 11));
            button->addChild(star);
        }
        
        if (i % 5 != 4)
        {
            point.x += cellSize.width;
        }
        else
        {
            point.x = 0;
            point.y -= cellSize.height;
        }

        button->runAction(cocos2d::Sequence::create(
            cocos2d::DelayTime::create(0.01 * i),
            cocos2d::Spawn::create(
                cocos2d::EaseBounceIn::create(cocos2d::ScaleTo::create(0.25, 1)),
                cocos2d::MoveBy::create(0.25, cocos2d::Vec2(0, 100)),
                nullptr
            ),
            nullptr
        ));
        
        prevLevelCompleted = record.completed;
    }
    
    /*auto backButton = cocos2d::MenuItemSprite::create(cocos2d::Sprite::create("boots-ice.png"), nullptr, CC_CALLBACK_1(LevelsScene::_backCallback, this));
    backButton->setPosition(cocos2d::Vec2(100, 60));
    menu->addChild(backButton);*/
}
Esempio n. 11
0
void Game::changeScene(Scene* scene){
	if (!this->scenes.empty()){
		popScene();
	}
	pushScene(scene);
}
Esempio n. 12
0
void StartScene::toSetting(){
	auto director = Director::getInstance();
	RenderTexture* renderTexture = RenderTexture::create(visibleSize.width, visibleSize.height);
	renderTexture->begin();
	this->getParent()->visit();
	renderTexture->end();

	auto scene = pausePopup::createScene(renderTexture, "images/popupBg1.png");
	auto layer = pausePopup::create(renderTexture, "images/popupBg1.png");
	scene->addChild(layer, 1);

	layer->contentText = Label::createWithTTF("游戏设置", "fonts/msyhbd.ttc", 20);
	layer->contentText->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 5 * 4);
	layer->menuSprite->addChild(layer->contentText);

	auto musicSetting = Label::createWithTTF("音量设置", "fonts/msyhbd.ttc", 15);
	musicSetting->setPosition(layer->menuSprite->getContentSize().width / 3, layer->menuSprite->getContentSize().height / 5 * 3);
	layer->menuSprite->addChild(musicSetting);

	slider = ControlSlider::create("images/slider/slider1.png","images/slider/slider0.png","images/slider/slider2.png");
	slider->setPosition(layer->menuSprite->getContentSize().width / 3*2, layer->menuSprite->getContentSize().height / 5 * 3);
	slider->setMinimumValue(0.0f);
	slider->setMaximumValue(100.0f);

	auto initValue = 50.0f;
	if (database->getBoolForKey("isExit")) initValue = database->getFloatForKey("music");

	slider->setValue(initValue);
	slider->addTargetWithActionForControlEvents(this, cccontrol_selector(StartScene::musicSlider), Control::EventType::VALUE_CHANGED);
	layer->menuSprite->addChild(slider);

	auto resetLabel = Label::createWithTTF("重置游戏", "fonts/msyhbd.ttc", 15);
	MenuItemLabel* resetItem = MenuItemLabel::create(resetLabel, CC_CALLBACK_0(StartScene::resetGame,this));
	resetItem->setPosition(0, 0);
	auto resetMenu = Menu::create(resetItem,NULL);
	resetMenu->setPosition(layer->menuSprite->getContentSize().width / 3, layer->menuSprite->getContentSize().height / 5 * 2);
	layer->menuSprite->addChild(resetMenu);
	
	auto backLabel = Label::createWithTTF("返回游戏", "fonts/msyhbd.ttc", 15);
	backLabel->setColor(Color3B::BLACK);
	auto backItem = MenuItemLabel::create(backLabel, CC_CALLBACK_0(pausePopup::backToGame, layer));
	backItem->setPosition(backItem->getContentSize().width * 3 / 2, 0);

	layer->menu = Menu::create(backItem, NULL);

	layer->menu->setPosition(layer->menuSprite->getContentSize().width / 2, layer->menuSprite->getContentSize().height / 12);
	layer->menuSprite->addChild(layer->menu, 10);


	//auto popupScene = Popup::createScene(renderTexture,"images/popupBg.png");
	//auto popup = Popup::create("images/popupBg.png");
	//this->addChild(popup, 10);
	//Action* popupAction = Sequence::create(ScaleTo::create(0.0f, 0.0f),
	//								ScaleTo::create(0.06f, 1.05f),
	//								ScaleTo::create(0.08f, 0.95f),
	//								ScaleTo::create(0.08f, 1.0f), NULL);
	//popup->runAction(popupAction);
	//Director::getInstance()->pause();
	director->pushScene(scene);
	//Director::getInstance()->replaceScene(popupScene);
}
Esempio n. 13
0
void Director::runWithScene(Scene* scene)
{
	pushScene(scene);
}