void BZStageCommon::onEnter() { GUARD_FUNCTION(); CAStage::onEnter(); if (_debug_info) { CCSize size = CAWorld::getScreenSize(); size.width *= 0.9f; #if defined(_DEBUG) size.height = 18 * 9; #else size.height = 18 * 4; #endif //_pInfo = CCLabelTTF::labelWithString(" ", size, kCCTextAlignmentLeft, "Arial", 16); _pInfo = CCLabelTTF::create(" ", "Arial", 18.0f, size, kCCTextAlignmentLeft); _pInfo->setAnchorPoint(ccp(0.0f, 0.0f)); _pInfo->setPosition( ccp(0, 20) ); _pInfo->setVertexZ(99); ccColor3B cc; cc.r = 255; cc.g = 0; cc.b = 0; _pInfo->setColor(cc); _pInfo->setOpacity(0x9b); this->addChild(_pInfo, 10000); _pInfo->retain(); } }
/// Game BZGame::BZGame(CAStageLayer* player) : BZBoard(player) { GUARD_FUNCTION(); _name = "na"; _nCounter = 0; _nScore = 0; _typesCount = 0; if (_typesCount < BLOCK_TYPES) _types[_typesCount++] = "bubble_a"; else _Assert(false); if (_typesCount < BLOCK_TYPES) _types[_typesCount++] = "bubble_b"; else _Assert(false); if (_typesCount < BLOCK_TYPES) _types[_typesCount++] = "bubble_c"; else _Assert(false); if (_typesCount < BLOCK_TYPES) _types[_typesCount++] = "bubble_d"; else _Assert(false); if (_typesCount < BLOCK_TYPES) _types[_typesCount++] = "bubble_e"; else _Assert(false); //_types[_typesCount++] = "bird"; _nGameStatesCount = 0; memset(_oldGameStates, 0, sizeof(_oldGameStates)); setState(GS_Idle); _timeLastBorn = 0; //_VerifyClass(this); }
void BZStagePlayLayerHome::onStateBegin(CAState* from, void* param) { GUARD_FUNCTION(); const string& fname = from->getFullName(); if (0) ; else _HANDLE_STATE(idle, if (_bFirstRun) { this->setConditionResult("*****@*****.**", true); _bFirstRun = false; }) else _HANDLE_STATE(mode_fadein, (void)0)
void BZSpriteButton::_setAnimateState(EAnimateState s) { GUARD_FUNCTION(); _animateState = s; if (BS_Idle == s) { _touchState = TS_None; } _Debug("button %s -> %d", this->getModName().c_str(), s); }
BZBubble* BZGame::_onUpdateBlock(BZBlock* pblock) { GUARD_FUNCTION(); pblock->onUpdate(); if (_canBoom(pblock)) { return pblock->booom(); } return null; }
BZStagePlayLayerGamePlay::BZStagePlayLayerGamePlay(CAStage* pstage, CAStageLayer* playerParent) : CAStageLayer(pstage, playerParent) { GUARD_FUNCTION(); _Trace("%s allocated", __FUNCTION__); _nScore = -1; _nLevel = 0; _pgame = null; _pgame = null; _score = null; _level = null; _NullGetters(); }
void BZSpriteButton::onTouched(CAEventTouch* pEvent) { if (!_bEnabled) return; GUARD_FUNCTION(); switch (pEvent->state()) { case kTouchStateGrabbed: _Debug("button %s touch grabbed", this->getModName().c_str()); if (_animateState == BS_Idle || _animateState == BS_Animated) { _Debug("button %s press", this->getModName().c_str()); _touchState |= TS_Down; _setAnimateState(BS_Animating); setState(ButtonPose_Pressed, true); CASpriteModelPose* ppose = this->getCurrentPose(); if (ppose->name() != ButtonPose_Pressed) { _onPressedAnimationFinished(); } } else if (_animateState == BS_Animating) { //do nothing } break; case kTouchStateUngrabbed: _Debug("button %s touch ungrabbed", this->getModName().c_str()); if (_animateState == BS_Idle) { } else if (_animateState == BS_Animating) { _Debug("button %s touch up flag", this->getModName().c_str()); _touchState |= TS_Up; } else if (_animateState == BS_Animated) { _Debug("button %s touch end, onclick", this->getModName().c_str()); if (_bEnabled) _onClick(); } break; } }
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 BZGame::loadData() { GUARD_FUNCTION(); string str = CAUserData::sharedUserData().getString(_name.c_str()); size_t len = str.length(); len = (len + 16) * 3 / 4; unsigned char* pb = new unsigned char[len]; unsigned int olen = CAString::str2bin(str, pb, len); _Assert(olen <= len); CADataBuf buf(pb, len); delete [] pb; ccTime time; buf >> str; _Assert(str == "1.0"); buf >> str; _Assert(str == _name); buf >> time; _timeLastBorn = this->getTimeNow() - time; buf >> _lastBubble; //buf >> _nLevel; buf >> _nScore; //_Assert(null != _pboard); BZBoard::loadData(buf); }
void BZGame::createBoard(const CCPoint& ptBoardAnchor, int rows, int cols, float bubblesize) { GUARD_FUNCTION(); BZBoard::setParams(ptBoardAnchor, rows, cols, bubblesize); }
void BZStagePlayLayerGamePlay::onEnter() { GUARD_FUNCTION(); CAStageLayer::onEnter(); }
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; }