cocos2d-x by Example Beginner's Guide 第5章 Rocket Through
来源:互联网 发布:考试软件大全下载 编辑:程序博客网 时间:2024/05/16 05:28
废话少说,先上游戏截图。
游戏里有几个重要的地方。
1.向量知识。
2.橡皮筋线的绘制。
3.粒子系统。
void LineContainer::draw(){ switch (_lineType) { case LINE_NONE: break; case LINE_TEMP: ccDrawColor4F(1.0F, 1.0F, 1.0F, 1.0F); ccDrawLine(_tip, _pivot); ccDrawCircle(_pivot,10,CC_DEGREES_TO_RADIANS(360),10,false); break; case LINE_DASHED: ccDrawColor4F(1.0F, 1.0F, 1.0F, 1.0F); ccDrawCircle(_pivot, 10, M_PI, 10, false); {//复合语句 int segments = _lineLength / (_dash + _dashSpace); float t = 0.0F; float x_,y_; float dt = 1.0F / segments; for (int i = 0; i < segments; i++) { x_ = _pivot.x + t * (_tip.x - _pivot.x); y_ = _pivot.y + t * (_tip.y - _pivot.y); ccDrawCircle(ccp(x_,y_), 4, M_PI, 6, false); t += dt; } } break; default: break; } //画能量条 ccDrawColor4F(0.0F, 0.0F, 0.0F, 1.0F); ccDrawLine(ccp(_energyLineX, _screenSize.height * 0.1F), ccp(_energyLineX, _screenSize.height * 0.1F)); ccDrawColor4F(1.0F, 0.5F, 0.0F, 1.0F); ccDrawLine(ccp(_energyLineX, _screenSize.height * 0.1F), ccp(_energyLineX, _screenSize.height * 0.1F + _energy * _energyHeight));}
最重要的部分
void GameLayer::update(float dt) { if (!_running) { return ; } CCPoint rocketPos = _rocket->getPosition(); if (_lineContainer->getLineType() != LINE_NONE) { _lineContainer->setTip(rocketPos); } //检测是否与边缘发生碰撞,若碰消线 if (_rocket->collideWithSides()) { _lineContainer->setLineType(LINE_NONE); } _rocket->update(dt); //尾部火焰 if (!_jet->isActive()) { _jet->resetSystem(); } _jet->setRotation(_rocket->getRotation()); _jet->setPosition(rocketPos); //更新 timers _cometTimer += dt; float newY; if (_cometTimer > _cometInterval) { _cometTimer = 0; if (!_comet->isVisible()) { _comet->setPositionX(0); newY = (float) rand()/ ((float)RAND_MAX/_screenSize.height * 0.6F) + _screenSize.height * 0.2F; if (newY > _screenSize.height * 0.9F) { newY = _screenSize.height * 0.9F; } _comet->setPositionY(newY); _comet->setVisible(true); _comet->resetSystem();//要不要和上面的一句交换一下位置//? } } if (_comet->isVisible()) { //comet碰撞 CCPoint cometPos = _comet->getPosition(); if (pow(cometPos.x - rocketPos.x, 2) + pow(cometPos.y - rocketPos.y, 2) <= pow(_rocket->getRadius(), 2)) { if (_rocket->isVisible()) { killPlayer(); } } _comet->setPositionX(cometPos.x + 50 * dt); if (_comet->getPositionX() > _screenSize.width * 1.5F) { _comet->stopSystem(); _comet->setVisible(false); } } // _lineContainer->update(dt); _rocket->setOpacity(_lineContainer->getEnergy() * 255);#ifdef DEBUG CCLog("_lineContainer->getEnergy():%f",_lineContainer->getEnergy()); CCLog("_rocket->getOpacity():%f",_rocket->getOpacity());#endif //行星碰撞 GameSprite* planet; CCPoint planetPos; int planetCount = _planets->count(); for (int i = 0; i < planetCount; i++) { planet = (GameSprite *)_planets->objectAtIndex(i); planetPos = planet->getPosition(); if (pow(planetPos.x - rocketPos.x ,2) + pow(planetPos.y - rocketPos.y,2) <= pow(_rocket->getRadius() * 0.8F + planet->getRadius() * 0.65F, 2)) { if (_rocket->isVisible()) { killPlayer(); } break; } } // 星星 CCPoint starPos = _star->getPosition(); if (pow(starPos.x - rocketPos.x, 2) + pow(starPos.y - rocketPos.y, 2) <= pow(_rocket->getRadius() * 1.2F,2) ) { _pickup->setPosition(starPos); _pickup->resetSystem(); if (_lineContainer->getEnergy() + 0.25F < 1) { _lineContainer->setEnergy(_lineContainer->getEnergy() + 0.25F); } else { _lineContainer->setEnergy(1.0F); } _rocket->setSpeed(_rocket->getSpeed() + 2); _lineContainer->setEnergyDecrement(0.001F); SimpleAudioEngine::sharedEngine()->playEffect("pickup.wav"); resetStar(); int points = 100 - _timeBetweenPickups; points = MAX(0, points); _score += points; char szValue[60] = {0}; sprintf(szValue, "%i",_score); _scoreDisplay->setString(szValue); _timeBetweenPickups = 0; } _timeBetweenPickups += dt; if (_lineContainer->getEnergy() == 0) {//float类型 可以和 0 比较相等 if (_rocket->isVisible()) { killPlayer(); } } }
0 0
- cocos2d-x by Example Beginner's Guide 第5章 Rocket Through 之 粒子系统
- cocos2d-x by Example Beginner's Guide 第5章 Rocket Through
- Cocos2d-x by Example Beginner's Guide
- cocos2d-x 粒子系统例子 Rocket Through
- Nginx: Beginner’s Guide
- Cisco: A Beginner's Guide, Fourth Edition (Beginner's Guide
- WAP: A Beginner's Guide
- Objective-C Beginner's Guide
- PHP: A BEGINNER'S GUIDE
- PHP: A BEGINNER'S GUIDE
- PHP: A BEGINNER'S GUIDE
- AJAX: A Beginner's Guide
- AJAX: A Beginner's Guide
- Magento书籍: Beginner’s Guide
- Ogre1.7 Beginner's guide
- Objective-c Beginner's Guide
- 《MooTools 1.2 Beginner's Guide》
- web:nginx Beginner’s Guide
- 怎样成为java软件工程师?
- 2013年的总结
- 将系统/硬盘数据整体迁移到SSD上
- Hadoop实战实例
- ZooKeeper 典型的应用场景
- cocos2d-x by Example Beginner's Guide 第5章 Rocket Through
- centos 中安装好apache 后 外网是访问不了的,得设置 iptables
- 谁有产品分类的代码,发一个分享一下
- 客户的真正需求
- ASP探测用户发送的字节总数
- Json转换利器Gson
- The most useful Windows CMD commands reference
- 由懒汉式单例模式谈懒加载
- iOS事件传递机制(二)