先是敌机与玩家子弹的碰撞检测:
代码:
GameLayer.h
void GameLayer::update(float dt) { for (int i = 0 ;i < m_pEnermyVec.size();i++) { Sprite * pEne = m_pEnermyVec.at(i) ; for (int j = 0 ; j < m_pPlayerBullet.size();j++ ) { Sprite * pBul = m_pPlayerBullet.at(j) ; if (pEne->getBoundingBox().intersectsRect(pBul->getBoundingBox())) { pEne->stopAllActions() ; pBul->stopAllActions() ; pEne->runAction(Sequence::create(FadeOut::create(0.5f),RemoveSelf::create(true),nullptr)) ; pBul->runAction(RemoveSelf::create(true)) ; m_pEnermyVec.eraseObject(pEne) ; m_pPlayerBullet.eraseObject(pBul) ; i-- ; j-- ; } } } }
这样游戏逻辑的基本功能就写完了,后面主要会研究下弹幕。
源码:http://pan.baidu.com/s/1bntWUC3
只有Class和Resource
时间: 2024-11-10 05:28:32