Exemplo n.º 1
0
void Level00::VInitialize()
{
	mState = BASE_SCENE_STATE_INITIALIZING;

	VOnResize();

	InitializeLevel();
	InitializeGrid();
	InitializeRobots();
	InitializeGeometry();
	InitializeWallShaders();
	InitializeLightShaders();
	InitializePlayerShaders();
	InitializeCamera();

	mState = BASE_SCENE_STATE_RUNNING;
}
Exemplo n.º 2
0
void Game::Run()
{
	XmlParser parser("settings/Players.xml");
	PlayerType playerType = (PlayerType)parser.ReadInt("/PlayerData/PlayerOneType");
	u32 keybinds[4] = { CL_KEY_LEFT, CL_KEY_RIGHT, CL_KEY_UP, CL_KEY_J };

	Initialize();
	InitializeLevel();	
	InitializePlayer(playerType, keybinds);

	s32 timeElapsedMs, lastTime, currentTime, waitTime;
	currentTime = lastTime = CL_System::get_time();

	// Main game loop
	while(!m_quit) {
		//Calculate the elapsed time since the beginning of the last frame
		currentTime = CL_System::get_time();
		timeElapsedMs = currentTime - lastTime;
		if (timeElapsedMs > 50)	{
			//Guard to ensure that the frame time isn't too long
			timeElapsedMs = 50;
		}
		lastTime = currentTime;
		
		//Update the game state
		m_level->Update();
		m_updateSignal.invoke(timeElapsedMs);	
		m_drawSignal.invoke();
		
		// Flip the display, showing on the screen what we drew since last call to flip()
		m_window.flip(0);

		//Measure the time for this frame's update
		waitTime = 16 - (CL_System::get_time() - currentTime);
		if (waitTime < 0) {
			waitTime = 0;
		}

		// This call processes user input and other events
		CL_KeepAlive::process(0);

		// Sleep for a little while to avoid using too much of the CPU.
		CL_System::sleep(waitTime);		
	}
}
Exemplo n.º 3
0
void GameServer::Run()
{
	XmlParser parser("settings/Players.xml");
	PlayerType playerType = (PlayerType)parser.ReadInt("/PlayerData/PlayerOneType");
	u32 keybinds[4] = { CL_KEY_LEFT, CL_KEY_RIGHT, CL_KEY_UP, CL_KEY_J };

	Initialize();
	InitializeLevel();
	InitializePlayer(playerType, keybinds);
	InitializeNetwork();

	s32 timeElapsedMs, lastTime, currentTime, waitTime;
	currentTime = lastTime = CL_System::get_time();

	// Main game loop
	while (!m_quit) {
		//Calculate the elapsed time since the beginning of the last frame
		currentTime = CL_System::get_time();
		timeElapsedMs = currentTime - lastTime;
		if (timeElapsedMs > 50)	{
			//Guard to ensure that the frame time isn't too long
			timeElapsedMs = 50;
		}
		lastTime = currentTime;

		m_frameCounter++;

		m_incomingMessages.clear();
		m_outgoingMessages.clear();

		while (true) {
			MessageData packet;
			u32 bytes_read = m_connection.ReceivePacket(packet.data, sizeof(packet.data));
			if (bytes_read == 0) {
				break;
			}
			m_incomingMessages.push_back(packet);
		}

		std::vector<MessageData>::iterator it = m_incomingMessages.begin();
		for (; it != m_incomingMessages.end(); ++it) {
			ProcessMessage((*it).data);
		}

		//Update the game state
		m_level->Update();
		m_updateSignal.invoke(timeElapsedMs);
		m_drawSignal.invoke();

		// Flip the display, showing on the screen what we drew since last call to flip()
		m_window.flip(0);
		
		ComposeUpdateMessage();

		if ((m_frameCounter % 6) == 0) {
			ComposeSyncMessage();
		}
		
		if (m_outgoingMessages.size() > 0) {
			std::vector<MessageData>::iterator it = m_outgoingMessages.begin();
			for (; it != m_outgoingMessages.end(); ++it)
			{
				m_connection.SendPacket((*it).data, (*it).size);
			}
		}		

		//Measure the time for this frame's update
		waitTime = 16 - (CL_System::get_time() - currentTime);
		if (waitTime < 0) {
			waitTime = 0;
		}

		// This call processes user input and other events
		CL_KeepAlive::process(0);

		// Sleep for a little while to avoid using too much of the CPU.
		CL_System::sleep(waitTime);
	}
}
Exemplo n.º 4
0
void GameActions(const int frameTicks)
{
	//Start playing the music if it isn't already started
	if(Mix_PlayingMusic() == 0)
	{
		Mix_FadeInMusic(allMusic[(int)musicType], -1, 200);
	}
	if(currentLevel == 0)
	{
		if(playingMode == constants::Waiting)
		{
			//Start the game
			currentLevel = 1;
			levelStartTicks = 0;
			levelEndTicks = 0;
		}
	}
	else if(currentLevel <= gameLevels.levelsCount)
	{		
		if(levelStartTicks == 0)
		{
			//Initialize the level
			playingMode = constants::Playing;
			levelStartTicks = frameTicks;
			levelEndTicks = 0;
			InitializeLevel(currentLevel - 1);
		}
		if(playingMode == constants::Playing)
		{
			if(!player.isAlive)
			{
				//Queue the death music
				if(Mix_PlayingMusic() == 1)
				{
					Mix_FadeOutMusic(30);
				}
				musicType = constants::Death;

				//Game over when the player is killed
				playingMode = constants::GameOver;
				levelEndTicks = frameTicks;
			}
			if(!IsEnemyAlive())
			{
				//End the level when the last enemy is killed
				playingMode = constants::EndOfLevel;
				levelEndTicks = frameTicks;
			}
		}
		else if(playingMode == constants::GameOver)
		{
			//Wait a couple seconds after game over to reset
			if (frameTicks - levelEndTicks > 5000)
			{
				ResetGame();
			}
		}
		if(playingMode == constants::EndOfLevel && frameTicks - levelEndTicks > 2000)
		{
			//Pause before starting the next level
			currentLevel++;
			levelStartTicks = 0;
		}
	}
	else
	{
		if(playingMode != constants::GameCompleted)
		{
			//Queue the victory music!
			if(Mix_PlayingMusic() == 1)
			{
				Mix_FadeOutMusic(30);
			}
			musicType = constants::Victory;

			//When all the levels are done, the game is over
			playingMode = constants::GameCompleted;
			levelStartTicks = 0;
			levelEndTicks = frameTicks;
		}
		else if (frameTicks - levelEndTicks > 5000)
		{
			//Reset the game after a few seconds
			ResetGame();
		}
	}
}