Пример #1
0
void retro_run(void)
{
   input_poll_cb();

   ks1.up     = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
   ks1.right  = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
   ks1.down   = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
   ks1.left   = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
   ks1.start  = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
   ks1.select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
   ks1.a      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
   ks1.b      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
   ks1.x      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
   ks1.y      = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);

   ks2.up     = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP);
   ks2.right  = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT);
   ks2.down   = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN);
   ks2.left   = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT);
   ks2.start  = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START);
   ks2.select = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT);
   ks2.a      = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A);
   ks2.b      = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B);
   ks2.x      = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
   ks2.y      = input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);

   render_game();
}
Пример #2
0
int main( int argc, char *argv[] )
{
    GLFWwindow* window;

    /*
    Setting error callback to receive any errors during
    initialization
    */
    glfwSetErrorCallback(error_callback);

    /*
    Initialize library
    */
    if( !glfwInit() ) {
        return( -1 );
        }

    /*
    Create a windowed mode window and its OpenGL context
    */
    window = glfwCreateWindow( WINDOW_WIDTH, WINDOW_HEIGHT, "Hello World", NULL, NULL );
    if( !window ) {
        glfwTerminate();
        return( -1 );
        }

    /*
    Make the window's context current
    */
    glfwMakeContextCurrent( window );

    /*
    Initialize game state
    */
    init_game_state( &game_ctrl );

    /*
    Set key callback to receive key events
    */
    glfwSetKeyCallback(window, key_callback);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        update_game_state( &game_ctrl );
        render_game( &game_ctrl );

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }
    
    glfwDestroyWindow(window);
    glfwTerminate();
    return( 0 );
}
Пример #3
0
JNIEXPORT void JNICALL Java_com_intel_deferredgles_JNIWrapper_frame(JNIEnv * env, jobject obj)
{
    update_game(_game);
    render_game(_game);

    UNUSED_PARAMETER(env);
    UNUSED_PARAMETER(obj);
}
Пример #4
0
int
	main(
		int argc,
const char ** argv
	)
{
	int width = 64;
	int height = 64;

	ledscape_config_t * config = &ledscape_matrix_default;
	if (argc > 1)
	{
		config = ledscape_config(argv[1]);
		if (!config)
			return EXIT_FAILURE;
	}

	if (config->type == LEDSCAPE_MATRIX)
	{
		config->matrix_config.width = width;
		config->matrix_config.height = height;
	}

	ledscape_t * const leds = ledscape_init(config, 0);

	printf("init done\n");
	time_t last_time = time(NULL);
	unsigned last_i = 0;

	unsigned i = 0;
	uint32_t * const p = calloc(width*height,4);

	render_game(p);

	i++;
	ledscape_draw(leds, p);

	usleep(20000);

	// wait for the previous frame to finish;
	//const uint32_t response = ledscape_wait(leds);
	const uint32_t response = 0;
	time_t now = time(NULL);
	if (now != last_time)
	{
		printf("%d fps. starting %d previous %"PRIx32"\n",
		i - last_i, i, response);
		last_i = i;
		last_time = now;
	}

	printf("init done\n");
	ledscape_close(leds);

	return EXIT_SUCCESS;
}
Пример #5
0
int main()
{
    //shell vars
    bool render = false;

    //allegro vars
    ALLEGRO_DISPLAY *display = NULL;
    ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    ALLEGRO_TIMER *timer = NULL;

    //allegro init functions
    printf ("Initializing allegro\n");
    if (!al_init())
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Creating display\n");
    display = al_create_display(WIDTH, HEIGHT);
    if (!display)
    {
        al_show_native_message_box(NULL, NULL, NULL, "failed", NULL, 0);
        return -1;
    }

    printf("Installing addons\n");
    al_init_font_addon();
    al_init_ttf_addon();
    al_init_primitives_addon();
    al_init_image_addon();
    al_install_keyboard();
    al_install_mouse();
    al_install_audio();
    al_init_acodec_addon();
    al_reserve_samples(10);

    //project inits
    srand(time(NULL));

    printf("Initializing timer\n");
    event_queue = al_create_event_queue();
    timer = al_create_timer(1.0 / FPS);

    printf("Registering event sources\n");
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_start_timer(timer);

    printf("Init mouse and keyboard\n");
    init_keyboard();
    init_mouse();

    printf("Loading assets\n");
    load_bitmaps();
    load_fonts();
    load_samples();

    printf ("Creating manager\n");
    push_state(new TitleMenu());
    
    printf("Beginning game\n");
    while (!is_game_over())
    {
        //declare an event
        ALLEGRO_EVENT event;

        //monitor event sources
        al_wait_for_event(event_queue, &event);
        if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
        {
            end_game();
        }
        else if (event.type == ALLEGRO_EVENT_TIMER)
        {
            render = true;

            update_mouse();
            update_keyboard();

            handle_key();
            update_game();
        }

        // Render screen
        if (render && al_event_queue_is_empty(event_queue))
        {
            render = false;
            render_game();
            al_flip_display();
        }
    }

    unload_assets();
    al_destroy_event_queue(event_queue);
    al_destroy_display(display);
    al_destroy_timer(timer);

    return 0;
}
Пример #6
0
int main(int argc, char *argv[])
{
	int	i;
	char buf[512];
	SDL_Surface	*screen = NULL,
							*message = NULL;
	SDL_PixelFormat fmt;
	TTF_Font *tmp_font;
	SDL_Color text_color_black = {0,0,0};
	SDL_Color text_color_white = {255, 255, 255};
	//Mix_Music *music = NULL;
	//Mix_Chunk *scratch = NULL;
	Uint32 timer_start = 0, timer_last_frame = 0;
	struct game game;
	
	// initialisation
	if(init_game(&game))
		return 1;
	screen = SDL_GetVideoSurface();
	fmt = *(screen->format);
	///////////////
	// main loop //
	///////////////
	timer_start = SDL_GetTicks();
	timer_last_frame = SDL_GetTicks();
	
	while(!game.quit)
	{
		// update time
		game.timer_delta = ((double)(SDL_GetTicks() - (double)timer_last_frame) / 1000);
		timer_last_frame = SDL_GetTicks();
		
		///////////
		// Input //
		///////////
		read_input(&game);
		
		///////////
		// Logic //
		///////////
		if(game.finished)
		{
			//game.menu = MAPBROWSER;
			sscanf(game.map, "%d", &i);
			i++;
			sprintf(game.map, "%d", i);
			
			game.reset = 1;
			game.update = 1;
			game.finished = 0;
		}
		
		// Ingame
		if(game.menu == INGAME)
		{
			if(!game.paused || game.reset)
			{
				if(game.pause_screen)
					game.pause_screen = 0;
			
				// reset game
				if(game.reset)
				{
					if(!load_map(&game))
					{
						printf("Invalid map!\n");
						game.menu = MAINMENU;
					}
					game.reset = 0;
					game.paused = 0;
					game.update = 1;
					game.moves = 0;
					game.keys = 0;
				}
				
				// loop through all objects
				for(i=0; i<game.num_objects; i++)
				{
					// save old position
					game.object[i].x_Prev = game.object[i].x;
					game.object[i].y_Prev = game.object[i].y;
				
					// move object
					move(i, &game);
					
					// configure cursor
					if(!strcmp(game.object[i].type, "player"))
					{
						set_cursor (&game, i);
					}
					
					// check if screen refresh is needed
					if( (int)game.object[i].x != (int)game.object[i].x_Prev ||
							(int)game.object[i].y != (int)game.object[i].y_Prev)
					{
						game.update = 1;
					}
				}
				
				// set camera to player
				for(i=0; i<game.num_objects; i++)
				{
					if(!strcmp(game.object[i].type, "player"))
					{
						game.camera.x = (game.object[i].x + game.object[i].w / 2) - game.screen_width / 2;
						game.camera.y = (game.object[i].y + game.object[i].h / 2) - game.screen_height / 2;
					}
				}
				if(game.camera.x < 0)
					game.camera.x = 0;
				if(game.camera.x + game.camera.w > game.level_width)
					game.camera.x = game.level_width - game.camera.w;
				if(game.camera.y < 0)
					game.camera.y = 0;
				if(game.camera.y + game.camera.h > game.level_height)
					game.camera.y = game.level_height - game.camera.h;
				
			}
		}
		
		// Editor
		else if(game.menu == EDITOR)
		{
			game.num_buttonlist = 0;
			
			if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
				process_buttons(&game);
			
			game.paused = 0;
			if(game.reset)
			{
				if(!game.map[0])// && !game.enter_mapname)
					new_map(&game);
				else
					load_map(&game);

				// remove "player" from toolbox
				// if the map contains a player tile
				game.tool_object[PLAYER].visible = 1;
				for(i=0; i<game.num_objects; i++)
					if(!strcmp(game.object[i].type, "player"))
						game.tool_object[PLAYER].visible = 0;
											
				game.reset = 0;
			}
			set_map_properties(&game);
			scroll_map(&game);
			drag_objects(&game);
			handle_tools(&game);
			if(game.enter_mapname)
				enter_mapname(&game);
			
			if(strcmp(game.map_prev, game.map))
			{
				if(game.save_as)
					SDL_FreeSurface(game.save_as);
				game.save_as = TTF_RenderUTF8_Blended(game.font_yo_frankie, game.map, text_color_white);
				strcpy(game.map_prev, game.map);
				game.update = 1;
			}
		}
		
		// Mainmenu
		else if(game.menu == MAINMENU)
		{
			game.num_buttonlist = 0;
			
			if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
				process_buttons(&game);
			
			// reset cursor
			for(i=1; i<5; i++)
			{
				game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0;
				game.mouse.clip[i].x = 0;  game.mouse.clip[2].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0;
				game.mouse.point_dir = 0;
			}
		}
		
		// Mapbrowser
		else if(game.menu == MAPBROWSER)
		{
			process_list(&game);
			// reset cursor
			for(i=1; i<5; i++)
			{
				game.mouse.clip[i].x = 0; game.mouse.clip[1].y = 0;
				game.mouse.clip[i].x = 0;  game.mouse.clip[2].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[3].y = 0;
				game.mouse.clip[i].x = 0; game.mouse.clip[4].y = 0;
				game.mouse.point_dir = 0;
			}
		}
		
		if(game.mouse.x_input != game.mouse.x_prev || game.mouse.y_input != game.mouse.y_prev)
		{
			game.mouse.x_prev = game.mouse.x_input;
			game.mouse.y_prev = game.mouse.y_input;
			//if(SDL_GetTicks() % 2 == 0)
				game.update = 1;
		}

		////////////
		// Render //
		////////////
		
		// don't update screen if it is not required
		if(game.update)
		{
			//printf("updating screen\n");
			//SDL_SetAlpha(wall_surface, SDL_SRCALPHA, 0); 
			//printf("%d | %d » %d | %d || %d\n", game.mouse.x_prev, game.mouse.y_prev, game.mouse.x, game.mouse.y, game.mouse.click);
			if(game.menu == INGAME)
			{
				render_game(&game);
				
				message = SDL_CreateRGBSurface(0, 300, 50, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
				SDL_SetAlpha(message, SDL_SRCALPHA, 150);
				SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				apply_surface(0, game.screen_height - message->h, message, screen, NULL);
				SDL_FreeSurface(message);
				
				sprintf(buf, "Moves: %d  Keys: %d", game.moves, game.keys);
				message = TTF_RenderUTF8_Blended(game.font_yo_frankie, buf, text_color_black);
				apply_surface(5, game.screen_height - message->h - 5, message, screen, NULL);
				SDL_FreeSurface(message);
			}
			else if(game.menu == EDITOR)
			{
				render_game(&game);
				/*tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18);
				message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);*/
				render_toolbox(&game);
				render_buttons(&game);
				if(game.enter_mapname)
				{
					i = 450;
					
					if(game.save_as && game.save_as->w > 430)
							i = game.save_as->w + 20;
					
					message = SDL_CreateRGBSurface(0, i, 70, fmt.BitsPerPixel, fmt.Rmask, fmt.Gmask, fmt.Bmask, fmt.Amask);
					SDL_SetAlpha(message, SDL_SRCALPHA, 180);
					SDL_FillRect(message, &message->clip_rect, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00));
					apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2, message, screen, NULL);
					SDL_FreeSurface(message);
					
					message = TTF_RenderUTF8_Blended(game.font_yo_frankie, "Enter Mapname and press Enter", text_color_white);
					apply_surface(game.screen_width / 2 - message->w / 2, game.screen_height / 2 - message->h / 2 - 15, message, screen, NULL);
					if(game.save_as)
						apply_surface(game.screen_width / 2 - game.save_as->w / 2, game.screen_height / 2 - game.save_as->h / 2 + 15, game.save_as, screen, NULL);
				}
			}
			else if(game.menu == MAINMENU)
			{
				SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				render_buttons(&game);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 56);
				message = TTF_RenderUTF8_Blended(tmp_font, "<Lustiger Spielname hier>", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 50, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 18);
				message = TTF_RenderUTF8_Blended(tmp_font, "By Sören Wegener", text_color_black);
				apply_surface(game.screen_width / 2 - message->w / 2, 150, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
				
				tmp_font = TTF_OpenFont("data/fonts/yo_frankie.ttf", 14);
				message = TTF_RenderUTF8_Blended(tmp_font, "Yo Frankie font created by Pablo Vazquez and converted by Mango Jambo using FontForge 2.0", text_color_black);
				apply_surface(0, game.screen_height - message->h, message, screen, NULL);
				TTF_CloseFont(tmp_font);
				SDL_FreeSurface(message);
			}
			else if(game.menu == MAPBROWSER)
			{
				SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));
				render_list(&game);
			}
			
			render_cursor(&game);
						
			// refresh screen
			SDL_Flip(screen);
			game.update = 0;
		}
		
		// needed to prevent 100% CPU usage
		SDL_Delay(0);
	}
	
	cleanup(&game);
	return 0;
}
Пример #7
0
int main(int argc, char** argv)
{
    if(!glfwInit()) {
        error("Failed to intialize GLFW.");
        return 1;
    }

    GLFWwindow* win;
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    win = glfwCreateWindow(800, 600, "Halberd", NULL, NULL);
    if(!win) {
        error("Unable to create window.");
        return 1;
    }
    glfwSetFramebufferSizeCallback(win, sizeCallback);
    glfwMakeContextCurrent(win);

	glewExperimental = 1;
	if(glewInit() != GLEW_OK) {
        error("glewInit() failed.");
        glfwDestroyWindow(win);
        return 1;
    }
    glGetError(); // Because GLEW is silly. <http://stackoverflow.com/questions/20034615/why-does-glewinit-result-in-gl-invalid-enum-after-making-some-calls-to-glfwwin>
    GLuint VAO; // FIXME: Stupid Hack. <http://stackoverflow.com/questions/13403807/glvertexattribpointer-raising-gl-invalid-operation>
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    init_graphics();
    update_camera(800, 600);
    init_input(win);
    init_player(0, 0);
    init_ui();
    init_settings();

    /*init_maps();*/
    // TODO: Figure out the correct way to start up
    /*get_tileset_id("Plains.png");*/
    /*load_maps("test");*/

    float delta = 0;
    glfwSetTime(0);
    do {
        delta = glfwGetTime();
        glfwSetTime(0);
        glfwPollEvents();

        if(!ui_present())
            update_player(delta);
        update_actors(delta);
        update_ui(delta);
        update_input_states(delta);

        render_game();

        glfwSwapBuffers(win);
    } while(!glfwWindowShouldClose(win) && get_input_state(4) != 2);

    destroy_player_actor();
    destroy_actors();
    /*destroy_maps();*/
    destroy_ui();
    destroy_graphics();
    cleanup_settings();

    glfwDestroyWindow(win);
    glfwTerminate();
    return 0;
}
Пример #8
0
int main(int argc, char **argv)
{
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
	{
		APP_LOG << "Failed to initialize SDL: " << SDL_GetError() << '\n';
		return EXIT_FAILURE;
	}

	int window_width = 640;
	int window_height = 480;
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
	SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);

	SDL_Window *window = SDL_CreateWindow(
		"Sample Application",
		SDL_WINDOWPOS_CENTERED,
		SDL_WINDOWPOS_CENTERED,
		window_width, window_height,
		SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);

	if (window == NULL)
	{
		APP_LOG << "Failed to create a window: " << SDL_GetError() << '\n';
		SDL_Quit();
		return EXIT_FAILURE;
	}

	SDL_GLContext gl_context = SDL_GL_CreateContext(window);
	SDL_GL_SetSwapInterval(1); // Wait for vertical refresh

	glewExperimental = true;
	GLenum glew_error = glewInit();
	if (glew_error != GLEW_OK)
	{
		APP_LOG << "Failed to load OpenGL functions: " << glewGetErrorString(glew_error) << '\n';
		SDL_GL_DeleteContext(gl_context);
		SDL_DestroyWindow(window);
		SDL_Quit();
		return EXIT_FAILURE;
	}

	print_debug_info();

	if(!load_game(window_width, window_height))
	{
		APP_LOG << "Failed to load content" << '\n';
		SDL_GL_DeleteContext(gl_context);
		SDL_DestroyWindow(window);
		SDL_Quit();
		return EXIT_FAILURE;
	}

	init_game();
	gui::init(window_width, window_height);	

	uint vao;
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	glViewport(0, 0, window_width, window_height);

	double frame_time = 1.0 / 60.0;
	bool running = true;
	while (running)
	{
		double frame_begin = get_elapsed_time();
		handle_events(running, window);
		gui::update(frame_time);
		update_game(frame_time);
		render_game(frame_time);
		SDL_GL_SwapWindow(window);
		frame_time = get_elapsed_time() - frame_begin;

		if (check_gl_errors())
			running = false;

		if (frame_time < 1.0 / 60.0)
		{
			sleep(1.0 / 60.0 - frame_time);
			frame_time = get_elapsed_time() - frame_begin;
		}
	}

	gui::dispose();
	SDL_GL_DeleteContext(gl_context);
	SDL_DestroyWindow(window);
	SDL_Quit();
	return EXIT_SUCCESS;
}
Пример #9
0
int MENUS::render()
{
    RECT screen = *ui_screen();
	gfx_mapscreen(screen.x, screen.y, screen.w, screen.h);

	static bool first = true;
	if(first)
	{
		if(config.ui_page == PAGE_INTERNET)
			client_serverbrowse_refresh(0);
		else if(config.ui_page == PAGE_LAN)
			client_serverbrowse_refresh(1);
		first = false;
	}
	
	if(client_state() == CLIENTSTATE_ONLINE)
	{
		color_tabbar_inactive = color_tabbar_inactive_ingame;
		color_tabbar_active = color_tabbar_active_ingame;
	}
	else
	{
		render_background();
		color_tabbar_inactive = color_tabbar_inactive_outgame;
		color_tabbar_active = color_tabbar_active_outgame;
	}
	
	RECT tab_bar;
	RECT main_view;

	// some margin around the screen
	ui_margin(&screen, 10.0f, &screen);
	
	if(popup == POPUP_NONE)
	{
		// do tab bar
		ui_hsplit_t(&screen, 24.0f, &tab_bar, &main_view);
		ui_vmargin(&tab_bar, 20.0f, &tab_bar);
		render_menubar(tab_bar);
		
		// news is not implemented yet
		if(config.ui_page <= PAGE_NEWS || config.ui_page > PAGE_SETTINGS || (client_state() == CLIENTSTATE_OFFLINE && config.ui_page >= PAGE_GAME && config.ui_page <= PAGE_CALLVOTE))
		{
			client_serverbrowse_refresh(BROWSETYPE_INTERNET);
			config.ui_page = PAGE_INTERNET;
		}
		
		// render current page
		if(client_state() != CLIENTSTATE_OFFLINE)
		{
			if(game_page == PAGE_GAME)
				render_game(main_view);
			else if(game_page == PAGE_SERVER_INFO)
				render_serverinfo(main_view);
			else if(game_page == PAGE_CALLVOTE)
				render_servercontrol(main_view);
			else if(game_page == PAGE_SETTINGS)
				render_settings(main_view);
		}
		else if(config.ui_page == PAGE_NEWS)
			render_news(main_view);
		else if(config.ui_page == PAGE_INTERNET)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_LAN)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_DEMOS)
			render_demolist(main_view);
		else if(config.ui_page == PAGE_FAVORITES)
			render_serverbrowser(main_view);
		else if(config.ui_page == PAGE_SETTINGS)
			render_settings(main_view);
//		else if(config.ui_page == PAGE_TEE-NG)
//			renger_settings(main_teeng);
	}
	else
	{
		// make sure that other windows doesn't do anything funnay!
		//ui_set_hot_item(0);
		//ui_set_active_item(0);
		char buf[128];
		const char *title = "";
		const char *extra_text = "";
		const char *button_text = "";
		int extra_align = 0;
		
		if(popup == POPUP_MESSAGE)
		{
			title = message_topic;
			extra_text = message_body;
			button_text = message_button;
		}
		else if(popup == POPUP_CONNECTING)
		{
			title = localize("Connecting to");
			extra_text = config.ui_server_address;  // TODO: query the client about the address
			button_text = localize("Abort");
			if(client_mapdownload_totalsize() > 0)
			{
				title = localize("Downloading map");
				str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
				extra_text = buf;
			}
		}
		else if(popup == POPUP_DISCONNECTED)
		{

			title = localize("Disconnected");
			extra_text = client_error_string();
			button_text = localize("Ok");
			extra_align = -1;
		}
		else if(popup == POPUP_PURE)
		{
			title = localize("Disconnected");
			extra_text = localize("The server is running a non-standard tuning on a pure game type.");
			button_text = localize("Ok");
			extra_align = -1;
		}
		else if(popup == POPUP_PASSWORD)
		{
			title = localize("Password Incorrect");
			extra_text = client_error_string();
			button_text = localize("Try again");
		}
		else if(popup == POPUP_QUIT)
		{
			title = localize("Quit");
			extra_text = localize("Are you sure that you want to quit?");
		}
		else if(popup == POPUP_FIRST_LAUNCH)
		{
			title = localize("Welcome to Teeworlds");
			extra_text = localize("As this is the first time you launch the game, please enter your nick name below. It's recommended that you check the settings to adjust them to your liking before joining a server.");
			button_text = localize("Ok");
			extra_align = -1;
		}
		
		RECT box, part;
		box = screen;
		ui_vmargin(&box, 150.0f, &box);
		ui_hmargin(&box, 150.0f, &box);
		
		// render the box
		ui_draw_rect(&box, vec4(0,0,0,0.5f), CORNER_ALL, 15.0f);
		 
		ui_hsplit_t(&box, 20.f, &part, &box);
		ui_hsplit_t(&box, 24.f, &part, &box);
		ui_do_label(&part, title, 24.f, 0);
		ui_hsplit_t(&box, 20.f, &part, &box);
		ui_hsplit_t(&box, 24.f, &part, &box);
		ui_vmargin(&part, 20.f, &part);
		
		if(extra_align == -1)
			ui_do_label(&part, extra_text, 20.f, -1, (int)part.w);
		else
			ui_do_label(&part, extra_text, 20.f, 0, -1);

		if(popup == POPUP_QUIT)
		{
			RECT yes, no;
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			ui_vsplit_mid(&part, &no, &yes);
			
			ui_vmargin(&yes, 20.0f, &yes);
			ui_vmargin(&no, 20.0f, &no);

			static int button_abort = 0;
			if(ui_do_button(&button_abort, localize("No"), 0, &no, ui_draw_menu_button, 0) || escape_pressed)
				popup = POPUP_NONE;

			static int button_tryagain = 0;
			if(ui_do_button(&button_tryagain, localize("Yes"), 0, &yes, ui_draw_menu_button, 0) || enter_pressed)
				client_quit();
		}
		else if(popup == POPUP_PASSWORD)
		{
			RECT label, textbox, tryagain, abort;
			
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			ui_vsplit_mid(&part, &abort, &tryagain);
			
			ui_vmargin(&tryagain, 20.0f, &tryagain);
			ui_vmargin(&abort, 20.0f, &abort);
			
			static int button_abort = 0;
			if(ui_do_button(&button_abort, localize("Abort"), 0, &abort, ui_draw_menu_button, 0) || escape_pressed)
			{
				if(config.cl_autoconnect)
				config.cl_autoconnect == 0;
				else
				popup = POPUP_NONE;
			}

			static int button_tryagain = 0;
			if(ui_do_button(&button_tryagain, localize("Try again"), 0, &tryagain, ui_draw_menu_button, 0) || enter_pressed)
			{
				client_connect(config.ui_server_address);
			}
			
			ui_hsplit_b(&box, 60.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			
			ui_vsplit_l(&part, 60.0f, 0, &label);
			ui_vsplit_l(&label, 100.0f, 0, &textbox);
			ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
			ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
			ui_do_label(&label, localize("Password"), 20, -1);
			ui_do_edit_box(&config.password, &textbox, config.password, sizeof(config.password), 14.0f, true);
		}
		else if(popup == POPUP_FIRST_LAUNCH)
		{
			RECT label, textbox;
			
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 80.0f, &part);
			
			static int enter_button = 0;
			if(ui_do_button(&enter_button, localize("Enter"), 0, &part, ui_draw_menu_button, 0) || enter_pressed)
				popup = POPUP_NONE;
			
			ui_hsplit_b(&box, 40.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			
			ui_vsplit_l(&part, 60.0f, 0, &label);
			ui_vsplit_l(&label, 100.0f, 0, &textbox);
			ui_vsplit_l(&textbox, 20.0f, 0, &textbox);
			ui_vsplit_r(&textbox, 60.0f, &textbox, 0);
			ui_do_label(&label, localize("Nickname"), 20, -1);
			ui_do_edit_box(&config.player_name, &textbox, config.player_name, sizeof(config.player_name), 14.0f);
		}
		else
		{
			ui_hsplit_b(&box, 20.f, &box, &part);
			ui_hsplit_b(&box, 24.f, &box, &part);
			ui_vmargin(&part, 120.0f, &part);

			static int button = 0;
			if(ui_do_button(&button, button_text, 0, &part, ui_draw_menu_button, 0) || escape_pressed || enter_pressed)
			{
				if(popup == POPUP_CONNECTING)
					client_disconnect();
				popup = POPUP_NONE;
			}
		}
	}
	
	return 0;
}
Пример #10
0
void Game::main_loop(){
    //Quit flag
    bool quit = false;

	Timer fps;

	timer.start();

	int ticks = timer.get_ticks();
	int last_ticks = 0;

    //While the user hasn't quit
    while( quit == false )
    {
        //While there's events to handle
        while( SDL_PollEvent( &event ) )
        {
            //Handle events for the player
            player.handle_input(event);
			OutputDebugString(toString().c_str());

            //If the user has clicked X
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

		if(ticks - last_ticks > 10000){ // if it has been ten seconds since the last enemy spawned
			last_ticks = ticks;
			//step up speed for existing enemies
			for(int i = 0; i < enemies.size(); i++){
				enemies[i].setSpeed(enemies[i].speed + 0.5f);
			}
			//add an enemy
			setup_enemy();
		}

		//Move enemies and player
		if(!move_enemies()){ //if there was a collision between enemies and player
			quit = true;     //quit the game altogether
		}
		move_player();
		
        //Render background
        //Show the dot on the screen
        render_game();

        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return; //FAIL!
        }

        //Cap the frame rate
        if( fps.get_ticks() < 1000 / fpsCap )
        {
            SDL_Delay( ( 1000 / fpsCap ) - fps.get_ticks() );
        }
		ticks = timer.get_ticks();
    }
	//stop timer
	timer.stop();

    //Clean up
    clean_up();
}
Пример #11
0
int run_game_loop(GameState * state) {
	int done = 0;
	int i = 0;

	/* Initialise gui */
	init_gui(SCREEN_WIDTH,SCREEN_HEIGHT);

	/* Load resources */
	init_sprite_cache();
	render_world_to_sprite(&state->world);
	update_hud(
		&state->hud, 
		&state->score,
		&state->mana,
		&state->money, 
		&state->world.castle->castle.health,
		&state->wave.wave_number,
		&state->play);

	/* Initialise game loop */
	init_game_loop(FPS);
	while (!done) {
		
			/* Get events */
			Event ev;
			wait_for_event(&ev);

			/* Event handlers */
			switch (ev.type) {
			case EVENT_TIMER:
				state->redraw = 1;
				if (!state->game_over) {
					if (*state->hud.play) {
						check_spells(state);
						check_enemy_wave(state);
						update_movement(state);
						do_tower_attacks(state);
					}
				}
				break;
			case EVENT_MOUSE_MOVE:
				mouse_move(&ev.mouseMoveEvent, state);
				break;
			case EVENT_MOUSE_DOWN:
				mouse_down(&ev.mouseDownEvent, state);
				break;
			case EVENT_MOUSE_UP:
				mouse_up(&ev.mouseUpEvent, state);
				break;
			case EVENT_DISPLAY_CLOSE:
				done = 1;
				break;
			} 

			/* Render only on timer event AND if all movement and logic was processed */
			if (state->redraw && all_events_processed()) { 
				render_game(state);
			}
	}
	/* Cleanup */
	cleanup_game_loop();
	cleanup_sprite_cache();
	return 0;
}
Пример #12
0
void render() {
	clear();
	render_game();
	render_score();
}
Пример #13
0
int main(int argc, char* argv[])
{
	// init allegro and add keyboard and optional mouse support
	allegro_init();
	install_timer();
	install_keyboard();
	if (ENABLE_MOUSE_SUPPORT)
	{
		install_mouse();
	}

	// set the video mode
	set_color_depth(WINDOW_COLOR_DEPTH);
	set_gfx_mode(
		(WINDOW_USE_FULLSCREEN) ?
			GFX_AUTODETECT_FULLSCREEN :
			GFX_AUTODETECT_WINDOWED,
		WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0);
	// set the window caption text
	set_window_title(WINDOW_CAPTION);

	// create the back buffer bitmap
	backbuffer = create_bitmap(SCREEN_W, SCREEN_H);

	// seed the random number generator
	srand(time(0));

	// lock the static functions and variables we need for handling timing and closing the window via the [X] button
	LOCK_FUNCTION(my_allegro_close_button_handler);
	LOCK_FUNCTION(my_allegro_timer_speed_controller);
	LOCK_VARIABLE(allegrotimerspeedcounter);

	// set the callback function for the close-button to our global handler function
	set_close_button_callback(my_allegro_close_button_handler);

	// set our FPS lock timing global function
	install_int_ex(my_allegro_timer_speed_controller, BPS_TO_TIMER(FRAME_LOCK_RATE));

	// setup the game
	if (!setup_game())
	{
		fprintf(stderr, "The game initialization has failed. Cannot continue!\n");
		exit(1);
	}

	// main loop
	bool gameover = false;
	while(!gameover)
	{
		// if our global is ever false
		if (!mainthreadisrunning)
		{
			gameover = true;
		}

		// we only draw when the FPS should be locked
		if (allegrotimerspeedcounter > 0)
		{
			// we only update during our FPS lock time
			while (allegrotimerspeedcounter > 0)
			{
				// ensure the keyboard data is current
				if (keyboard_needs_poll())
				{
					poll_keyboard();
				}

				// ensure the mosue data is current
				if (ENABLE_MOUSE_SUPPORT)
				{
					if (mouse_needs_poll())
					{
						poll_mouse();
					}
				}

				// update
				update_game();

				// decrement the global timing var so that we can leave the update loop!
				allegrotimerspeedcounter--;
			}

			// start rendering the scene
			render_game();

			if (ENABLE_MOUSE_SUPPORT)
			{
				show_mouse(backbuffer);
			}

			// make it all visible
			blit(backbuffer, screen, 0, 0, 0, 0, backbuffer->w, backbuffer->h);
		}
		else
		{
			// a little rest to keep CPU usage down ^-^
			rest(1);
		}
	}

	// shutdown the game
	shutdown_game();

	// clean up the back buffer
	if (backbuffer)
	{
		if (ENABLE_MOUSE_SUPPORT)
		{
			show_mouse(0);
		}
		destroy_bitmap(backbuffer);
	}

	return 0;
}
Пример #14
0
void render_buffer()
{
	frame++;
	need_render_frame = 0;
	if (in_game >= 5) {
		render_game(); 
	}
	else {
		switch(mode)
		{
			
			case 1:	render_checkerboard();	break;
			case 2:	render_psycho();		break;
			case 3:	render_heartbeat();		break;
			case 4:	render_rain();			break;
			case 5:	render_fire();			break;
			case 6:	render_character(28);	break;
			case 7: render_character(29);	break;
			case 8: render_character(30);	break;
			case 9: render_character(31);	break;
			case 10: render_character(32);	break;
			case 11: render_character(33);	break;
			case 12: render_character(34);	break;
			case 13: render_character(35);	break;
			case 14: render_character(36);	break;
			case 15: render_character(37);	break;
			case 16: render_character(38);	break;
			case 17: render_character(39);	break;
			case 18: render_character(40);	break;
			case 19: render_character(0);	break;
			case 20: render_character(1);	break;
			case 21: render_character(2);	break;
			case 22: render_character(3);	break;
			case 23: render_character(4);	break;
			case 24: render_character(5);	break;
			case 25: render_character(6);	break;
			case 26: render_character(7);	break;
			case 27: render_character(8);	break;
			case 28: render_character(9);	break;
			case 29: render_character(10);	break;
			case 30: render_character(11);	break;
			case 31: render_character(12);	break;
			case 32: render_character(13);	break;
			case 33: render_character(14);	break;
			case 34: render_character(15);	break;
			case 35: render_character(16);	break;
			case 36: render_character(17);	break;
			case 37: render_character(18);	break;
			case 38: render_character(19);	break;
			case 39: render_character(20);	break;
			case 40: render_character(21);	break;
			case 41: render_character(22);	break;
			case 42: render_character(23);	break;
			case 43: render_character(24);	break;
			case 44: render_character(25);	break;
			case 45: render_character(26);	break;
		}
	}
	if (in_game >= 10) {
		in_game = 0;
		render_game(); 
	}

}