尊重开发者的劳动成果,转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/17324915
<捕鱼达人>回顾
【cocos2d-x IOS游戏开发-捕鱼达人1】内容介绍
上节回顾
【cocos2d-x IOS游戏开发-城市跑酷12】男一号上场,大家鼓掌!
提示,就是一步步的操作:
改变主角状态,停止所有动作,提示下一条,玩家操作之后继续改变。
因为游戏运行起来之后,一直处于主界面:点击新游戏,或点击游戏提示;
需要等待玩家选择,所以在GameLayer::update()里面更新。
先定义一组游戏状态:
typedef enum { kGameIntro,//游戏介绍 kGamePlay,//开始游戏 kGameOver,//游戏结束 kGameTutorial,// kGameTutorialJump,// kGameTutorialFloat,// kGameTutorialDrop// } GameState;当游戏的状态是>提示状态时,就一步步的在玩家操作之后做相应的操作;
if (_state > kGameTutorial) { if (_state == kGameTutorialJump) { if (_player->getState() == kPlayerFalling && _player->getVector().y < 0) { _player->stopAllActions(); _jam->setVisible(false); _jam->stopAllActions(); _running = false; _tutorialLabel->setString("While in the air, tap the screen to float."); _state = kGameTutorialFloat; } } else if (_state == kGameTutorialFloat) { if (_player->getPositionY() < _screenSize.height * 0.95f) { _player->stopAllActions(); _running = false; _tutorialLabel->setString("While floating, tap the screen again to drop."); _state = kGameTutorialDrop; } } else { _tutorialLabel->setString("That's it. Tap the screen to play."); _state = kGameTutorial; } }
同时更新主角状态:
//更新主角状态 _player->update(dt); _terrain->move(_player->getVector().x); //检查碰撞冲突 if (_player->getState() != kPlayerDying) _terrain->checkCollision(_player); //放置主角 _player->place(); if (_player->getNextPosition().y > _screenSize.height * 0.6f) { _gameBatchNode->setPositionY( (_screenSize.height * 0.6f - _player->getNextPosition().y) * 0.8f); } else { _gameBatchNode->setPositionY ( 0 ); } //update paralax if (_player->getVector().x > 0) { //一直往左移 _background->setPositionX(_background->getPosition().x - _player->getVector().x * 0.25f); float diffx; //移完一个宽度时,重新把位置设置为接近0的位置 if (_background->getPositionX() < -_background->getContentSize().width) { diffx = fabs(_background->getPositionX()) - _background->getContentSize().width; _background->setPositionX(-diffx); } _foreground->setPositionX(_foreground->getPosition().x - _player->getVector().x * 4); if (_foreground->getPositionX() < -_foreground->getContentSize().width * 4) { diffx = fabs(_foreground->getPositionX()) - _foreground->getContentSize().width * 4; _foreground->setPositionX(-diffx); } int count = _clouds->count(); CCSprite * cloud; for (int i = 0; i < count; i++) { cloud = (CCSprite *) _clouds->objectAtIndex(i); cloud->setPositionX(cloud->getPositionX() - _player->getVector().x * 0.15f); if (cloud->getPositionX() + cloud->boundingBox().size.width * 0.5f < 0 ) cloud->setPositionX(_screenSize.width + cloud->boundingBox().size.width * 0.5f); } }