Exemple #1
0
void g_loop()
{
	int frame = 0;
	int startTime;
	int endTime;

	while ( !game.exitGameYet )
	{
		startTime = SDL_GetTicks();
		//get time passed since last loop and see if enough time has passed for another update (target = 60 fps)
		//take note of the current time (for next loop around)
		
		
		//handle input, this should do nothing more then set values on objects (like tetrominos) so they know what to do next
		g_handleInput();
		
		//update the game (moving, scoring, menu seletion etc). this should look at the values set by g_handleInput() and update accordingly
		g_updateGame();
		
		//update the display with latest updated data clear the screen and redraw everything
		g_drawGame();
		frame++;
		//printf("frame %d\n", frame);
		
		endTime = SDL_GetTicks() - startTime;
		
		if ( endTime < (ONE_SECOND / TARGET_FRAME_RATE) )
			SDL_Delay( (ONE_SECOND / TARGET_FRAME_RATE) - endTime );
			
	}
	g_end(); //exit to dos
}
static void g_check_complete_square(square_s *square)
{
	if (square->owner != NONE) return;

	if (square->owner_up == NONE) return;
	if (square->owner_right == NONE) return;
	if (square->owner_down == NONE) return;
	if (square->owner_left == NONE) return;
	
	// current player own the square
	square->owner = local_player.turn;

	++player[local_player.turn].score;
	--squares_remaining;

	if (!squares_remaining) g_end();
}