// AI_run() is called by DEFCON during every game update cycle (every 100ms) extern "C" bool AI_run() { m_bot.Update(); return true; }
void GameEngine::Update(float dt) { if (gameover) return; handleInput(); // simulate physics m_world->Step(dt, 8, 3); // update entity bot.Update(); // update game scenario elapsedTime = glutGet(GLUT_ELAPSED_TIME) - initializedTime; long additionalBullets = elapsedTime / 2000; if (m_bulletCount < MAX_BULLET_COUNT + additionalBullets) { createBullet(); } typedef std::list<b2Body*> BodyList; BodyList::iterator end = m_bullets.end(); for (BodyList::iterator it = m_bullets.begin(); it != end; ++it) { b2Body* bullet = *it; const b2Vec2& pos = bullet->GetPosition(); if (pos.x < 0 || pos.x > m_stage.upperBound.x || pos.y < 0 || pos.y > m_stage.upperBound.y) { --m_bulletCount; m_bullets.erase(it); continue; } } if (bot.GetState() == BOT_STATE_DEAD) { // stop the world gameover = true; #ifdef _WIN32 PlaySound(TEXT("scifi011.wav"), NULL, SND_ASYNC); #endif } }