コード例 #1
0
ファイル: menu.c プロジェクト: guigahick87/ihsproducts
void initMenu(void)
{
    timer = al_create_timer(1.0 / 60);
    if (!timer)
        abort_game("Failed to create timer");

    background = al_load_bitmap(MENU_BACKGROUND_PATH);
    if (!background)
        abort_game("Failed to load background");

    eventMenuQueue = al_create_event_queue();
    if (!eventMenuQueue)
        abort_game("Failed to create event queue");

    font = al_load_ttf_font("font.ttf", 48, 0);
    if (!font)
        abort_game("failed to load font");

    music = al_load_audio_stream("musica.ogg", 4, 1024);
    if (!music)
        abort_game("failed to load audio");

    al_register_event_source(eventMenuQueue, al_get_keyboard_event_source());
    al_register_event_source(eventMenuQueue, al_get_timer_event_source(timer));

    menuDone = false;
    gState = Menu;
}
コード例 #2
0
void init(void)
{
    if (!al_init())
        abort_game("Failed to initialize allegro");
 
    if (!al_install_keyboard())
        abort_game("Failed to install keyboard");
 
    timer = al_create_timer(1.0 / 60);
    if (!timer)
        abort_game("Failed to create timer");
 
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(640, 480);
    if (!display)
        abort_game("Failed to create display");
 
    event_queue = al_create_event_queue();
    if (!event_queue)
        abort_game("Failed to create event queue");
 
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
 
    done = false;
}
コード例 #3
0
ファイル: blasteroids.c プロジェクト: btelles/head_first_c
void init(void)
{
	if (!al_init())
		abort_game("failed to initialize allegro!");

	if (!al_install_keyboard())
		abort_game("Couldn't find or connect the keyboard.");

	timer = al_create_timer(1.0 / 60);
	if (!timer)
		abort_game("Weird...I couldn't find or create a system timer.");

	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(640, 480);
	if(!display)
		abort_game("failed to create the display!");

	event_queue = al_create_event_queue();
	if (!event_queue)
		abort_game("Weird...I couldn't create an event queue.");

	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_display_event_source(display));

    spaceship.color = al_map_rgb(0,100,0);
    spaceship.heading = 0.0f;
    spaceship.x = 320.0f;
    spaceship.y = 240.0f;

	done = false;
}
コード例 #4
0
ファイル: render.cpp プロジェクト: adahera222/yogo-grenade
Render::Render(ALLEGRO_DISPLAY **display, Mapdata *mapdata,
	Gamedata *gamedata): display(display), mapdata(mapdata), gamedata(gamedata)
{
	al_init_font_addon();
	al_init_ttf_addon();

	font24 = al_load_font("OldNewspaperTypes.ttf", 24, 0);
	font16 = al_load_font("OldNewspaperTypes.ttf", 16, 0);
	if(font24 == NULL || font16 == NULL)
		abort_game("null font");

	bitmaps[0] = al_load_bitmap("orange.png");
	bitmaps[1] = al_load_bitmap("dirt.png");
	bitmaps[2] = al_load_bitmap("bunny.png");
	bitmaps[3] = al_load_bitmap("gun.png");
	bitmaps[4] = al_load_bitmap("bullet.png");
	bitmaps[5] = al_load_bitmap("grenade.png");
	bitmaps[6] = al_load_bitmap("white.png");
	bitmaps[7] = al_load_bitmap("portal.png");

	for(int i = 0; i <= 7; i++)
		if(bitmaps[i] == NULL)
			abort_game("null sprite");
			//load error
} // Render()
コード例 #5
0
ファイル: mapdata.cpp プロジェクト: adahera222/yogo-grenade
void Mapdata::load_map()
{
	FILE *fp;
	char *ptr;
	int i = 0;

	// start with 1024x256 char array. 256 is max height
	data = (char**)calloc(sizeof(char*), 1024);
	for(int i = 0; i <= 1024; i++)
		data[i] = (char*)calloc(sizeof(char), 256);

	if(!(fp = fopen("map.txt", "r")))
		abort_game("Could not find and open map.txt");

	while((fgets(data[i], 255, fp)) != NULL)
	{
		printf("R:%s", data[i]);// FIXME

		if((ptr = strchr(data[i], 'S')))
		{
			spawn_x = i;
			spawn_y = ptr - data[i];
			printf("SPAWN %d, %d\n", spawn_x, spawn_y); // FIXME
		}

		if((ptr = strchr(data[i], 'E')))
		{
			bunny_x = i;
			bunny_y = ptr - data[i];
			printf("BUNNY %d, %d\n", bunny_x, bunny_y); // FIXME
		}

		if((ptr = strchr(data[i], 'F')))
		{
			finish_x = i;
			finish_y = ptr - data[i];
			printf("FIN %d, %d\n", finish_x, finish_y); // FIXME
		}

		i++;
		if(i > 1024)
			abort_game("Map too long (> 1024)");
	} //while not null

	length = i;
	fclose(fp);
} // load_map()
コード例 #6
0
ファイル: init_allegro.c プロジェクト: winobes/L5
void init_allegro(void)
{

	if (!al_init()) {
	abort_game("Failed to initialize allegro");
	}

 
	if(!al_init_image_addon()){
		abort_game("failed to initialize allegro image addon!");
	}

	al_init_font_addon();
	if(!al_init_ttf_addon()) {
		abort_game("failed to initialize allegro ttf addon!");
	}


	if (!al_install_keyboard()) {
		abort_game("Failed to install keyboard");
	}
 
	timer = al_create_timer(1.0 / FPS);
	if (!timer) {
		abort_game("Failed to create timer");
	}
 
	al_set_new_display_flags(ALLEGRO_WINDOWED);
	display = al_create_display(width, height);
	if (!display){
		abort_game("Failed to create display");
	}
 
	event_queue = al_create_event_queue();
	if (!event_queue) {
		abort_game("Failed to create event queue");
	}






	al_register_event_source(event_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));
	al_register_event_source(event_queue, al_get_display_event_source(display));

}
コード例 #7
0
ファイル: main.cpp プロジェクト: karjonas/ld35
void init(void)
{
    if (!al_init())
        abort_game("Failed to initialize allegro");
 
    if (!al_install_keyboard())
        abort_game("Failed to install keyboard");
    if (!al_init_primitives_addon())
        abort_game("Failed to install primitives");
    al_init_font_addon(); // initialize the font addon
    al_init_ttf_addon();// initialize the ttf (True Type Font) addon 

    timer = al_create_timer(1.0 / 60);
    if (!timer)
        abort_game("Failed to create timer");
 
    ALLEGRO_DISPLAY_MODE disp_data;
    al_get_display_mode(0, &disp_data);
   
    al_set_new_display_flags(ALLEGRO_WINDOWED);
    //display = al_create_display(disp_data.width, disp_data.height);
    display = al_create_display(800, 480);
    if (!display)
        abort_game("Failed to create display");
 
    event_queue = al_create_event_queue();
    if (!event_queue)
        abort_game("Failed to create event queue");
    
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
    
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
    
    font = al_load_ttf_font("src/Atari_Full.ttf", 16,0 );

    done = false;
}
コード例 #8
0
void init(void)
{
    if (!al_init())
        abort_game("Failed to initialize allegro");

    if (!al_install_keyboard())
        abort_game("Failed to install keyboard");

    if (!al_install_mouse())
    {
        abort_game("Mouse init Failed\n");
    }

    if (!al_init_image_addon())
    {
        abort_game("image init Failed\n");
    }

    al_init_font_addon(); // initialize the font addon

    al_init_ttf_addon();// initialize the ttf (True Type Font) addon 
    if (!al_init_ttf_addon())
    {
        abort_game("ttf addon init Failed\n");
    }

    timer = al_create_timer(1.0 / FPS);
    if (!timer)
        abort_game("Failed to create timer");

    al_set_new_display_flags(ALLEGRO_WINDOWED);
    display = al_create_display(screenW, screenH);
    if (!display)
        abort_game("Failed to create display");

    event_queue = al_create_event_queue();
    if (!event_queue)
        abort_game("Failed to create event queue");

    //Registering Allegro Events
    al_register_event_source(event_queue, al_get_keyboard_event_source());
    al_register_event_source(event_queue, al_get_timer_event_source(timer));
    al_register_event_source(event_queue, al_get_display_event_source(display));
    al_register_event_source(event_queue, al_get_mouse_event_source());

    done = false;

    //creating bitmaps
   playerBitmap = al_create_bitmap(squareSize, squareSize);
   if(!playerBitmap) {
      fprintf(stderr, "failed to create playerBitmap bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      done = true;
   }

   crosshair = al_load_bitmap("data/crosshair.png");
   if(!crosshair) 
   {
      fprintf(stderr, "failed to create crosshair bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      done = true;
   }

   transporter = al_load_bitmap("data/transporter.png");
   if(!transporter) 
   {
      fprintf(stderr, "failed to create transporter bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      done = true;
   }

   tilesDungeon = al_load_bitmap("data/bigDungeonTiles.png");
   if(!crosshair) 
   {
      fprintf(stderr, "failed to load bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      done = true;
   }

   al_set_target_bitmap(playerBitmap);
   al_clear_to_color(al_map_rgb(255, 0, 255));
   al_set_target_bitmap(al_get_backbuffer(display));
   al_flip_display();

}