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


C++ world::checkSpriteCollision方法代码示例

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


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

示例1: movePersonOrWorld

void movePersonOrWorld(int &xCord, int &yCord, int &direction) { //This function checks to see which direction you are planning for your character or world to move in, according to your arrow keys. It then checks to see if there are any collisions, or space bar events, and if not, it updates your new position. 
	if(dbUpKey()==1)
		{
			direction = 1;
			if(dbSpriteFrame(1) < 13) //If our frame for the character is not within its proper regions (In this case, is on a frame that's below our up animation):
			{
				dbSetSpriteFrame(1,13); //Set the first sprite frame to 13, so we can play through the upwards animation correctly.
			}

			if(dbShiftKey() == 1)
			{
				dbPlaySprite(1, 13, 16, 75); //play through our animations (from 13 to 16) with a 75 millisecond delay since we're running.
				if(house.checkSpriteCollision(xCord,yCord-3) == 0) 
				{
					yCord -= 3;
				}
			}
			else
			{
				dbPlaySprite(1, 13, 16, 150); //play through our animations (from 13 to 16) with a 150 millisecond delay because we're walking.
				if(house.checkSpriteCollision(xCord,yCord-1) == 0) 
				{
					yCord --;
				}
			}
		}
		else if(dbDownKey()==1)
		{
			direction = 2; //we set our direction variable to 2, which represents the downward motion.
			if(dbSpriteFrame(1) > 4) //Like before, if our sprite 1 frame is out of its desired regions, then set it to the correct location.
			{
				dbSetSpriteFrame(1, 4);
			}

			if(dbShiftKey() == 1)
			{
				dbPlaySprite(1, 1, 4, 75);
				if(house.checkSpriteCollision(xCord,yCord+3) == 0) 
				{
					yCord += 3;
				}
			}
			else
			{
				dbPlaySprite(1, 1, 4, 150);
				if(house.checkSpriteCollision(xCord,yCord+1) == 0) 
				{
					yCord ++;
				}
			}
		}
		else if(dbLeftKey()==1)
		{
			direction = 3; //Set our variable to 3 which represents leftward motion.
			if(dbSpriteFrame(1) < 5 || dbSpriteFrame(1) > 8)
			{
				dbSetSpriteFrame(1,5);
			}
			if(dbShiftKey() == 1)
			{
				dbPlaySprite(1, 5, 8, 75);
				if(house.checkSpriteCollision(xCord-3,yCord) == 0) 
				{
					xCord -= 3;
				}
			}
			else
			{
				dbPlaySprite(1, 5, 8, 150);
				if(house.checkSpriteCollision(xCord-1,yCord) == 0) 
				{
					xCord --;
				}
			}
		}
		else if(dbRightKey()==1)
		{
			direction = 4; //Set our variable to 4 which represents rightward motion.
			if(dbSpriteFrame(1) < 9 || dbSpriteFrame(1) > 12)
			{
				dbSetSpriteFrame(1,9);
			}
			if(dbShiftKey() == 1)
			{
				dbPlaySprite(1, 9, 12, 75);
				if(house.checkSpriteCollision(xCord+3,yCord) == 0) 
				{
					xCord += 3;
				}
			}
			else
			{
				dbPlaySprite(1, 9, 12, 150);
				if(house.checkSpriteCollision(xCord+1,yCord) == 0) 
				{
					xCord ++;
				}
			}
		}
		if(dbKeyState(57) == 1){ //If we pressed the space bar, check to see if we have an event associated with that object.
//.........这里部分代码省略.........
开发者ID:ChrisMcNealy,项目名称:Game-Structure,代码行数:101,代码来源:Main.cpp


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