bool GameScene::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent) { if(GameData::gameState == GameData::STATE_PAUSE) { return false; } else if(GameData::gameState == GameData::STATE_GAMEOVER) { CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->stopBackgroundMusic(); CCScene* scene = CCTransitionFade::create(0.3f, MainScene::scene()); CCDirector::sharedDirector()->replaceScene(scene); GameData::gameState = GameData::STATE_PLAYING; return false; } int x = (CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView())).x; if(x>450) { this->changeCharLine(true); } else { this->changeCharLine(false); } return false; }
void MainLayer::onPlay(CCObject* pSender) { CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine(); audioEngine->playBackgroundMusic("background.mp3",true); CCDirector::sharedDirector()->replaceScene(PlayLayer::scene()); }
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_stopBackgroundMusic(lua_State* tolua_S) { int argc = 0; CocosDenshion::SimpleAudioEngine* cobj = nullptr; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror; #endif cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 if (!cobj) { tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_stopBackgroundMusic'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; if (argc == 0) { if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_stopBackgroundMusic'", nullptr); return 0; } cobj->stopBackgroundMusic(); return 0; } if (argc == 1) { bool arg0; ok &= luaval_to_boolean(tolua_S, 2,&arg0, "cc.SimpleAudioEngine:stopBackgroundMusic"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_stopBackgroundMusic'", nullptr); return 0; } cobj->stopBackgroundMusic(arg0); return 0; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:stopBackgroundMusic",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_stopBackgroundMusic'.",&tolua_err); #endif return 0; }
void GameScene::clickBtnResume(CCObject* pObject) { layerPauseMenu->setVisible(false); GameData::gameState = GameData::STATE_PLAYING; CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->resumeBackgroundMusic(); }
void GameScene::clickBtnExit(CCObject* pObject) { CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->stopBackgroundMusic(); CCScene* scene = CCTransitionFade::create(0.3f, MainScene::scene()); CCDirector::sharedDirector()->replaceScene(scene); // GameData::gameState = GameData::STATE_PLAYING; }
void Runner::crouch() { m_state = RunnerStateCrouch; this->initShape("crouch"); this->stopAllActions(); this->runAction(m_actionCrouch); this->scheduleOnce(schedule_selector(Runner::loadNormal), 1.5); CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine(); audioEngine->playEffect("Sound/crouch.mp3"); }
void GameScene::startBackgroundMusic() { CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->stopBackgroundMusic(); if(GameData::isMusicSound) { instance->playBackgroundMusic("game.wav", true); } }
void HelloWorld::menuMusicCallback(CCObject* pSender) { CocosDenshion::SimpleAudioEngine* audio = CocosDenshion::SimpleAudioEngine::sharedEngine(); if(!audio->isBackgroundMusicPlaying()) { audio->playBackgroundMusic("akon.mp3", true); } else { audio->stopBackgroundMusic(); } }
void Runner::jump() { if (m_state == RunnerStateRunning) { m_state = RunnerStateJumpUp; cpBodyApplyImpulse(body, cpv(0, 400), cpv(0, 0)); this->stopAllActions(); this->runAction(m_actionJumpUp); CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine(); audioEngine->playEffect("Sound/jump.mp3"); } }
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getDuration(lua_State* tolua_S) { int argc = 0; CocosDenshion::SimpleAudioEngine* cobj = nullptr; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror; #endif cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 if (!cobj) { tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getDuration'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; if (argc == 1) { const char* arg0; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:getDuration"); arg0 = arg0_tmp.c_str(); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getDuration'", nullptr); return 0; } double ret = cobj->getDuration(arg0); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:getDuration",argc, 1); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getDuration'.",&tolua_err); #endif return 0; }
void GameScene::clickBtnPause(CCObject* pOjbect) { // initMenuItemBtnPause(); if(GameData::gameState == GameData::STATE_GAMEOVER) { return; } startSoundEffect("pong.wav"); GameData::gameState = GameData::STATE_PAUSE; layerPauseMenu->setVisible(true); CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->pauseBackgroundMusic(); }
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_pauseEffect(lua_State* tolua_S) { int argc = 0; CocosDenshion::SimpleAudioEngine* cobj = nullptr; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror; #endif cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 if (!cobj) { tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_pauseEffect'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; if (argc == 1) { unsigned int arg0; ok &= luaval_to_uint32(tolua_S, 2,&arg0, "cc.SimpleAudioEngine:pauseEffect"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_pauseEffect'", nullptr); return 0; } cobj->pauseEffect(arg0); lua_settop(tolua_S, 1); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:pauseEffect",argc, 1); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_pauseEffect'.",&tolua_err); #endif return 0; }
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getEffectsVolume(lua_State* tolua_S) { int argc = 0; CocosDenshion::SimpleAudioEngine* cobj = nullptr; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror; #endif cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 if (!cobj) { tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getEffectsVolume'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; if (argc == 0) { if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getEffectsVolume'", nullptr); return 0; } double ret = cobj->getEffectsVolume(); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:getEffectsVolume",argc, 0); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_getEffectsVolume'.",&tolua_err); #endif return 0; }
bool MainLayer::init() { if (!CCLayer::init()) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCPoint centerPos = CCPoint(visibleSize.width / 2, visibleSize.height / 2); //add backgroud CCSprite *spriteBG = CCSprite::create("MainBG.png"); spriteBG->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); this->addChild(spriteBG, 0); //add menu item CCMenuItemFont::setFontSize(60); CCMenuItemImage *menuItemPlay = CCMenuItemImage::create("start_n.png", "start_s.png", this, menu_selector(MainLayer::onPlay)); menuItemPlay->setPosition(centerPos); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(menuItemPlay, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); // preload music CocosDenshion::SimpleAudioEngine *audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine(); audioEngine->preloadBackgroundMusic("background.mp3"); audioEngine->preloadEffect("jump.mp3"); audioEngine->preloadEffect("crouch.mp3"); audioEngine->setBackgroundMusicVolume(0.3); audioEngine->setEffectsVolume(0.3); return true; }
void GameScene::removeHumanSprite(HumanSprite *humanSprite) { if(humanSprite->humanState == 1 && humanSprite->currentY > -200) { GameData::gameState = GameData::STATE_GAMEOVER; sprGameOver->setVisible(true); CocosDenshion::SimpleAudioEngine* instance = CocosDenshion::SimpleAudioEngine::sharedEngine(); instance->stopBackgroundMusic(); this->unschedule(schedule_selector(GameScene::update)); layerCombo->setVisible(false); if(GameData::highScore < currentScore) { GameData::highScore = currentScore; FileIO::sharedInstance()->saveFile(); } return; } arrayHumanSprite->removeObject(humanSprite); this->removeChild(humanSprite, true); }
void CCSWFNodeExt::handleFrameChanged(cocos2d::CCObject * obj){ CCSWFNode * node = (CCSWFNode *)obj; if (m_logicDict) { CocosDenshion::SimpleAudioEngine * audioEngine = CocosDenshion::SimpleAudioEngine::sharedEngine(); std::stringstream frameKey; frameKey << (node->getCurrentFrame() + 1); CCDictionary * dict = (CCDictionary *)m_logicDict->objectForKey(frameKey.str()); if (dict) { //切换背景音乐 CCString * music = (CCString *)dict->objectForKey("music"); if (music && m_music.compare(music->m_sString) != 0) { m_music = music->m_sString; if (m_music.length() > 0) { CCLOG("CSWFNodeExt::handleFrameChanged %d playBackgroundMusic %s",node->getCurrentFrame(),m_music.c_str()); audioEngine->stopBackgroundMusic(true); audioEngine->preloadBackgroundMusic(m_music.c_str()); audioEngine->playBackgroundMusic(m_music.c_str(),true); } } //播放音效 CCString * effect = (CCString *)dict->objectForKey("effect"); if (effect && effect->length() > 0) { const std::string tag = "#"; std::string srcString = effect->m_sString; size_t startPos = srcString.find_first_of(tag); if (startPos != std::string::npos) { std::string tmp; do { tmp = srcString.substr(0,startPos); CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str()); audioEngine->preloadEffect(tmp.c_str()); audioEngine->playEffect(tmp.c_str(), false); srcString = srcString.substr(startPos+tag.length()); startPos = srcString.find_first_of(tag); if(startPos == std::string::npos){ CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),tmp.c_str()); audioEngine->preloadEffect(tmp.c_str()); audioEngine->playEffect(tmp.c_str(), false); } } while(startPos != std::string::npos) ; }else{ CCLOG("CSWFNodeExt::handleFrameChanged %d playEffect %s",node->getCurrentFrame(),srcString.c_str()); audioEngine->preloadEffect(srcString.c_str()); audioEngine->playEffect(srcString.c_str(), false); } } } if (node->getCurrentFrame() == node->getFrameCount() - 1) { audioEngine->stopAllEffects(); if (m_stopBgMusic) { audioEngine->stopBackgroundMusic(true); } CCObject * effectFile = NULL; CCARRAY_FOREACH(m_loadEffects, effectFile){ audioEngine->unloadEffect(((CCString *)effectFile)->getCString()); } m_loadEffects->removeAllObjects(); }
int lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect(lua_State* tolua_S) { int argc = 0; CocosDenshion::SimpleAudioEngine* cobj = nullptr; bool ok = true; #if COCOS2D_DEBUG >= 1 tolua_Error tolua_err; #endif #if COCOS2D_DEBUG >= 1 if (!tolua_isusertype(tolua_S,1,"cc.SimpleAudioEngine",0,&tolua_err)) goto tolua_lerror; #endif cobj = (CocosDenshion::SimpleAudioEngine*)tolua_tousertype(tolua_S,1,0); #if COCOS2D_DEBUG >= 1 if (!cobj) { tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } #endif argc = lua_gettop(tolua_S)-1; if (argc == 1) { const char* arg0; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str(); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } unsigned int ret = cobj->playEffect(arg0); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } if (argc == 2) { const char* arg0; bool arg1; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str(); ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } unsigned int ret = cobj->playEffect(arg0, arg1); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } if (argc == 3) { const char* arg0; bool arg1; double arg2; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str(); ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } unsigned int ret = cobj->playEffect(arg0, arg1, arg2); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } if (argc == 4) { const char* arg0; bool arg1; double arg2; double arg3; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str(); ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 5,&arg3, "cc.SimpleAudioEngine:playEffect"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } if (argc == 5) { const char* arg0; bool arg1; double arg2; double arg3; double arg4; std::string arg0_tmp; ok &= luaval_to_std_string(tolua_S, 2, &arg0_tmp, "cc.SimpleAudioEngine:playEffect"); arg0 = arg0_tmp.c_str(); ok &= luaval_to_boolean(tolua_S, 3,&arg1, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 4,&arg2, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 5,&arg3, "cc.SimpleAudioEngine:playEffect"); ok &= luaval_to_number(tolua_S, 6,&arg4, "cc.SimpleAudioEngine:playEffect"); if(!ok) { tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'", nullptr); return 0; } unsigned int ret = cobj->playEffect(arg0, arg1, arg2, arg3, arg4); tolua_pushnumber(tolua_S,(lua_Number)ret); return 1; } luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.SimpleAudioEngine:playEffect",argc, 1); return 0; #if COCOS2D_DEBUG >= 1 tolua_lerror: tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_cocosdenshion_SimpleAudioEngine_playEffect'.",&tolua_err); #endif return 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; }
void AppDelegate::preload_sounds() { #ifdef _WIN32 CCLOG("on windows, skipping audio preload"); #else CocosDenshion::SimpleAudioEngine* cache = CocosDenshion::SimpleAudioEngine::getInstance(); CCLOG("start loading audio"); cache->preloadEffect(clean_path("sounds\\old\\Swoosh.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\barrel.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\beep.mp3").c_str()); // cache->preloadEffect(clean_path("sounds\\old\\block.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\brick_hit.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\brick_scrape.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\cheering.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\coin.mp3").c_str()); //cache->preloadEffect(clean_path("sounds\\old\\ding.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\doom_rocket.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\dsnoway.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\glassbreak.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\ice_freeze.mp3").c_str()); //cache->preloadEffect(clean_path("sounds\\old\\lighter.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\radio_wave.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\real_punch.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\shield_die.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\shield_disable.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\shield_hit.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\shotgun.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\shotgun_reload.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\suicide_bomber.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\wall_destroy.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\barrel\\C_barrel_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\block\\C_block+1.mp3").c_str()); // cache->preloadEffect(clean_path("sounds\\new\\block\\C_block+2.mp3").c_str()); // cache->preloadEffect(clean_path("sounds\\new\\block\\C_block_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\charged\\C_charged_1.mp3").c_str()); //cache->preloadEffect(clean_path("sounds\\new\\cheering\\C_cheering_11.mp3").c_str()); //TODO Find a use for this //cache->preloadEffect(clean_path("sounds\\new\\cheering\\C_cheering_12.mp3").c_str()); //TODO Find a use for this cache->preloadEffect(clean_path("sounds\\new\\cheering\\C_cheering_13.mp3").c_str()); //cache->preloadEffect(clean_path("sounds\\new\\coin\\C_coin_1.mp3").c_str()); //cache->preloadEffect(clean_path("sounds\\new\\coin\\C_coin_2.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\doom_rocket\\C_grenade_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\doom_rocket\\C_rocket_big_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\doom_rocket\\C_rocket_small_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_11.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_12.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_13.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_14.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_15.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_16.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_17.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Grunt_18.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_11.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_12.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_13.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_14.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_15.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_16.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_17.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\dsnoway\\C_Hit_18.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\extra\\C_explosion_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\glassbreak\\C_glassbreak_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\ice_freeze\\C_ice_freeze+.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\ice_freeze\\C_ice_freeze_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\lighter\\C_lighter_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\radio_wave\\C_radio_wave_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\radio_wave\\C_radio_wave_2.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\radio_wave\\C_radio_wave_3.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_combo_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch+1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch+2.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch+3.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_11.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_21.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_22.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_23.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_24.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_25.mp3").c_str()); // cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_26.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_27.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_28.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\real_punch\\C_punch_31.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\shotgun\\C_shotgun_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\shotgun_reload\\C_shotgun_reload_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\suicide_bomber\\C_rocket_big+1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\suicide_bomber\\C_rocket_small+2.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_1.wav").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_11.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_12.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_13.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_14.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_15.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_21.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_22.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_23.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_24.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_25.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_26.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\Swoosh\\C_Swoosh_27.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\new\\woop\\C_woop_1.mp3").c_str()); cache->preloadEffect(clean_path("sounds\\old\\woop.mp3").c_str()); CCLOG("done loading audio"); #endif };