bool GameScene::init() { if (!Layer::init())return false; initPlist(); initEffect(); //set game status Config::getInstance()->setGameSatus(ING); Config::getInstance()->setScore(0);//rest score //loding effect auto _SimpleAudioEngine = SimpleAudioEngine::getInstance(); _SimpleAudioEngine->preloadEffect(air_shoot_effect1); _SimpleAudioEngine->preloadEffect(ship_explode_effect0); //init game map //init enemy type switch (levelNum) { case GAMEMAP1://0 if (Config::getInstance()->getmusicState()) { auto simpleAudio = SimpleAudioEngine::getInstance(); simpleAudio->preloadBackgroundMusic(battle_bg_stage0); simpleAudio->setBackgroundMusicVolume(1.0f); simpleAudio->playBackgroundMusic(battle_bg_stage0, true); } addMap("Map1.png"); levelScore = BOOS_LEVEL1; break; case GAMEMAP2://1 if (Config::getInstance()->getmusicState()) { auto simpleAudio = SimpleAudioEngine::getInstance(); simpleAudio->preloadBackgroundMusic(battle_bg_stage1); simpleAudio->setBackgroundMusicVolume(1.0f); simpleAudio->playBackgroundMusic(battle_bg_stage1, true); } addMap("Map2.png"); levelScore = BOOS_LEVEL2; //add particle Kit::addParticle(snow_plist, this, VisibleRect::top()); break; case GAMEMAP3://2 if (Config::getInstance()->getmusicState()) { auto simpleAudio = SimpleAudioEngine::getInstance(); simpleAudio->preloadBackgroundMusic(battle_bg_stage2); simpleAudio->setBackgroundMusicVolume(1.0f); simpleAudio->playBackgroundMusic(battle_bg_stage2, true); } addMap("Map3.png"); levelScore = BOOS_LEVEL3; break; case GAMEMAP4://3 if (Config::getInstance()->getmusicState()) { auto simpleAudio = SimpleAudioEngine::getInstance(); simpleAudio->preloadBackgroundMusic(battle_bg_stage2); simpleAudio->setBackgroundMusicVolume(1.0f); simpleAudio->playBackgroundMusic(battle_bg_stage2, true); } addMap("Map4.png"); levelScore = BOOS_LEVEL4; //add fire paticle Kit::addParticle(battle_fire_bg_particle_plist, this, VisibleRect::top()); break; default: log("there's no game map to do !"); return false; break; } //add logo one top-left auto logoShip = Sprite::createWithSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(SHIP_FILE_NAME)); float offset = logoShip->getContentSize().width / 2; logoShip->setScale(0.8f); auto winsize = Director::getInstance()->getWinSize(); logoShip->setPosition(Vec2(offset, winsize.height - offset)); this->addChild(logoShip, SHIP_Z_ORDER); //set life value beside of logoShip Config::getInstance()->setShipLife(SHIP_LIFES); __String life("X"); life.appendWithFormat("%02d", Config::getInstance()->getShipLife()); lifeValue = Label::createWithSystemFont(life.getCString(), "Arial", 12); lifeValue->setPosition(Vec2(offset * 3, winsize.height - offset)); lifeValue->setColor(Color3B::RED); this->addChild(lifeValue, SHIP_Z_ORDER); //add score __String tempscore("得分:"); tempscore.appendWithFormat("%07d", Config::getInstance()->getScore()); score = Label::createWithSystemFont(tempscore.getCString(), "Arial", 12); score->setPosition(Vec2(winsize.width - 45, winsize.height - offset)); score->setColor(Color3B::RED); this->addChild(score, SHIP_Z_ORDER); ship = Ship::creatShip(this, 0, SHIP_LIFE_VALUE); auto initPosition = VisibleRect::center(); ship->setPosition(Vec2(initPosition.x, initPosition.y - 120.0f)); this->addChild(ship, SHIP_Z_ORDER); //add bone btn auto bone_btn_sprite = Sprite::create(btn_bone_res); bone_btn_sprite->setScale(0.8f); auto bone_btn = MenuItemSprite::create(bone_btn_sprite, nullptr, [&](Ref* _bone_btn){ //处理炸弹效果 log("bone released ......"); //can shake auto j = JumpBy::create(0.5f, Vec2::ZERO, 5, 5); this->runAction(j); auto config = Config::getInstance(); //remove enemy and bullet for (auto bullet : *config->enemy_bullet_list) { bullet->boneDestory(); } for (auto enemy : *config->enemy_list) { //effect it log("effect it ......"); enemy->boneDestory(this); } config->enemy_bullet_list->clear(); config->enemy_list->clear(); }); auto menue = Menu::create(bone_btn, NULL); menue->setPosition(Vec2(35, 200)); this->addChild(menue, BTN_BACK_Z_ORDER); menue->runAction(Kit::creatEaseSineInOut(100.0f)); //add back btn auto btn_sprite = Sprite::createWithTexture(Director::getInstance()->getTextureCache()->addImage(btn_back_res)); btn_sprite->setColor(Color3B(0, 245, 255)); auto btn_back = MenuItemSprite::create(btn_sprite, nullptr, [&](Ref* item){ auto menuSprite = (MenuItemSprite*)item; auto scale = ScaleBy::create(0.2f, 1.1); auto jumpToGameLevel = CallFunc::create([](){ auto config=Config::getInstance(); if (config->getmusicState()) SimpleAudioEngine::getInstance()->stopBackgroundMusic();// 停止当前背景音乐 if (config->getmusicState()) { SimpleAudioEngine::getInstance()->playBackgroundMusic(main_bg_stage1, true); } Director::getInstance()->replaceScene(TransitionFade::create(1.2f, GameLevelLayer::creatScene())); }); //call back std::function<void()> releaseResources = [&](){ this->releaseR(); }; menuSprite->runAction(Sequence::create(CallFunc::create(releaseResources), scale, scale->reverse(), jumpToGameLevel, NULL)); }); menue = Menu::create(btn_back, NULL); auto btn_back_position = VisibleRect::rightBottom(); offset = btn_sprite->getContentSize().width / 2; menue->setPosition(Vec2(btn_back_position.x - 50, btn_back_position.y + 25)); this->addChild(menue, BTN_BACK_Z_ORDER); menue->runAction(Kit::creatEaseSineInOut(100.0f)); //添加敌机 this->schedule(schedule_selector(GameScene::addEnemy), 2.0f, kRepeatForever, 1.2f); this->scheduleUpdate(); //初始化地图移动 this->scheduleOnce(schedule_selector(GameScene::initMoveMap), 1.2f); return true; }
/* * Construct a new genxWriter */ genxWriter genxNew(void * (* alloc)(void * userData, int bytes), void (* dealloc)(void * userData, void * data), void * userData) { genxWriter w; genxNamespace xml; if (alloc) w = (genxWriter) (*alloc)(userData, sizeof(struct genxWriter_rec)); else w = (genxWriter) malloc(sizeof(struct genxWriter_rec)); if (w == NULL) return NULL; w->status = GENX_SUCCESS; w->alloc = alloc; w->dealloc = dealloc; w->userData = userData; w->sequence = SEQUENCE_NO_DOC; if (initPlist(w, &w->namespaces) != GENX_SUCCESS || initPlist(w, &w->elements) != GENX_SUCCESS || initPlist(w, &w->attributes) != GENX_SUCCESS || initPlist(w, &w->prefixes) != GENX_SUCCESS || initPlist(w, &w->stack) != GENX_SUCCESS) return NULL; if ((w->status = initCollector(w, &w->arec.value)) != GENX_SUCCESS) return NULL; if ((w->empty = copy(w, (utf8) "")) == NULL) { w->status = GENX_ALLOC_FAILED; return NULL; } w->xmlnsEquals = declareAttribute(w, NULL, (utf8) "xmlns", NULL, &w->status); if (w->xmlnsEquals == NULL || w->status != GENX_SUCCESS) return NULL; w->defaultNsDeclared = False; w->nextPrefix = 1; genxSetCharProps(w->xmlChars); w->etext[GENX_SUCCESS] = "Success"; w->etext[GENX_BAD_UTF8] = "Bad UTF8"; w->etext[GENX_NON_XML_CHARACTER] = "Non XML Character"; w->etext[GENX_BAD_NAME] = "Bad NAME"; w->etext[GENX_ALLOC_FAILED] = "Memory allocation failed"; w->etext[GENX_BAD_NAMESPACE_NAME] = "Bad namespace name"; w->etext[GENX_INTERNAL_ERROR] = "Internal error"; w->etext[GENX_DUPLICATE_PREFIX] = "Duplicate prefix"; w->etext[GENX_SEQUENCE_ERROR] = "Call out of sequence"; w->etext[GENX_NO_START_TAG] = "No Start-tag for EndElement call"; w->etext[GENX_IO_ERROR] = "I/O error"; w->etext[GENX_MISSING_VALUE] = "Missing attribute value"; w->etext[GENX_MALFORMED_COMMENT] = "Malformed comment body"; w->etext[GENX_MALFORMED_PI] = "?> in PI"; w->etext[GENX_XML_PI_TARGET] = "Target of PI matches [xX][mM][lL]"; w->etext[GENX_DUPLICATE_ATTRIBUTE] = "Same attribute specified more than once"; w->etext[GENX_ATTRIBUTE_IN_DEFAULT_NAMESPACE] = "Attribute cannot be in default namespace"; w->etext[GENX_DUPLICATE_NAMESPACE] = "Declared namespace twice with different prefixes on one element."; w->etext[GENX_BAD_DEFAULT_DECLARATION] = "Declared a default namespace on an element which is in no namespace"; /* the xml: namespace is pre-wired */ xml = genxDeclareNamespace(w, (utf8) "http://www.w3.org/XML/1998/namespace", (utf8) "xml", &w->status); if (xml == NULL) return NULL; xml->declCount = 1; xml->declaration = xml->defaultDecl; return w; }