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