当前位置: 首页>>代码示例>>C++>>正文


C++ Npc::setPos方法代码示例

本文整理汇总了C++中Npc::setPos方法的典型用法代码示例。如果您正苦于以下问题:C++ Npc::setPos方法的具体用法?C++ Npc::setPos怎么用?C++ Npc::setPos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Npc的用法示例。


在下文中一共展示了Npc::setPos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: collisionHandling

void GamePlay::collisionHandling()
{

	//!Collision between npcs and player
	std::vector<Npc>::iterator npcit;
	int counter;
	counter = 0;
	if(numberOfNpc != 0) //!< if npc's still exist
	{
		for(npcit = npc.begin(); npcit != npc.end();)
		{
			if(collision.AABBvsAABB(player, *npcit)) //!< if there is a collision between player and the npc
			{
				collision.collisionNormal(player,*npcit); //!< calculate collision normal
				if(npcit->getPowerUPNum() == 0) //!< if the NPC is an enemy
				{
					if(player.getNormal().getY() == -1)//!< if player lands on top of npc
					{
						collision.resolve(player, *npcit); //!< resolve collision
					}else{
						lives = lives-1; //!< reduce lives by 1
						player.setBuff(1, false); //!< remove player buffs
						player.setBuff(2, false); //!< remove player buffs
						backgroundMusic.setPitch(1.f); //!< change pitch of music back
						player.setPos(Vector2D(370.f,480.f)); //!< reset position of player
						mainView.setCenter(player.getPos().getX(), player.getPos().getY() - 150); //!< set screen center on player
					}
					if(npcit->getNormal().getY() == 1 && npcit->getPowerUPNum() != 1) //!< if the npc's normal is 1
					{
						player.setVel(Vector2D(player.getVel().getX(), -30.f)); //!< make player bounce a little bit
						npcit = npc.erase(npc.begin() + counter); //!< erase npc from vector
						score += 50; //!< increase score by 50
						--numberOfNpc;
					}else{
						++npcit;
					}
				}
				if(npcit->getPowerUPNum() == 1) //!< if the NPC is a shroom
				{
					npcit = npc.erase(npc.begin() + counter);
					score += 50;
					--numberOfNpc;
					coinSound.play();
					backgroundMusic.setPitch(1.3f);
					player.setBuff(1, true);
					
				}
			
			}
			else {++npcit;}
		
			++counter;
		}
	}
	//! if the player falls down
	if(player.getPos().getY() > 500) 
	{
		lives = lives-1; //!< reduce lives by 1
		player.setPos(Vector2D(370.f,460.f)); //!< reset players position
		mainView.setCenter(player.getPos().getX(), player.getPos().getY() - 150); //!< set screen center on player
		player.setBuff(1, false); //!< remove player buffs
		player.setBuff(2, false); //!< remove player buffs
		backgroundMusic.setPitch(1.f); //!< change pitch of music back
	}

	//collision between level and player
	std::vector<Block>::iterator it2;
	std::vector<std::vector<Block>>::iterator it;
	for(it = blocks.begin(); it != blocks.end();++it)
	{
		for(it2 = it->begin(); it2 != it->end();)
		{
			if(collision.AABBvsAABB(player,*it2) == true) //!< If player has collided with a block
			{
					collision.collisionNormal(player, *it2); //!< calculate the collision normal
					collision.resolve(player, *it2);		//!< resolve the collision
					if(it2->getNormal().getY() == -1 && it2->getDestroyable() == true) //!< if the player bounced ontop and the block is destroyable
					{
						if(it2->getHits() == 0) //!< and the blocks hits left is 0
						{
							it2 = it->erase(it2); //!< erase  block
							score = score + 25; //!< grand 25 score
							blockBreakSound.play();
						}else{
							score = score + 25;
							coinSound.play();
							it2->setHits(it2->getHits()-1); //!< else reduce hits by 1
						}
					}
					if(it2->getNormal().getY() == -1 && it2->getSpecial() == true) //!< if player hits from underneat on a special block
					{
						if(it2->getHits() != 0)
						{
						
							it2->setBlock(5, it2->getPos().getX(), it2->getPos().getY(), usedBlockTexture); //!< change block to be used
							score = score + 25; //!< increase score
							powerUpBlockSound.play();
							Npc tempPowerUP;
							tempPowerUP.randPowerUp(shroomText);
							tempPowerUP.setPos(Vector2D(it2->getPos().getX() + 10, it2->getPos().getY() - 30));
//.........这里部分代码省略.........
开发者ID:manisoftwartist,项目名称:2Dplatformer-Dave,代码行数:101,代码来源:GamePlay.cpp


注:本文中的Npc::setPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。