Beispiel #1
0
void GameEngine::render() const
{	
	// HAUKAP - game engine shouldn't be rendering.  
	//				CGfxOpenGL::render() should take a list of renderables and render them
	
	Status stat = m_background->render();
	assert(StatusSucceeded(stat));

	GameObjects objects = m_levelObjects->getObjectsInPortal();
	CHUint sz = (CHUint)objects.size();
	for( CHUint i=0; i<sz; ++i )
   {
		stat = objects[i]->render();
      assert(StatusSucceeded(stat));
   }

	stat = m_mainCharacter->render();
	assert(StatusSucceeded(stat));

	sz = (CHUint)g_projectiles.size();
	for( CHUint i=0; i<sz; ++i )
   {
		stat = g_projectiles[i]->render();
      assert(StatusSucceeded(stat));
   }   
}
Beispiel #2
0
void GameEngine::initializePostMenu()
{
   OggPlayer* bgMusic = OggController::getOggPlayer(g_bgMusicHandle);
   bgMusic->play();

	m_levelObjects->startLevel();

	GameObjects objects = m_levelObjects->getAllObjects();
	CHUint sz = (CHUint)objects.size();
	for( CHUint i=0; i<sz; ++i )
      m_objectScroller->addObject( objects[i] );   
}
Beispiel #3
0
void
GameEngine::objectCleanup()
{
   if(m_mainCharacter->isMarkedForRemoval())
   {
      if(m_mainCharacter->canRespawn())
      {
         m_mainCharacter->respawn();
         m_mainCharacter->decrementLife();
      }
      else
		{
			m_levelObjects->restartLevel();
         m_objectScroller->clear();
         
	      GameObjects objects = m_levelObjects->getAllObjects();
	      CHUint sz = (CHUint)objects.size();
	      for( CHUint i=0; i<sz; ++i )
            m_objectScroller->addObject( objects[i] );   

         m_mainCharacter->gainLives(3);
         m_mainCharacter->respawn();
		}
   }

   for( std::vector<Projectile*>::iterator iter = g_projectiles.begin();
        iter != g_projectiles.end();
        ++ iter )
	{
		if((*iter)->isMarkedForRemoval())
		{
         g_projectiles.erase(iter);
         if( g_projectiles.empty() )
            break;
         else
            iter = g_projectiles.begin();
		}
	}
}
Beispiel #4
0
void 
GameEngine::resolveCollisions()
{
	std::vector<AICharacter*> enemies;
	std::vector<ForegroundObject*> terrain;
	
	GameObjects objects = m_levelObjects->getObjectsInPortal();
	CHUint sz = (CHUint)objects.size();
	for(CHUint i=0; i<sz; ++i)
	{
		if(objects[i]->collidableType() == Collidable::CollidableTerrain)
			terrain.push_back(dynamic_cast<ForegroundObject*>(objects[i]));
		else if(objects[i]->collidableType() == Collidable::CollidableCharacter)
			enemies.push_back(dynamic_cast<AICharacter*>(objects[i]));
	}

	CHUint numTerrain = (CHUint)terrain.size();
	for(CHUint i=0; i<numTerrain; ++i)
	{
		if(m_mainCharacter->collidedWith( *(terrain[i]) ) )
		{
			m_mainCharacter->resolveCollision( *(terrain[i]) );
			terrain[i]->resolveCollision( *m_mainCharacter );
		}

      CHUint numEnemies = (CHUint)enemies.size();
      for(CHUint j=0; j<numEnemies; ++j)
      {
		   if(terrain[i]->collidedWith( *(enemies[j]) ))
		   {
			   terrain[i]->resolveCollision( *(enemies[j]) );
			   enemies[j]->resolveCollision( *(terrain[i]) );
		   }
      }		

		CHUint numProjectiles = (CHUint)g_projectiles.size();
      for(CHUint j=0; j<numProjectiles; ++j)
      {
         if(g_projectiles[j]->collidedWith( *m_mainCharacter ))
		   {
			   g_projectiles[j]->resolveCollision( *m_mainCharacter );
			   m_mainCharacter->resolveCollision( *(g_projectiles[j]) );
		   }
      }		
	}

	CHUint numEnemies = (CHUint)enemies.size();
	for(CHUint i=0; i<numEnemies; ++i )
	{
		if(m_mainCharacter->collidedWith( *(enemies[i]) ) )
		{
			m_mainCharacter->resolveCollision( *(enemies[i]) );
			enemies[i]->resolveCollision( *m_mainCharacter );
		}
	

		CHUint numProjectiles = (CHUint)g_projectiles.size();
      for(CHUint j=0; j<numProjectiles; ++j)
      {
		   if(g_projectiles[j]->collidedWith( *(enemies[i]) ))
		   {
			   g_projectiles[j]->resolveCollision( *(enemies[i]) );
			   enemies[i]->resolveCollision( *(g_projectiles[j]) );
		   }
      }		
	}


}
Beispiel #5
0
void GameEngine::process()
{   
	m_levelObjects->process();

   processCamera();
	Status stat = m_mainCharacter->process();
	assert(StatusSucceeded(stat));
   
	GameObjects objects = m_levelObjects->getObjectsInPortal();
	CHUint sz = (CHUint)objects.size();
	for( CHUint i=0; i<sz; ++i )
   {
      if(objects[i]->isEnemy())
      {
         ScribbleEnemy* enemy = dynamic_cast<ScribbleEnemy*>( objects[i] );
         if(enemy->isBoss())
         {
            g_boss = dynamic_cast<Level1Boss*>( enemy );
         }
      }

		stat = objects[i]->process();
      assert(StatusSucceeded(stat));
   }

   if(!bossMusicPlaying && g_boss != NULL)
   {
      OggController::getOggPlayer(g_bgMusicHandle)->stop();
      OggController::getOggPlayer(g_bossMusicHandle)->play();
      bossMusicPlaying = true;
   }

	sz = (CHUint)g_projectiles.size();
	for( CHUint i=0; i<sz; ++i )
   {
		stat = g_projectiles[i]->process();
      assert(StatusSucceeded(stat));
   }
	
   resolveCollisions();
   objectCleanup();

   m_objectScroller->process();

	// ensure Hero stays on screen
	Vector3 mainPos(m_mainCharacter->position());
	if(mainPos.x < m_boundaryLeft)
	{
		mainPos.x = m_boundaryLeft;
		m_mainCharacter->setPosition(mainPos); 
	}
   else if( mainPos.x > m_boundaryRight )
   {
      mainPos.x = m_boundaryRight;
      m_mainCharacter->setPosition(mainPos);
   }
   if(mainPos.y < -12.0f)
   {
      m_mainCharacter->setVelocity( Vector3(0.0f, 0.0f, 0.0f) );
      m_mainCharacter->setPosition( mainPos.x, -12.0f, 0.0f);
   }
}