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


C++ Entities::AddEntity方法代码示例

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


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

示例1: Mouse

//=======================================================================
// Mouse Function
//=======================================================================
void Mouse(int button, int state, int x, int y)
{
	y = glutGet(GLUT_WINDOW_HEIGHT) - y;

	if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		Vector dirVector = Vector(x,y) - Vector(WIDTH/2, HEIGHT/2);

		float dirVectorMag = sqrtf((dirVector.x * dirVector.x) + (dirVector.y * dirVector.y));

		Vector normalizedDir = dirVector/dirVectorMag;

		Entity *bullet = new Entity(WIDTH/2, HEIGHT/2, normalizedDir, BULLET);

		bulletsList.AddEntity(bullet);

		Vector shipUp(0,1);

		float dotProduct = (dirVector.x * shipUp.x) + (dirVector.y * shipUp.y);

		float cosAngle = dotProduct / (shipUp.Magnitude() * dirVector.Magnitude()) ;

		float angle = acos(cosAngle) * 180.f / PI;

		x > WIDTH/2 ? shipRotation = -angle : shipRotation = angle;
	}
}
开发者ID:MohamedIsmailHafez,项目名称:Space-Shooter,代码行数:30,代码来源:main_Old.cpp

示例2: SpawnEnemies

//=======================================================================
// Random Enemy Location Function
//=======================================================================
void SpawnEnemies(int)
{
	Vector startlocation = GetRandomPosOffScreen();
	int level;
	(((int)startlocation.x + (int)startlocation.y) % 2) == 0 ? level = 0 : level = 1;
	Enemy *enemy = new Enemy(startlocation.x, startlocation.y, Vector(), ENEMY, startlocation, level);
	EnemyList.AddEntity(enemy);

	glutTimerFunc(1000.0/Difficulty, SpawnEnemies, 0);
}
开发者ID:MohamedIsmailHafez,项目名称:Space-Shooter,代码行数:13,代码来源:main_Old.cpp


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