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


C++ Collision::ResolveCollisionEnemy方法代码示例

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


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

示例1: main


//.........这里部分代码省略.........
	float t = 0.0f;
	float dt = 0.01f;

	float prevTime =(float) glfwGetTime();
	float accumulator = 0.0f;

	Collision *collide = new Collision();
	

	bool hit = false;
	bool hit2 = false;
	int i;
	while (!glfwWindowShouldClose(window))
	{

		_update_fps_counter(window);

		float newTime =(float) glfwGetTime();
		float deltaTime = (float)(newTime - prevTime);
		

		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		glViewport(0, 0, g_gl_width, g_gl_height);


		if (deltaTime > 0.25f)
			deltaTime = 0.25f;
		prevTime = newTime;

		accumulator += deltaTime;

		while (accumulator >= dt)
		{
			// update logic pentru player
			PlayerEntity.Update(dt);

			// update animatie
			CSpriteManager::Get()->Update(dt);

			//update enemies
			int nr = 0;
			for (int i = 0; i < number_of_enemy; i++)
			{
				if (enemies[i]->life>0){
					vec[i].Update(dt, nr);
				}
			}
			t += dt;
			accumulator -= dt;
		}

		// desenare
		CSpriteManager::Get()->Draw();

		//verificare coliziune intre player si inamic
		for ( i = 0; i< number_of_enemy; i++)
		{
			collide->ResolveCollisionPlayer(playerSprite,enemies[i]);
			if (collide->getStatusPlayer() == true){
				if (playerSprite->life>=0){
					CSpriteManager::Get()->RemoveSprite(lives[lives.size() - 1]->index);
					lives.erase(lives.end() - 1);
				}
				

			}



			//verificare coliziune intre player si proiectile inamici
			vec[i].Collide(playerSprite, collide);

			if (playerSprite->life == 0){
				playerSprite->SetPosition(glm::vec3(-5.0f, -5.0f, playerSprite->GetPosition().z));
			}

			if (enemies[i]->life == 0){
				enemies[i]->life = 2;
			}

		}


		//verificare coliziune intre inamic si proiectilul player-ului
		collide->ResolveCollisionEnemy(CSpriteManager::Get()->projectiles, enemies );

		glfwPollEvents();
		glfwSwapBuffers(window);

		if (GLFW_PRESS == glfwGetKey(window, GLFW_KEY_ESCAPE))
		{
			glfwSetWindowShouldClose(window, 1);
		}

	}

	delete collide;
	glfwTerminate();
	return 0;
}
开发者ID:BiancaTud,项目名称:Ubisoft,代码行数:101,代码来源:Main.cpp


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