您的位置:首页 > 博客中心 > 前端开发 >

cocos2d-x 我要入门——微信打飞机(9)

时间:2022-04-06 11:01

这是前段时间完成的了,一直没总结起来

因为刚好3.0横空出世,重新安装vs2013,cocos2dx3.0 ,cocoStudio……

也是想把飞机移植到手机上,遇到了很多问题,用什么方法移植,一直想在myeclipse里安装ADT插件,用于创建安卓项目,卸载安装出错卸载安装出错,那两天就是这么过来的。后来还是简单粗暴地解决了安卓环境的问题,直接下载集成ADT的eclipse。但还是在创建项目时候出错了。至今未果。(当然也是恶心了太多天了,我暂且放下,结果,沉没在各种作业当中,也沉浸在各种即将和好友见面的期待中,各种没抵挡住,面壁自省中。。。)

废话不说,先把我在偶尔教程中自己添加的那一部分总结出来。


我是在游戏中,增加了两个模式:普通模式和无敌模式(灵感出于舍友说有没有不死的飞机)

用枚举类型,创建两个常量 ISSTRONG NOTSTRONG

GameLayer.h

enum Strong
{
	ISSTRONG,
	NOTSTRONG,
};


在Welcome界面设置2个Menu

gxlsystem.com,布布扣

(= =自己画的)


在Welcome.h中

	static Strong getStrong(); //用于获取传递过来的常量值
	static Strong isStrong; 

Welcome.cpp

Strong WelcomeLayer::getStrong()
{
	return isStrong;
}


点击普通模式,传递的就是NOTSTRONG

void WelcomeLayer::normalPlane(CCObject* pSender)
{
	isStrong = NOTSTRONG;
	CCScene* pSence = GameScene::create();
	CCTransitionMoveInB* animateScene=CCTransitionMoveInB::create(1.0f,pSence);
	CCDirector::sharedDirector()->replaceScene(animateScene);
}
点击无敌模式

void WelcomeLayer::strongPlane(CCObject* pSender)
{
	isStrong = ISSTRONG;
	CCScene* pSence = GameScene::create();
	CCTransitionMoveInB* animateScene=CCTransitionMoveInB::create(1.0f,pSence);
	CCDirector::sharedDirector()->replaceScene(animateScene);
}


然后在对飞机的碰撞检测中,判断在Welcome界面点击的哪个模式,传递的是哪个值,来进行碰撞与否。

在GameLayer.cpp中

	switch (WelcomeLayer::getStrong())
	{
	case NOTSTRONG:
		//enemy1&airplane checkcollosion
		CCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy1, et)
		{
			Enemy* enemy1 = (Enemy*)et;
			if (enemy1->getLife() > 0)
			{
				if (airplaneRect.intersectsRect(enemy1->getBoundingBox()))
				{
					this->unscheduleAllSelectors();
					this->bulletLayer->StopShoot();
					this->mutiBulletLayer->StopShoot();
					this->planeLayer->Blowup(score);
					return;
				}
			}
		}
		//enemy2&airplane checkcollosion
		CCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy2, et)
		{
			Enemy* enemy2 = (Enemy*)et;
			if (enemy2->getLife() > 0)
			{
				if (airplaneRect.intersectsRect(enemy2->getBoundingBox()))
				{
					this->unscheduleAllSelectors();
					this->bulletLayer->StopShoot();
					this->mutiBulletLayer->StopShoot();
					this->planeLayer->Blowup(score);
					return;
				}
			}
		}
		//enemy3&airplane checkcollosion
		CCARRAY_FOREACH(this->enemyLayer->m_pAllEnemy3, et)
		{
			Enemy* enemy3 = (Enemy*)et;
			if (enemy3->getLife() > 0)
			{
				if (airplaneRect.intersectsRect(enemy3->boundingBox()))
				{
					this->unscheduleAllSelectors();
					this->bulletLayer->StopShoot();
					this->mutiBulletLayer->StopShoot();
					this->planeLayer->Blowup(score);
					return;
				}
			}
		}
		break;
	case ISSTRONG:
		break;
	}
主要是当飞机和敌机不进行碰撞检测的时候,就是飞机无敌的时候。


gxlsystem.com,布布扣





cocos2d-x 我要入门——微信打飞机(9),布布扣,bubuko.com

本类排行

今日推荐

热门手游