工作总结6(随时修改)

战斗:

1.触摸层:

	_hotZone = LayerColor::create(Color4B(128,128,128));
	_hotZone->setPosition(Vec2(600,0));  //由于本游戏要求子弹不能向后射,所以位置设置在这
	_hotZone->setTouchEnabled(true);
	_hotZone->setContentSize(visibleSize);
	addChild(_hotZone,0);
2单点触摸

	/**单点触摸**/
	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
	listener->setSwallowtouches(true);
	listener->onTouchBegan = CC_CALLBACK_2(Battle::onPress,this);
	listener->onTouchMoved = CC_CALLBACK_2(Battle::onMove,this);
	listener->onTouchEnded = CC_CALLBACK_2(Battle::onRelease,this);
	_eventdispatcher->addEventListenerWithSceneGraPHPriority(listener,this);
	_eventdispatcher->setPriority(listener,1);//第二个参数是优先级,数值越小优先级越高
3. 事件侦听

	EventListenerCustom* bossShootListener = EventListenerCustom::create(BOSS_SHOOT,CC_CALLBACK_1(Battle::bossShoot,this));
	_eventdispatcher->addEventListenerWithFixedPriority(bossShootListener,1);
4. 碰撞

1).子弹与士兵的碰撞

版本1:

	Vector<Bullet*>::iterator itb = _bulletVec.begin();
	while (itb != _bulletVec.end())
	{
		Bullet* itbullet = (*itb);
		Vector<Soldier*>::iterator its = _soldierVec.begin();
		bool flag = false;
		while (its != _soldierVec.end())
		{
			Soldier* itsoldier = (*its);
			if (itsoldier->hit(itbullet->getPosition()))
			{
                <span style="white-space:pre">		</span>flag = true;		
				int Nowlife = itsoldier->hurt();
				if (Nowlife <= 0)
				{
					itsoldier->die();
					its = _soldierVec.erase(its);
				}
				itbullet->resetBullet();
				itb = _bulletVec.erase(itb);
				break;
			}
			else
			{
				its++;
			}
		}
		if (!flag)
		{
			++itb;
		}
	}
版本2:

	for (Node* a : _bulletVec)
	{
		Bullet* bullet = (Bullet*)a;
		Rect bulletRect = bullet->getRect();
		for (Node* b : _soldierVec)
		{
			Soldier* soldier = (Soldier*)b;
			Rect soldierRect = soldier->getRect();
			if (bulletRect.intersectsRect(soldierRect))
			{
				if (!bullet->getHurtObj())
				{					
					if (soldier->hurt(bullet->getdamage()))//在hurt函数中判断是否死亡
					{
						bullet->setHurtObj(soldier);
						_soldierVec.eraSEObject(soldier);
						return;
					}			
					bullet->setHurtObj(soldier);
				}
				else
				{
					if (bullet->getHurtObj() != soldier)
					{
						if (soldier->hurt(bullet->getdamage()))
						{
							_soldierVec.eraSEObject(soldier);
						}
						bulletBoom(bullet);  //爆炸效果
						return;
					}
				}
			}
		}
	}
2)子弹和boss碰撞(与上述的类似)

	for (Node* a : _bulletVec)
	{
		Bullet* bullet = (Bullet*)a;
		Rect bulletRect = bullet->getRect();
		for (Node* b : _bossvec)
		{
			Boss* boss = (Boss*)b;
			Rect bossRect = boss->getRect();
			if (bulletRect.intersectsRect(bossRect))
			{
				if (boss->hurt(bullet->getdamage()))
				{
					_bossvec.eraSEObject(boss);
				}
				bulletBoom(bullet);
				_bulletVec.eraSEObject(bullet);
				return;
			}
		}
	}
3)地方子弹与武将碰撞

	for (Node* a : _enemyBulletVec)
	{
		Bullet* bullet = (Bullet*)a;
		Rect bulletRect = bullet->getRect();

		Rect bossRect = _general->getRect();
		if (bulletRect.intersectsRect(bossRect))
		{
			_general->hurt(bullet->getdamage());
			bulletBoom(bullet);
			_enemyBulletVec.eraSEObject(bullet);
			return;
		}
	}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...