Example #1
0
bool GameScene::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!Scene::initWithPhysics());
		//this->getPhysicsWorld()->setDebugDrawMask(PhysicsWorld::DEBUGDRAW_ALL);
		this->getPhysicsWorld()->setGravity(Vect(0, 0));
		/*Background* backgroundLayer = Background::create();
		this->addChild(backgroundLayer);*/
		auto bg = LayerColor::create(Color4B(130, 217, 212, 255));
		this->addChild(bg);
		StatusLayer* statusLayer = StatusLayer::create();
		GameLayer* gameLayer = GameLayer::create(statusLayer);
		//gameLayer->setDelegate(statusLayer);
		gameLayer->setPhyWorld(this->getPhysicsWorld());
		this->addChild(gameLayer);
		this->addChild(statusLayer);
		PlayLayer* playLayer = PlayLayer::create();
		playLayer->setDelegate(gameLayer);
		this->addChild(playLayer);
		bRet = true;
	} while (0);
	return bRet;
}
Example #2
0
void StartGameLoading::loadingEnd(float t)
{
    CCScene *scene = CCScene::create();
    GameLayer *gLayer = GameLayer::create();
    scene->addChild(gLayer);
    CCDirector::sharedDirector()->replaceScene(scene);
    gLayer->scheduleStart(); 
}
//インスタンス生成
GameLayer* GameLayer::create(int level)
{
    GameLayer *pRet = new GameLayer();
    pRet->init(level);
    pRet->autorelease();
    
    return pRet;
}
CCScene* GameLayer::scene()
{
    CCScene* scene = CCScene::create();
    GameLayer* gameLayer = new GameLayer();
    gameLayer->autorelease();
    scene->addChild(gameLayer);
    return scene;
}
Example #5
0
void PauseLayer::startGame(Ref* node)
{
	//CCLOG("START!");
	//GAMEDATA::getInstance()->init();
	//Director::getInstance()->replaceScene(GameScene::create());
    
    Node* pender = (Node*)node;
    
    int tag = pender->getTag();
    
    CCLOG("btn tag = %d",tag);
    
    Scene* scene = (Scene*)this->getParent();
    
    GameLayer* gameLayer = (GameLayer*)scene->getChildByTag(999);
    
    TopMenu* topMenu = (TopMenu*)gameLayer->getChildByTag(9999);
    
    Menu* menuPause = (Menu*)topMenu->getChildByTag(100);
    
    menuPause->setEnabled(true);
    
    switch (tag)
    {
        case 10:
        {
            this->removeSelfListener();

            //主菜单
            Director::getInstance()->replaceScene(MenuScene::create());
            
            this->removeFromParent();
        }
            break;
        case 11:
        {
            Director::getInstance()->getEventDispatcher()->removeEventListener(listener);
            //重新开始
            EventCustom eventReset = EventCustom("Game_Reset");
            Director::getInstance()->getEventDispatcher()->dispatchEvent(&eventReset);
            //从头来
            
            this->removeFromParent();
        }
            break;
        case 12:
        {
            Director::getInstance()->getEventDispatcher()->removeEventListener(listener);
            //继续游戏
            this->removeFromParent();
        }
            break;
            
        default:
            break;
    }

}
Example #6
0
CCScene *GameLayer::scenee()
{
    CCScene *scene = CCScene::create();
    GameLayer *layer = new GameLayer();
    layer->init();
    scene->addChild(layer);
    return scene;
    
}
Example #7
0
void TopMenu::pauseGame()
{
    CCLOG("PAUSE!");
    this->m_menuBtnPause->setEnabled(false);
    //Director::getInstance()->replaceScene(GameScene::create());
    GameLayer* gameLayer = (GameLayer*)this->getParent();
    //gameLayer->setiGameState(2);
    
    Scene* scene = (Scene*)gameLayer->getParent();
    scene->addChild(PauseLayer::create(),2);
}
Example #8
0
void PlayMenu::play()
{
    CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("ButtonClick.mp3");
    CCScene *scene = CCScene::create();
    GameLayer *gameLayer = GameLayer::create();
    gameLayer->GameStart();
    scene->addChild(gameLayer);
    
    CCDirector::sharedDirector()->replaceScene(CCTransitionCrossFade::create(0.5,scene));

}
GameLayer * GameLayer::create() {
	GameLayer * layer = new GameLayer();
    
	if (layer) {
		layer->autorelease();
		layer->initGame();
        return layer;
	}
	CC_SAFE_DELETE(layer);
	return NULL;
}
Example #10
0
void BarPipe::setRandomY() {
    if (!mParent) {
        return;
    }
    GameLayer *layer = (GameLayer *)mParent;
    float groundHeight = layer->getGroundHeight();
    // 计算出管道最多能上下的最大值
    float randomTotal = upBar->getContentSize().height + downBar->getContentSize().height + getBarInterval() - (mParent->getContentSize().height - groundHeight);
    float randomY = CCRANDOM_0_1() * randomTotal;
    downBar->setPositionY(-randomY + groundHeight);
    upBar->setPositionY(downBar->getPositionY() + getHeight(downBar) + getBarInterval());
}
GameScene* GameScene::create(const int gameType)
{
    GameScene* result = new GameScene();
    if (result->init())
    {
        GameLayer* layer = new GameLayer(gameType);
        layer->autorelease();
        result->addChild(layer);
        return result;
    }
    delete result;
    return NULL;
}
Example #12
0
GameLayer* GameLayer::create(GameMode gameMode) {
    GameLayer *pRet = new GameLayer(gameMode);
    if (pRet && pRet->init())
    {
        pRet->autorelease();
        return pRet;
    }
    else
    {
        delete pRet;
        pRet = NULL;
        return NULL;
    }
}
Example #13
0
void GameEngine::start()
{
	_LCD.begin();
	_LCD.setContrast(50);
	_LCD.clearDisplay();
	_LCD.display();

	_OldTick = millis();

	for (int i=0; i<_Layers.size(); i++) {
		GameLayer *layer = _Layers.get(i);
		layer->start();
	}
}
Example #14
0
CCScene* GameLayer::scene(bool isBlackStart)
{
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    GameLayer *layer = GameLayer::create();
    layer->startGame(isBlackStart);

    // add layer as a child to scene
    scene->addChild(layer);

    // return the scene
    return scene;
}
Example #15
0
CCScene * GameLayer::scene() {
	CCScene *scene = CCScene::create();
	if (scene && scene->init()) {
		if (scene) {
			/*-- 背景 --*/
			scene->addChild(BgLayer::create());
			GameLayer *layer = GameLayer::create();
			scene->addChild(layer, TAG_LAYER_GAME);
			scene->addChild(layer->createPauseButtonLayer());
		}
		return scene;
	} else {
		CC_SAFE_DELETE(scene);
		return NULL;
	}

}
Example #16
0
GameLayer*  GameLayer::create(int gamemode) 
{ 
    GameLayer *pRet = new(std::nothrow) GameLayer(); 
    if (pRet) 
    { 
		pRet->gamemode=gamemode;
		if(pRet->init()){
        pRet->autorelease(); 
		return pRet; }else{delete pRet; 
        pRet = NULL; 
        return NULL; }
    } 
    else 
    { 
        delete pRet; 
        pRet = NULL; 
        return NULL; 
    } 
}
Example #17
0
void Game::starNewGame(Player* player1, Player* player2, bool restart)
{
    CCScene *pScene = GameLayer::scene();
    GameLayer* gameLayer = (GameLayer*)pScene->getChildByTag(1337);
    
    if(!restart) {
        addPlayer(player1);
        addPlayer(player2);
    }
    gameLayer->startGame(player1, player2);
    
    if(CCDirector::sharedDirector()->getRunningScene()){
        CCDirector::sharedDirector()->replaceScene(pScene);
    }else{
        CCDirector::sharedDirector()->runWithScene(pScene);
    }
    
    setCurrentScreen(GAME_SCREEN);
    currentGameType = player2->isAI() ? VS_AI : VS_HUMAN;
}
CCScene* EggScrambleModeLayer::scene(int levelNumber)
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);
        
        // 'layer' is an autorelease object
        GameLayer *layer = EggScrambleModeLayer::create(levelNumber);
        CC_BREAK_IF(! layer);
        layer->setName("GameLayer");
        
        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}
Example #19
0
CCScene* Level0::scene()
{
	CCScene* scene = NULL;
	do
	{
		//scene is an autorelease object
		scene = CCScene::create();
		CC_BREAK_IF(! scene);

		//layer is an autorelease object
		SkyLayer* skyLayer = SkyLayer::create();
		skyLayer->setContentSize(CCSizeMake(SCREEN_WIDTH, SCREEN_WIDTH));
		//skyLayer->setPosition(ccp(0, SCREEN_HEIGHT*-2.25));
		CC_BREAK_IF(! skyLayer);

		//add layer as a child to scene
		scene->addChild(skyLayer, 1);

		GameLayer* gameLayer = GameLayer::create();
		gameLayer->setContentSize(CCSizeMake(SCREEN_WIDTH*3, SCREEN_WIDTH*3));
		gameLayer->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_WIDTH*-2.75));
		CC_BREAK_IF(! gameLayer);
		scene->addChild(gameLayer, 2);

		HUDLayer* hudLayer = HUDLayer::create();
		hudLayer->setContentSize(CCSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT));
		CC_BREAK_IF(! hudLayer);

		scene->addChild(hudLayer, 4);

	} while (0);

	

	// return the scene
	return scene;
}
Example #20
0
unsigned long GameEngine::update()
{
	unsigned long tick = millis();
	unsigned long term = 0;
	if (tick > _OldTick) term = tick - _OldTick;
	_OldTick = tick;

	if (_OnBeforeUpdate != NULL) _OnBeforeUpdate(term);

	_LCD.clearDisplay();

	for (int i=0; i<_Layers.size(); i++) {
		GameLayer *layer = _Layers.get(i);
		layer->update(term);
	}

	_LCD.display();

	_AudioTrack.update(term);

	if (_OnAfterUpdate != NULL) _OnAfterUpdate(term);

	return term;
}
Example #21
0
GameScene::GameScene()
{
	GameLayer* pLayer = new GameLayer();
	addChild(pLayer);
	pLayer->release();
}
Example #22
0
Scene* SceneManager::generateLevel(int levelIndex, int score)
{
	if (levelIndex == 0) {
		Director* director = Director::getInstance();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create start scene
		ParallaxBackground* bckMenu = new ParallaxBackground();
		bckMenu->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckMenu->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckMenu->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckMenu->scheduleUpdate();

		auto startScene = IntermediaryScene::create(IntermediaryScene::MENU);
		startScene->setBackground(bckMenu);

		// Create dummy player
		auto dummy = DummyPlayer::create();
		dummy->setPosition(Vec2(width / 2, 130));
		startScene->setPlayer(dummy);

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level0.mp3", true);

		Label* playButtonLabel = Label::createWithTTF("Play", "font.ttf", 35);
		MenuItem* playButton = MenuItemLabel::create(playButtonLabel, [&](Ref* sender){SceneManager::getInstance().fillStack();});

		Label* optionsButtonLabel = Label::createWithTTF("Options", "font.ttf", 35);
		MenuItem* optionsButton = MenuItemLabel::create(optionsButtonLabel);

		Label* exitButtonLabel = Label::createWithTTF("Exit", "font.ttf", 35);
		MenuItem* exitButton = MenuItemLabel::create(exitButtonLabel, [&](Ref* sender){Director::getInstance()->end(); });

		startScene->addMenuItem(playButton);
		startScene->addMenuItem(optionsButton);
		startScene->addMenuItem(exitButton);
		startScene->createMenu();

		return startScene;
	}
	if (levelIndex == 1) {
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* firstLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckFirstLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckFirstLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckFirstLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckFirstLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0),true);
		bckFirstLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level1.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_FIRSTBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_1, OBJECT_FIRSTBOSS_CANNON_1_D, OBJECT_BOSSBULLET_LASER);
		cannon1->setPosition(Vec2(123, 105));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_2, OBJECT_FIRSTBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SPIKEBALL);
		cannon2->setPosition(Vec2(150, 183));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_FIRSTBOSS_CANNON_3, OBJECT_FIRSTBOSS_CANNON_3_D, OBJECT_BOSSBULLET_BALL);
		cannon3->setPosition(Vec2(59, 148));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon2);
		boss->addCannon(2, cannon1);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		firstLevelLayer->setBackground(bckFirstLevel);
		firstLevelLayer->setPlayer(hero);
		firstLevelLayer->setBoss(boss);
		firstLevelLayer->setDistanceToBoss(1000);
		firstLevelLayer->addObjectFactory(mailboxFactory);
		firstLevelLayer->addObjectFactory(rocketFactory);
		firstLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(firstLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 2)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* secondLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckSecondLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckSecondLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckSecondLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckSecondLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckSecondLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level2.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_SECONDBOSS,true);

		BossCannon* cannon1 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_1, OBJECT_SECONDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_ENERGYBALL);
		cannon1->setPosition(Vec2(85, 38));
		cannon1->setFireMethod(1, 10, 50);

		BossCannon* cannon2 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_2, OBJECT_SECONDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_SAWBLADE);
		cannon2->setPosition(Vec2(34, 137));
		cannon2->setFireMethod(2, 10, 50);

		BossCannon* cannon3 = BossCannon::create(OBJECT_SECONDBOSS_CANNON_3, OBJECT_SECONDBOSS_CANNON_3_D, OBJECT_BOSSBULLET_FLAMEBALL);
		cannon3->setPosition(Vec2(20, 135));
		cannon3->setFireMethod(3, 3, 50);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);
		boss->addCannon(3, cannon3);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));


		secondLevelLayer->setBackground(bckSecondLevel);
		secondLevelLayer->setPlayer(hero);
		secondLevelLayer->setBoss(boss);
		secondLevelLayer->setDistanceToBoss(100);
		secondLevelLayer->addObjectFactory(mailboxFactory);
		secondLevelLayer->addObjectFactory(rocketFactory);
		secondLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(secondLevelLayer);

		return firstLevel;
	}
	if (levelIndex == 3)
	{
		Director* director = Director::getInstance();

		// Create a new GameLayer
		GameLayer* thirdLevelLayer = GameLayer::create();

		// Create a background
		ParallaxBackground* bckThirdLevel = new ParallaxBackground();

		float height = director->getWinSize().height;
		float width = director->getWinSize().width;

		// Create animations and bullets
		bckThirdLevel->addImage("night.png", Vec2(width / 2, height / 1.3), Vec2(0.05, 0));
		bckThirdLevel->addImage("city.png", Vec2(width / 2, height / 1.6), Vec2(0.3, 0));
		bckThirdLevel->addImage("street.png", Vec2(width / 2, height / 2.6), Vec2(1.0, 0), true);
		bckThirdLevel->scheduleUpdate();

		// Create music
		CocosDenshion::SimpleAudioEngine* audioEngine = CocosDenshion::SimpleAudioEngine::getInstance();
		audioEngine->playBackgroundMusic("level3.mp3", true);

		// Create player
		Player* hero = Player::create();
		hero->setPosition(Vec2(width / 2, 130));
		hero->setTag(PLAYER_TAG);
		hero->setScore(score);

		// Create boss
		Boss* boss = Boss::create(OBJECT_THIRDBOSS);

		BossCannon* cannon1 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_1, OBJECT_THIRDBOSS_CANNON_1_D, OBJECT_BOSSBULLET_BOMB);
		cannon1->setPosition(Vec2(68, 218));
		cannon1->setFireMethod(2, 10, 10);

		BossCannon* cannon2 = BossCannon::create(OBJECT_THIRDBOSS_CANNON_2, OBJECT_THIRDBOSS_CANNON_2_D, OBJECT_BOSSBULLET_RASENGAN);
		cannon2->setPosition(Vec2(28, 148));
		cannon2->setFireMethod(3, 1, 10);

		boss->addCannon(1, cannon1);
		boss->addCannon(2, cannon2);

		// Create Interactive object factory
		InteractiveObjectFactory* mailboxFactory = InteractiveObjectFactory::create(OBJECT_MAILBOX, director->getWinSize().height * 1.6 / 800, false, MAILBOX_COLLISION_BITMASK, true, false, true);
		mailboxFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		mailboxFactory->setSpawnFrequency(5);
		mailboxFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		InteractiveObjectFactory* rocketFactory = InteractiveObjectFactory::create(OBJECT_ROCKET, director->getWinSize().height * 1.6 / 800, false, ROCKET_COLLISION_BITMASK, true, false, false);
		rocketFactory->setPositionInterval(Vec2(100, height));
		rocketFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 25.0 / 800), 0));
		rocketFactory->setSpawnFrequency(20);

		InteractiveObjectFactory* spikesFactory = InteractiveObjectFactory::create(OBJECT_SPIKES, director->getWinSize().height * 0.5 / 800, false, SPIKES_COLLISION_BITMASK, false, true, true);
		spikesFactory->setPositionInterval(Vec2(height / GROUND_PERCENTAGE_FOR_BOX + 10, height / GROUND_PERCENTAGE_FOR_BOX + 10));
		spikesFactory->setSpawnFrequency(5);
		spikesFactory->setSpeed(Vec2(-(Director::getInstance()->getWinSize().width * 10.0 / 800), 0));

		thirdLevelLayer->setBackground(bckThirdLevel);
		thirdLevelLayer->setPlayer(hero);
		thirdLevelLayer->setBoss(boss);
		thirdLevelLayer->setDistanceToBoss(1000);
		thirdLevelLayer->addObjectFactory(mailboxFactory);
		thirdLevelLayer->addObjectFactory(rocketFactory);
		thirdLevelLayer->addObjectFactory(spikesFactory);

		//Create Scene
		GameLevel* firstLevel = GameLevel::create(thirdLevelLayer);

		return firstLevel;
	}

	return nullptr;
}
Example #23
0
GameLayer* GameLayer::create() {
    GameLayer* mGameLayer = new GameLayer();
    mGameLayer->autorelease();
    return mGameLayer;
}
Example #24
0
bool IdleLayer::init() {
    if(!LayerColor::init()) {
        return false;
    }
    
    Director* director = Director::getInstance();
    Vec2 visibleOrigin = director->getVisibleOrigin();
    Size visibleSize = director->getVisibleSize();
    
    setContentSize(visibleSize);
    
    GameLayer* gameLayer = GameLayer::create(IDLE);
    gameLayer->getUiLayer()->setVisible(false);
    addChild(gameLayer);
    
//    gameLayer->setColor(Color3B::RED);
    
    Widget* idleForeground = GUIReader::getInstance()->widgetFromJsonFile("ui/connect/idle_foreground.json");
    Node* background = idleForeground->getChildByName("background");
    background->setContentSize(visibleSize);
    
    Text* touchToStart = dynamic_cast<Text*>(idleForeground->getChildByName("touchToStart"));
    touchToStart->setString(LANG->getLang("touch_to_start"));
    touchToStart->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2));
    touchToStart->runAction(RepeatForever::create(Blink::create(1, 1)));

    addChild(idleForeground);
    
    EventDispatcher* eventDispatcher = director->getEventDispatcher();
    
    EventListenerTouchOneByOne* eventListener = EventListenerTouchOneByOne::create();
    eventListener->setSwallowTouches(true);
    eventListener->onTouchEnded = [=](Touch* touch, Event* event){
        auto scene = MainMenuLayer::createScene();
        director->replaceScene(scene);
    };
    eventListener->onTouchBegan = [](Touch* touch, Event* event){
        return true;
    };
    
    eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, touchToStart);
    
    CallFunc* connectAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty() && gameLayer->getAcceptInput()) {
            auto path = game->getRandomPath();
            if(path) {
                auto front = path->getPath().front();
                auto back = path->getPath().back();
                gameLayer->doConnect(front->getX(), front->getY(), back->getX(), back->getY());
            }

        }
    });
    
    CallFunc* shuffleAction = CallFunc::create([=](){
        auto game = gameLayer->getGame();
        if (!game->isEmpty()) {
            if (rand()%10 == 0) {
                gameLayer->doShuffle();
            }
        }
    });
    
    runAction(RepeatForever::create(Sequence::create(DelayTime::create(1.5), connectAction, shuffleAction, NULL)));
    
    return true;
}
Example #25
0
void Game::endGame()
{
    CCScene * pScene = CCDirector::sharedDirector()->getRunningScene();
    GameLayer* gameLayer = (GameLayer*)pScene->getChildByTag(1337);
    gameLayer->endGame();
}