CAStage* TSWorld::createStage(const char* _name) { GUARD_FUNCTION(); string name = _name; CAStage* ps = NULL; if (name == _stage_play) { GUARD_FIELD(stage_play); ps = new TSStagePlay(_name); } else if (name == _stage_logo) { GUARD_FIELD(stage_logo); ps = new TSStageLogo(_name); } /* else if (name == _stage_menu) { GUARD_FIELD(stage_menu); ps = new TSStageMenu(_name); } else if (name == _stage_help) { GUARD_FIELD(stage_help); ps = new TSStageHelp(_name); } else if (name == _stage_options) { GUARD_FIELD(stage_options); ps = new TSStageOptions(_name); } else if (name == _stage_credits) { GUARD_FIELD(stage_credits); ps = new TSStageCredits(_name); } */ else if (name == _stage_test) { GUARD_FIELD(stage_test); ps = new TSStageTest(_name); } return ps; }
/* 这里生成的 sprite 是全局的,可能任何Stage, 任何Layer都会使用。 这里不对他们的坐标等具象化东西进行初始化。 */ CASprite* TSWorld::createSprite(CAStageLayer* player, const char* _name) { GUARD_FUNCTION(); CASprite* pspr = null; string name = _name; //if (player->stage()->name() == _stage_play) { //if (player->name() == _layer_game) { if (name == "player") { GUARD_FIELD(player); pspr = new TSSpritePlayer(player, name.c_str()); } /* else if (name == "bubble") { GUARD_FIELD(bubble); pspr = new TSSpriteBubble(player, name.c_str()); } */ else if (name.find("button") == 0 || 0) { GUARD_FIELD(bubble); pspr = new TSSpriteButton(player, name.c_str()); } else { GUARD_FIELD(common_sprite); pspr = new TSSpriteCommon(player, name.c_str()); //_Assert(false); } } } //_Trace("sprite [%s] created, p=%p", name.c_str(), pspr); return pspr; }
void BZStagePlayLayerGamePlay::onStateBegin(CAState* from, void* param) { GUARD_FUNCTION(); const string& fname = from->getFullName(); _state = fname; if (0) ; else if (CAString::startWith(fname, "root.idle")) //_onStateBeginIdle(from); { GUARD_FIELD(field); //this->setIsVisible(false); _NullGetters(); removeAllTimelines(); } else if (CAString::startWith(fname, "root.create")) //_onStateBeginFadein(from); { GUARD_FIELD(field); //this->stage()->resetTimer(); //this->stage()->setOffset(ccp(0, 0), 0); activeAllTimelines(); } else if (CAString::startWith(fname, "root.fadein")) //_onStateBeginFadein(from); { GUARD_FIELD(root_fadin); _InitGetters(); string strScore = _settings.getString("score_spr"); float fScoreScale = _settings.getFloat("score_scale"); CCPoint ptScore = _settings.getPoint("score_pos"); CAWorld::percent2view(ptScore); CCSize sizeScore = _settings.getSize("score_size"); CAWorld::percent2view(sizeScore); string strLevel = _settings.getString("level_spr"); float fLevelScale = _settings.getFloat("level_scale"); CCPoint ptLevel = _settings.getPoint("level_pos"); CAWorld::percent2view(ptLevel); CCSize sizeLevel = _settings.getSize("level_size"); CAWorld::percent2view(sizeLevel); _score = new BZGroupNumber(this, strScore); _score->setLayout(+1, ptScore, sizeScore, fScoreScale); _score->setChangeType(NCM_Near, NCO_Left); _level = new BZGroupNumber(this, strLevel); _level->setLayout(+1, ptLevel, sizeLevel, fLevelScale); _level->setChangeType(NCM_Near, NCO_Left); _pstage->setFocus(this); } else if (CAString::startWith(fname, "root.levelup")) { GUARD_FIELD(field); //stage()->setOffset(CCPointZero, 0); } else if (CAString::startWith(fname, "root.running")) //_onStateBeginRunning(from); { GUARD_FIELD(field); _initGame(); } else if (fname == "root.pause") { GUARD_FIELD(field); CAStageLayer* pl = this->getSubLayer("game.play.pause"); _Assert(pl); pl->setConditionResult("*****@*****.**", true); _pstage->setFocus(pl); pause(); } else if (CAString::startWith(fname, "root.restart")) { GUARD_FIELD(field); resume(); if (null != _pgame) { _pgame->release(); _pgame = null; } CAWorld::sharedWorld().gameenv().setString("how", "newgame"); _pstage->setFocus(this); } else if (CAString::startWith(fname, "root.quit")) { GUARD_FIELD(field); //wait plPause's state in idle //_pstage->setFocus(this); resume(); if (null != _pgame) { _pgame->release(); _pgame = null; } //_initGame(); this->_playerParent->onEvent(new CAEventCommand(this, "play.finished")); } else if (CAString::startWith(fname, "root.resume")) { GUARD_FIELD(field); //wait plPause's state in idle _pstage->setFocus(this); resume(); } else if (CAString::startWith(fname, "root.save_quit")) { GUARD_FIELD(field); resume(); if (null != _pgame) { _pgame->saveData(); _pgame->release(); _pgame = null; } //_initGame(); this->_playerParent->onEvent(new CAEventCommand(this, "play.finished")); } else if (CAString::startWith(fname, "root.over")) { GUARD_FIELD(field); //show game over message //save record here } else if (CAString::startWith(fname, "root.fadeout")) { GUARD_FIELD(field); //show fadeout effects //transite to idle if (_score) { _score->release(); _score = null; } if (_level) { _level->release(); _level = null; } } else ; };
CAStageLayer* TSWorld::createLayer(CAStage* pstage, CAStageLayer* playerParent, const char* _name) { GUARD_FUNCTION(); string name = ""; if (playerParent) { // name += playerParent->name(); } name += _name; if (pstage->name() == _stage_play) { if (name == _layer_game) { GUARD_FIELD(layer_game); return new TSStagePlayLayerGame(pstage, playerParent); } else if (name == _layer_game_prepare) { GUARD_FIELD(layer_game_prepare); return new TSStagePlayLayerGamePrepare(pstage, playerParent); } else if (name == _layer_game_prepare_quit) { GUARD_FIELD(layer_game_prepare_quit); return new TSStagePlayLayerGamePrepareQuit(pstage, playerParent); } else if (name == _layer_game_play) { GUARD_FIELD(layer_game_play); return new TSStagePlayLayerGamePlay(pstage, playerParent); } else if (name == _layer_game_shop) { GUARD_FIELD(layer_game_shop); return new TSStagePlayLayerGameShop(pstage, playerParent); } else if (name == _layer_game_play_pause) { GUARD_FIELD(layer_game_play_pause); return new TSStagePlayLayerGamePlayPause(pstage, playerParent); } /* else if (name == _layer_game_background) { GUARD_FIELD(layer_back); return new TSStagePlayLayerGameBackground(pstage, playerParent); } else if (name == _layer_game_doodads1) { GUARD_FIELD(layer_doodads1); return new TSStagePlayLayerGameDoodads1(pstage, playerParent); } else if (name == _layer_game_play_dialog) { GUARD_FIELD(layer_game_play_dialog); return new TSStagePlayLayerGamePlayDialog(pstage, playerParent); } else if (name == _layer_game_doodads2) { GUARD_FIELD(layer_doodads2); return new TSStagePlayLayerGameDoodads2(pstage, playerParent); } */ else { _Assert(false); } } else if (pstage->name() == _stage_logo) { if (name == _layer_logo) { GUARD_FIELD(layer_logo); return new TSStageLogoLayerMain(pstage, playerParent); } } /* else if (pstage->name() == _stage_menu) { if (name == _layer_menu) { GUARD_FIELD(layer_menu); return new TSStageMenuLayerMain(pstage, playerParent); } } else if (pstage->name() == _stage_help) { if (name == _layer_help) { GUARD_FIELD(layer_help); return new TSStageHelpLayerMain(pstage, playerParent); } } else if (pstage->name() == _stage_options) { if (name == _layer_options) { GUARD_FIELD(layer_options); return new TSStageOptionsLayerMain(pstage, playerParent); } } else if (pstage->name() == _stage_credits) { if (name == _layer_credits) { GUARD_FIELD(layer_credits); return new TSStageCreditsLayerMain(pstage, playerParent); } } */ else if (pstage->name() == _stage_test) { if (name == _layer_test) { GUARD_FIELD(layer_test); return new TSStageTestLayerTest(pstage, playerParent); } else if (name == _layer_test_bubbles) { GUARD_FIELD(layer_test_bubbles); return new TSStageTestLayerTestBubbles(pstage, playerParent); } } _Assert(false); return NULL; }