Beispiel #1
0
void unload_images()
{
    if( character_bitmaps != nullptr )
    {
        for( int i = 0; i < 4; ++i )
        {
            for( int j = 0; j < 30; ++j )
            {
                al_destroy_bitmap( character_bitmaps[ i ][ j ] );
            }
        }
    }

    for( int i = 0; i < 25; ++i )
    {
        al_destroy_bitmap( tiles[ i ] );
    }

    al_destroy_bitmap( play_solo_bitmap );
    al_destroy_bitmap( host_game_bitmap );
    al_destroy_bitmap( join_game_bitmap );
    al_destroy_bitmap( quit_game_bitmap );
}
Beispiel #2
0
void
unload_mirror (void)
{
  /* dungeon cga */
  al_destroy_bitmap (dc_mirror);

  /* palace cga */
  al_destroy_bitmap (pc_mirror);

  /* dungeon ega */
  al_destroy_bitmap (de_mirror);

  /* palace ega */
  al_destroy_bitmap (pe_mirror);

  /* dungeon vga */
  al_destroy_bitmap (dv_mirror);

  /* palace vga */
  al_destroy_bitmap (pv_mirror);

  /* callbacks */
  remove_room_callback (create_mirror_bitmaps);
}
Beispiel #3
0
/* Function: al_grab_font_from_bitmap
 */
ALLEGRO_FONT *al_grab_font_from_bitmap(ALLEGRO_BITMAP *bmp,
   int ranges_n, const int ranges[])
{
   ALLEGRO_FONT *f;
   ALLEGRO_FONT_COLOR_DATA *cf, *prev = NULL;
   ALLEGRO_STATE backup;
   int i;
   ALLEGRO_COLOR mask = al_get_pixel(bmp, 0, 0);
   ALLEGRO_BITMAP *glyphs = NULL, *unmasked = NULL;
   int import_x = 0, import_y = 0;
   ALLEGRO_LOCKED_REGION *lock = NULL;
   int w, h;

   ASSERT(bmp);
   
   w = al_get_bitmap_width(bmp);
   h = al_get_bitmap_height(bmp);

   f = al_calloc(1, sizeof *f);
   f->vtable = &_al_font_vtable_color;
   
   al_store_state(&backup, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA);
   unmasked = al_clone_bitmap(bmp);
   /* At least with OpenGL, texture pixels at the very border of
    * the glyph are sometimes partly sampled from the yellow mask
    * pixels. To work around this, we replace the mask with full
    * transparency.
    * And we best do it on a memory copy to avoid loading back a texture.
    */
   al_convert_mask_to_alpha(unmasked, mask);
   al_restore_state(&backup);   

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);
   // Use the users preferred format, so don't set this below!
   //al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA);

   for (i = 0; i < ranges_n; i++) {
      int first = ranges[i * 2];
      int last = ranges[i * 2 + 1];
      int n = 1 + last - first;
      cf = al_calloc(1, sizeof(ALLEGRO_FONT_COLOR_DATA));

      if (prev)
         prev->next = cf;
      else
         f->data = cf;
      
      cf->bitmaps = al_malloc(sizeof(ALLEGRO_BITMAP*) * n);
      cf->bitmaps[0] = NULL;

      if (!glyphs) {
         glyphs = al_clone_bitmap(unmasked);
         if (!glyphs)
            goto cleanup_and_fail_on_error;

         lock = al_lock_bitmap(bmp,
            ALLEGRO_PIXEL_FORMAT_RGBA_8888, ALLEGRO_LOCK_READONLY);
      }
      cf->glyphs = glyphs;

      if (import_bitmap_font_color(lock->data, lock->pitch, w, h,
         cf->bitmaps, cf->glyphs, n,
         &import_x, &import_y)) {
         goto cleanup_and_fail_on_error;
      }
      else {
         cf->begin = first;
         cf->end = last + 1;
         prev = cf;
      }
   }
   al_restore_state(&backup);
   
   cf = f->data;
   if (cf && cf->bitmaps[0])
      f->height = al_get_bitmap_height(cf->bitmaps[0]);

   if (lock)
      al_unlock_bitmap(bmp);

   if (unmasked)
       al_destroy_bitmap(unmasked);

   f->dtor_item = _al_register_destructor(_al_dtor_list, "font", f,
      (void (*)(void  *))al_destroy_font);

   return f;

cleanup_and_fail_on_error:

   if (lock)
      al_unlock_bitmap(bmp);
   al_restore_state(&backup);
   al_destroy_font(f);
   if (unmasked)
       al_destroy_bitmap(unmasked);
   return NULL;
}
int
main (int argc, char **argv)
{
    Mario mario;
    ALLEGRO_BITMAP *mario_spritesheet = NULL;
    bool tecla[4] = { false, false, false, false };
    int sprite_number = 0;
    srand (time (NULL));
    iniciar_allegro ();
    mario_spritesheet = al_load_bitmap (SPRITESHEET);
    if (!mario_spritesheet)
    {
	al_show_native_message_box (display, "Error", "Error",
		"No se ha podido crear el bitmap", NULL,
		ALLEGRO_MESSAGEBOX_ERROR);
	al_destroy_timer (timer);
	al_destroy_display (display);
	exit (EXIT_FAILURE);
    }
    mario.set_dibujo (mario_spritesheet);
    while (1)
    { /* Buzz Lightyear */
	ALLEGRO_EVENT ev;
	ALLEGRO_TIMEOUT timeout;
	al_init_timeout (&timeout, 0.06);
	bool get_event = al_wait_for_event_until (event_queue, &ev, &timeout);
	if (get_event)
	{
	    if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		break;
	    if (ev.type == ALLEGRO_EVENT_TIMER)
		redraw = true;
	    if (ev.type == ALLEGRO_EVENT_KEY_DOWN)
	    {
		switch (ev.keyboard.keycode)
		{
		    case ALLEGRO_KEY_UP:
			tecla[KEY_UP] = true;
			break;
		    case ALLEGRO_KEY_DOWN:
			tecla[KEY_DOWN] = true;
			break;
		    case ALLEGRO_KEY_LEFT:
			tecla[KEY_LEFT] = true;
			break;
		    case ALLEGRO_KEY_RIGHT:
			tecla[KEY_RIGHT] = true;
			break;
		}
	    }
	    if (ev.type == ALLEGRO_EVENT_KEY_UP)
	    {
		switch (ev.keyboard.keycode)
		{
		    case ALLEGRO_KEY_UP:
			tecla[KEY_UP] = false;
			break;
		    case ALLEGRO_KEY_DOWN:
			tecla[KEY_DOWN] = false;
			break;
		    case ALLEGRO_KEY_LEFT:
			tecla[KEY_LEFT] = false;
			break;
		    case ALLEGRO_KEY_RIGHT:
			tecla[KEY_RIGHT] = false;
			break;
		    case ALLEGRO_KEY_LSHIFT:
			sprite_number++;
			break;
		}
	    }
	}
	/* Actualizar las coordenadas de la pelota */
	if (tecla[KEY_UP])
	    mario.change_vy(-DELTA);
	if (tecla[KEY_DOWN])
	    mario.change_vy(DELTA);
	if (tecla[KEY_LEFT])
	    mario.change_vx(-DELTA);
	if (tecla[KEY_RIGHT])
	    mario.change_vx(DELTA);
	mario.actualizate();
	if (redraw && al_is_event_queue_empty (event_queue))
	{
	    al_clear_to_color (al_map_rgb (0, 0, 0));
	    for (int i = 0; i < N; i++)
		al_draw_bitmap (mario.get_dibujo (),  mario.get_x () + 450,
			mario.get_y () + 450, 0);
	    al_flip_display ();
	    redraw = false;
	}
    }
    al_destroy_bitmap (mario_spritesheet);
    destruir_allegro ();
    return 0;
}
Beispiel #5
0
int Menu_Keydown(struct Game *game, ALLEGRO_EVENT *ev) {

	if (ev->keyboard.keycode==ALLEGRO_KEY_UP) {
		game->menu.selected--;
		if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected--;
		al_play_sample_instance(game->menu.click);
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_DOWN) {
		game->menu.selected++;
		if ((game->menu.menustate==MENUSTATE_VIDEO) && (game->menu.selected==1) && (game->menu.options.fullscreen)) game->menu.selected++;
		al_play_sample_instance(game->menu.click);
	}

	if (ev->keyboard.keycode==ALLEGRO_KEY_ENTER) {
		char *text;
		al_play_sample_instance(game->menu.click);
		switch (game->menu.menustate) {
			case MENUSTATE_MAIN:
				switch (game->menu.selected) {
					case 0:
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_DISCLAIMER;
						break;
					case 1:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					case 2:
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_ABOUT;
						break;
					case 3:
						return 1;
						break;
				}
				break;
			case MENUSTATE_AUDIO:
				text = malloc(255*sizeof(char));
				switch (game->menu.selected) {
					case 0:
						game->music--;
						if (game->music<0) game->music=10;
						sprintf(text, "%d", game->music);
						SetConfigOption("SuperDerpy", "music", text);
						al_set_mixer_gain(game->audio.music, game->music/10.0);
						break;
					case 1:
						game->fx--;
						if (game->fx<0) game->fx=10;
						sprintf(text, "%d", game->fx);
						SetConfigOption("SuperDerpy", "fx", text);
						al_set_mixer_gain(game->audio.fx, game->fx/10.0);
						break;
					case 2:
						game->voice--;
						if (game->voice<0) game->voice=10;
						sprintf(text, "%d", game->voice);
						SetConfigOption("SuperDerpy", "voice", text);
						al_set_mixer_gain(game->audio.voice, game->voice/10.0);
						break;
					case 3:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
				}
				free(text);
				break;
			case MENUSTATE_OPTIONS:
				switch (game->menu.selected) {
					case 0:
						ChangeMenuState(game,MENUSTATE_CONTROLS);
						break;
					case 1:
						ChangeMenuState(game,MENUSTATE_VIDEO);
						break;
					case 2:
						ChangeMenuState(game,MENUSTATE_AUDIO);
						break;
					case 3:
						ChangeMenuState(game,MENUSTATE_MAIN);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_PAUSE:
				switch (game->menu.selected){
					case 0:
						PrintConsole(game,"Game resumed.");
						al_destroy_bitmap(game->pause.bitmap);
						game->pause.bitmap = NULL;
						ResumeGameState(game);
						game->gamestate = game->loadstate;
						break;
					case 1:
						game->gamestate=game->loadstate;
						UnloadGameState(game);
						game->gamestate = GAMESTATE_LOADING;
						game->loadstate = GAMESTATE_MAP;
						break;
					case 2:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					case 3:
						return 1;
					default:
						break;
				}
				break;
			case MENUSTATE_CONTROLS:
				switch (game->menu.selected) {
					case 3:
						ChangeMenuState(game,MENUSTATE_OPTIONS);
						break;
					default:
						break;
				}
				break;
			case MENUSTATE_VIDEO:
				switch (game->menu.selected) {
					case 0:
						game->menu.options.fullscreen = !game->menu.options.fullscreen;
						if (game->menu.options.fullscreen)
							SetConfigOption("SuperDerpy", "fullscreen", "1");
						else
							SetConfigOption("SuperDerpy", "fullscreen", "0");
						break;
					case 3:
						if ((game->menu.options.fullscreen==game->fullscreen) && (game->menu.options.fps==game->fps) && (game->menu.options.width==game->width) && (game->menu.options.height==game->height)) {
							ChangeMenuState(game,MENUSTATE_OPTIONS);
						} else {
							PrintConsole(game, "video settings changed, restarting...");
							game->restart = true;
							return 1;
						}
						break;
					default:
						break;
				}
				break;
			default:
				return 1;
				break;
		}
	} else if (ev->keyboard.keycode==ALLEGRO_KEY_ESCAPE) {
		switch (game->menu.menustate) {
			case MENUSTATE_OPTIONS:
				ChangeMenuState(game,MENUSTATE_MAIN);
				break;
			case MENUSTATE_VIDEO:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_AUDIO:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_CONTROLS:
				ChangeMenuState(game,MENUSTATE_OPTIONS);
				break;
			case MENUSTATE_PAUSE:
				PrintConsole(game,"Game resumed.");
				al_destroy_bitmap(game->pause.bitmap);
				game->pause.bitmap = NULL;
				ResumeGameState(game);
				game->gamestate = game->loadstate;
				break;
			default:
				return 1;
				break;
		}
	}

	if (game->menu.selected==-1) game->menu.selected=3;
	if (game->menu.selected==4) game->menu.selected=0;
	return 0;
}
Beispiel #6
0
void Menu_Preload(struct Game *game, void (*progress)(struct Game*, float)) {
	PROGRESS_INIT(16);

	game->menu.options.fullscreen = game->fullscreen;
	game->menu.options.fps = game->fps;
	game->menu.options.width = game->width;
	game->menu.options.height = game->height;
	game->menu.loaded = true;
	game->menu.image = LoadScaledBitmap( "menu/menu.png", game->viewportWidth, game->viewportWidth*(1240.0/3910.0));
	PROGRESS;
	game->menu.mountain = LoadScaledBitmap( "menu/mountain.png", game->viewportHeight*1.6*0.055, game->viewportHeight/9 );
	PROGRESS;
	game->menu.cloud = LoadScaledBitmap( "menu/cloud.png", game->viewportHeight*1.6*0.5, game->viewportHeight*0.25 );
	PROGRESS;
	game->menu.cloud2 = LoadScaledBitmap( "menu/cloud2.png", game->viewportHeight*1.6*0.2, game->viewportHeight*0.1 );
	PROGRESS;
	game->menu.logo = LoadScaledBitmap( "menu/logo.png", game->viewportHeight*1.6*0.3, game->viewportHeight*0.35 );
	game->menu.blurbg = al_create_bitmap(game->viewportHeight*1.6*0.3, game->viewportHeight*0.35);
	game->menu.blurbg2 = al_create_bitmap(game->viewportHeight*1.6*0.3, game->viewportHeight*0.35);
	PROGRESS;
	game->menu.logoblur = al_create_bitmap(game->viewportHeight*1.6*0.3+4, game->viewportHeight*0.35+4);
	al_set_target_bitmap(game->menu.logoblur);
	al_clear_to_color(al_map_rgba(0,0,0,0));
	float alpha = (1.0/40.0);
	ALLEGRO_COLOR color = al_map_rgba_f(alpha, alpha, alpha, alpha);
	int by, bx;
	for (by = -2; by <= 2; by++) {
		for (bx = -2; bx <= 2; bx++) {
			if (sqrt(bx*bx+by*by) <= 2)
				al_draw_tinted_bitmap(game->menu.logo, color, bx, by, 0);
		}
	}
	al_set_target_bitmap(al_get_backbuffer(game->display));
	PROGRESS;
	game->menu.glass = LoadScaledBitmap( "menu/glass.png", game->viewportHeight*1.6*0.3, game->viewportHeight*0.35 );
	PROGRESS;
	//game->menu.pinkcloud = LoadScaledBitmap( "menu/pinkcloud.png", game->viewportWidth*0.33125, game->viewportHeight*0.8122);
	game->menu.pinkcloud = LoadScaledBitmap( "menu/pinkcloud.png", game->viewportHeight*0.8122*(1171.0/2218.0), game->viewportHeight*0.8122);
	PROGRESS;
	al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
	game->menu.rain = al_load_bitmap( GetDataFilePath("menu/rain.png") );
	PROGRESS;
	game->menu.pie = al_load_bitmap( GetDataFilePath("menu/pie.png") );
	al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR | ALLEGRO_MIN_LINEAR);
	PROGRESS;

	game->menu.sample = al_load_sample( GetDataFilePath("menu/menu.flac") );
	PROGRESS;
	game->menu.rain_sample = al_load_sample( GetDataFilePath("menu/rain.flac") );
	PROGRESS;
	game->menu.click_sample = al_load_sample( GetDataFilePath("menu/click.flac") );
	PROGRESS;
	game->menu.mountain_position = game->viewportWidth*0.7;

	game->menu.music = al_create_sample_instance(game->menu.sample);
	al_attach_sample_instance_to_mixer(game->menu.music, game->audio.music);
	al_set_sample_instance_playmode(game->menu.music, ALLEGRO_PLAYMODE_LOOP);

	game->menu.rain_sound = al_create_sample_instance(game->menu.rain_sample);
	al_attach_sample_instance_to_mixer(game->menu.rain_sound, game->audio.fx);
	al_set_sample_instance_playmode(game->menu.rain_sound, ALLEGRO_PLAYMODE_LOOP);

	game->menu.click = al_create_sample_instance(game->menu.click_sample);
	al_attach_sample_instance_to_mixer(game->menu.click, game->audio.fx);
	al_set_sample_instance_playmode(game->menu.click, ALLEGRO_PLAYMODE_ONCE);

	game->menu.font_title = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.16,0 );
	game->menu.font_subtitle = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.08,0 );
	game->menu.font = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.05,0 );
	game->menu.font_selected = al_load_ttf_font(GetDataFilePath("fonts/ShadowsIntoLight.ttf"),game->viewportHeight*0.065,0 );
	PROGRESS;

	if (!game->menu.sample){
		fprintf(stderr, "Audio clip sample not loaded!\n" );
		exit(-1);
	}

	if (!game->menu.rain_sample){
		fprintf(stderr, "Audio clip sample#2 not loaded!\n" );
		exit(-1);
	}

	if (!game->menu.click_sample){
		fprintf(stderr, "Audio clip sample#3 not loaded!\n" );
		exit(-1);
	}

	game->menu.pinkcloud_bitmap = al_create_bitmap(game->viewportHeight*0.8122*(1171.0/2218.0), game->viewportHeight);

	game->menu.pie_bitmap = al_create_bitmap(game->viewportHeight*0.8, game->viewportHeight);
	al_set_target_bitmap(game->menu.pie_bitmap);
	al_clear_to_color(al_map_rgba(0,0,0,0));
	al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.5, 0, game->viewportHeight*1.6*0.11875, game->viewportHeight*0.0825, 0);
	al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.1, al_get_bitmap_height(game->menu.pie_bitmap)*0.3, game->viewportHeight*1.6*0.09, game->viewportHeight*0.06, ALLEGRO_FLIP_HORIZONTAL);
	al_draw_scaled_bitmap(game->menu.pie, 0, 0, al_get_bitmap_width(game->menu.pie), al_get_bitmap_height(game->menu.pie), al_get_bitmap_width(game->menu.pie_bitmap)*0.3, al_get_bitmap_height(game->menu.pie_bitmap)*0.6, game->viewportHeight*1.6*0.13, game->viewportHeight*0.1, 0);
	al_destroy_bitmap(game->menu.pie);
	PROGRESS;

	al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);
	game->menu.rain_bitmap = al_create_bitmap(al_get_bitmap_width(game->menu.pinkcloud_bitmap)*0.5, al_get_bitmap_height(game->menu.pinkcloud_bitmap)*0.1);
	al_set_new_bitmap_flags(ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
	al_set_target_bitmap(game->menu.rain_bitmap);
	al_clear_to_color(al_map_rgba(0,0,0,0));
	al_draw_scaled_bitmap(game->menu.rain,0, 0, al_get_bitmap_width(game->menu.rain), al_get_bitmap_height(game->menu.rain), 0, 0, al_get_bitmap_width(game->menu.rain_bitmap), al_get_bitmap_height(game->menu.rain_bitmap),0);
	al_destroy_bitmap(game->menu.rain);
	PROGRESS;
}
BaseNode::~BaseNode() {
#ifdef __DEBUG__
    std::cout << "Destroying image" << std::endl;
#endif
    al_destroy_bitmap(this->pImage);
}
Beispiel #8
0
MouseCursor::~MouseCursor(void) {
	al_destroy_bitmap(bitmap);
}
int main (int argc, char *argv[])
{
	al_init();
	ALLEGRO_DISPLAY *display = al_create_display(640, 480);

	al_init_primitives_addon();
	al_init_image_addon();
	al_init_font_addon();
	al_init_ttf_addon();

	srand(time(NULL));

	char* disappointed[] = {" Razocharovana sum!", " Tolkova losho kontrolno ne sum vijdala!", 
		"Golqm murzel vi e nalegnal...", " Potresavashto!!"};
	
	ALLEGRO_BITMAP *image = al_load_bitmap("pic.bmp");

	ALLEGRO_EVENT_QUEUE *event_queue = al_create_event_queue();
	ALLEGRO_TIMER *timer = al_create_timer(1/60.0);
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	ALLEGRO_FONT *font = al_load_font("Arial.ttf", 20, 0);
	
	int done = 0;
	int render = 0;

	int x = 375;
	int y = 340;
	int traveled_y = 0;

	int delay = 120;
	int time_elapsed = 0;
	int dir = -1;
	int move_left = 0;
	int traveled_x = 0;
	int time_elapsed2 = 0;
	int draw_text = 0;
	int random = 0;
	int should_draw_text = 0;

	al_start_timer(timer);

	while(!done)
	{
		ALLEGRO_EVENT event;
		al_wait_for_event(event_queue, &event);

		if(event.type == ALLEGRO_EVENT_TIMER)
		{
			if(x < 50)
				done = 1;
			if(traveled_y >= 75)
			{
				if(!draw_text)
				{
					random = rand() % 4;
					if(y < 350)
						should_draw_text = 1;
				}
				draw_text = 1;
				if(++time_elapsed >= delay)
				{
					traveled_y = 0;
					time_elapsed = 0;
					if(y <= 60 || y >= 375)
					{
						if(!move_left)
						{
							if(y <= 60)
							{
								if(traveled_x >= 50)
								{
									if(++time_elapsed2 >= delay)
									{
										traveled_x = 0;
										time_elapsed2 = 0;
										move_left = 1;
									}
								}
								else
								{
									x -= 3;
									traveled_x += 3;
								}									
							}
							else if(y >= 375)
							{
								should_draw_text = 0;
								if(traveled_x >= 140)
								{
									if(++time_elapsed2 >= delay)
									{
										traveled_x = 0;
										time_elapsed2 = 0;
										move_left = 1;
									}
								}
								else
								{
									x -= 3;
									traveled_x += 3;
								}
							}
							time_elapsed = 120;
							traveled_y = 75;
						}
						else
						{
							dir *= -1;
							move_left = 0;
						}
					}
				}				
			}
			else 
			{
				draw_text = 0;
				should_draw_text = 0;
				y += 3 * dir;
				traveled_y += 3;
			}
			render = 1;
		}

		if(render)
		{
			al_draw_bitmap(image, 0, 0, 0);
			al_draw_pixel(x, y, al_map_rgb(255, 0, 0));
			if(should_draw_text)
			{
				al_draw_text(font, al_map_rgb(255, 255, 255), 10, 450, 0, disappointed[random]);
			}
			al_flip_display();
			al_clear_to_color(al_map_rgb(0, 0, 0));
			render = 0;
		}
	}

	al_destroy_display(display);
	al_destroy_bitmap(image);
	al_destroy_event_queue(event_queue);
	al_destroy_timer(timer);

	return 0;
}
void destroy_sprite(struct ship_sprite *sprite)
{
	al_destroy_bitmap(sprite->image);
}
Beispiel #11
0
static void draw(void)
{
   float x, y;
   int iw = al_get_bitmap_width(ex.pattern);
   int ih = al_get_bitmap_height(ex.pattern);
   ALLEGRO_BITMAP *screen, *temp;
   ALLEGRO_LOCKED_REGION *lock;
   void *data;
   int size, i, format;
   
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);

   al_clear_to_color(ex.background);

   screen = al_get_target_bitmap();

   set_xy(8, 8);

   /* Test 1. */
   /* Disabled: drawing to same bitmap is not supported. */
   /*
   print("Screen -> Screen (%.1f fps)", get_fps(0));
   get_xy(&x, &y);
   al_draw_bitmap(ex.pattern, x, y, 0);

   start_timer(0);
   al_draw_bitmap_region(screen, x, y, iw, ih, x + 8 + iw, y, 0);
   stop_timer(0);
   set_xy(x, y + ih);
   */

   /* Test 2. */
   print("Screen -> Bitmap -> Screen (%.1f fps)", get_fps(1));
   get_xy(&x, &y);
   al_draw_bitmap(ex.pattern, x, y, 0);

   temp = al_create_bitmap(iw, ih);
   al_set_target_bitmap(temp);
   al_clear_to_color(al_map_rgba_f(1, 0, 0, 1));
   start_timer(1);
   al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0);

   al_set_target_bitmap(screen);
   al_draw_bitmap(temp, x + 8 + iw, y, 0);
   stop_timer(1);
   set_xy(x, y + ih);
   
   al_destroy_bitmap(temp);

   /* Test 3. */
   print("Screen -> Memory -> Screen (%.1f fps)", get_fps(2));
   get_xy(&x, &y);
   al_draw_bitmap(ex.pattern, x, y, 0);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   temp = al_create_bitmap(iw, ih);
   al_set_target_bitmap(temp);
   al_clear_to_color(al_map_rgba_f(1, 0, 0, 1));
   start_timer(2);
   al_draw_bitmap_region(screen, x, y, iw, ih, 0, 0, 0);

   al_set_target_bitmap(screen);
   al_draw_bitmap(temp, x + 8 + iw, y, 0);
   stop_timer(2);
   set_xy(x, y + ih);
   
   al_destroy_bitmap(temp);
   al_set_new_bitmap_flags(ALLEGRO_VIDEO_BITMAP);

   /* Test 4. */
   print("Screen -> Locked -> Screen (%.1f fps)", get_fps(3));
   get_xy(&x, &y);
   al_draw_bitmap(ex.pattern, x, y, 0);

   start_timer(3);
   lock = al_lock_bitmap_region(screen, x, y, iw, ih,
      ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
   format = lock->format;
   size = lock->pixel_size;
   data = malloc(size * iw * ih);
   for (i = 0; i < ih; i++)
      memcpy((char*)data + i * size * iw,
         (char*)lock->data + i * lock->pitch, size * iw);
   al_unlock_bitmap(screen);
   
   lock = al_lock_bitmap_region(screen, x + 8 + iw, y, iw, ih, format,
      ALLEGRO_LOCK_WRITEONLY);
   for (i = 0; i < ih; i++)
      memcpy((char*)lock->data + i * lock->pitch,
         (char*)data + i * size * iw, size * iw);
   al_unlock_bitmap(screen);
   free(data);
   stop_timer(3);
   set_xy(x, y + ih);

}
Beispiel #12
0
int main(int argc, char **argv)
{
   const int display_w = 640;
   const int display_h = 480;

   ALLEGRO_DISPLAY *dpy;
   ALLEGRO_BITMAP *buf;
   ALLEGRO_BITMAP *bmp;
   ALLEGRO_BITMAP *mem_bmp;
   ALLEGRO_BITMAP *src_bmp;
   int bmp_w;
   int bmp_h;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   double theta = 0;
   double k = 1.0;
   int mode = 0;
   bool wide_mode = false;
   bool mem_src_mode = false;
   bool trans_mode = false;
   int flags = 0;
   bool clip_mode = false;
   ALLEGRO_COLOR tint;

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_install_keyboard();
   al_init_image_addon();
   init_platform_specific();

   open_log();
   log_printf("Press 'w' to toggle wide mode.\n");
   log_printf("Press 's' to toggle memory source bitmap.\n");
   log_printf("Press space to toggle drawing to backbuffer or off-screen bitmap.\n");
   log_printf("Press 't' to toggle translucency.\n");
   log_printf("Press 'h' to toggle horizontal flipping.\n");
   log_printf("Press 'v' to toggle vertical flipping.\n");
   log_printf("Press 'c' to toggle clipping.\n");
   log_printf("\n");

   dpy = al_create_display(display_w, display_h);
   if (!dpy) {
      abort_example("Unable to set any graphic mode\n");
   }

   buf = al_create_bitmap(display_w, display_h);
   if (!buf) {
      abort_example("Unable to create buffer\n\n");
   }

   bmp = al_load_bitmap("data/mysha.pcx");
   if (!bmp) {
      abort_example("Unable to load image\n");
   }

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   mem_bmp = al_load_bitmap("data/mysha.pcx");
   if (!mem_bmp) {
      abort_example("Unable to load image\n");
   }

   bmp_w = al_get_bitmap_width(bmp);
   bmp_h = al_get_bitmap_height(bmp);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());

   while (true) {
      if (al_get_next_event(queue, &event)) {
         if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
               break;
            if (event.keyboard.unichar == ' ') {
               mode = !mode;
               if (mode == 0)
                  log_printf("Drawing to off-screen buffer\n");
               else
                  log_printf("Drawing to display backbuffer\n");
            }
            if (event.keyboard.unichar == 'w')
               wide_mode = !wide_mode;
            if (event.keyboard.unichar == 's') {
               mem_src_mode = !mem_src_mode;
               if (mem_src_mode)
                  log_printf("Source is memory bitmap\n");
               else
                  log_printf("Source is display bitmap\n");
            }
            if (event.keyboard.unichar == 't')
               trans_mode = !trans_mode;
            if (event.keyboard.unichar == 'h')
               flags ^= ALLEGRO_FLIP_HORIZONTAL;
            if (event.keyboard.unichar == 'v')
               flags ^= ALLEGRO_FLIP_VERTICAL;
            if (event.keyboard.unichar == 'c')
               clip_mode = !clip_mode;
         }
      }

      /*
       * mode 0 = draw scaled to off-screen buffer before
       *          blitting to display backbuffer
       * mode 1 = draw scaled to display backbuffer
       */

      if (mode == 0) {
         al_set_target_bitmap(buf);
      }
      else {
         al_set_target_backbuffer(dpy);
      }

      src_bmp = (mem_src_mode) ? mem_bmp : bmp;
      k = (wide_mode) ? 2.0 : 1.0;

      al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      tint = al_map_rgba_f(1, 1, 1, 1);
      if (mode == 0)
         al_clear_to_color(al_map_rgba_f(1, 0, 0, 1));
      else
         al_clear_to_color(al_map_rgba_f(0, 0, 1, 1));

      if (trans_mode) {
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
         tint = al_map_rgba_f(1, 1, 1, 0.5);
      }

      if (clip_mode) {
         al_set_clipping_rectangle(50, 50, display_w - 100, display_h - 100);
      }
      else {
         al_set_clipping_rectangle(0, 0, display_w, display_h);
      }

      al_draw_tinted_scaled_bitmap(src_bmp, tint,
         0, 0, bmp_w, bmp_h,
         display_w/2, display_h/2,
         k * cos(theta) * display_w/2, k * sin(theta) * display_h/2,
         flags);

      if (mode == 0) {
         al_set_target_backbuffer(dpy);
         al_set_clipping_rectangle(0, 0, display_w, display_h);
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
         al_draw_bitmap(buf, 0, 0, 0);
      }

      al_flip_display();
      al_rest(0.01);
      theta += 0.01;
   }

   al_destroy_bitmap(bmp);
   al_destroy_bitmap(mem_bmp);
   al_destroy_bitmap(buf);

   close_log(false);
   return 0;
}
Beispiel #13
0
void
ship_shutdown(void)
{
  al_destroy_bitmap(sprite);
  al_destroy_bitmap(thrust_sprite);
}
Beispiel #14
0
void perso_dest(Personnage* perso){
	al_destroy_bitmap(perso->sprite);
	free(perso);
}
Beispiel #15
0
GraphicsBuffer::~GraphicsBuffer()
{
	al_destroy_bitmap( mpBitmap );
	//printf( " GraphicsBuffer destroyed!\n");
}
Beispiel #16
0
void ScreenMain::Input(ALLEGRO_EVENT &event, float &xscale, float &yscale)
{
    if(global::play == true)
    {
        if(SCGame == nullptr)
        {
            SCGame = new ScreenGame();
        }

        SCGame->Input(event, xscale, yscale);

        return;
    }
    else
    {
        if(SCGame != nullptr)
        {
            delete SCGame;
        }
    }

    if(is_any_button_clicked() == false)
    {
        if(SCAbout != nullptr)
        {
            delete SCAbout;
            SCAbout = nullptr;
        }
        if(SCPlay != nullptr)
        {
            delete SCPlay;
            SCPlay = nullptr;
        }

        Musicb->Input(event, xscale, yscale);
        if(Musicb->is_button_clicked() == true)
        {
            Musicb->unclick();
            global::audio = (global::audio == true ? global::audio = false : global::audio = true);

            if(global::audio == true)
            {
                al_destroy_bitmap(Musicb->bmp);
                Musicb->bmp = al_load_bitmap(MusicON);
            }
            else
            {
                al_destroy_bitmap(Musicb->bmp);
                Musicb->bmp = al_load_bitmap(MusicOFF);
            }
        }

        for(int a = 0;a < buttons.size();a++)
        {
            buttons[a]->Input(event, xscale, yscale);
        }
    }

    if(buttons[EXIT]->is_button_clicked() == true)
    {
        global::loop = false;
    }
    else if(buttons[PLAY]->is_button_clicked() == true)
    {
        if(SCPlay == nullptr)
        {
            SCPlay = new ScreenPlay(buttons[PLAY]);
        }
        SCPlay->Input(event, xscale, yscale);
    }
    else if(buttons[ABOUT]->is_button_clicked() == true)
    {
        if(SCAbout == nullptr)
        {
            SCAbout = new ScreenAbout(buttons[ABOUT]);
        }
        SCAbout->Input(event, xscale, yscale);
    }

    return;
}
int main(void)
{
   ALLEGRO_DISPLAY *display[2];
   ALLEGRO_EVENT event;
   ALLEGRO_EVENT_QUEUE *events;
   ALLEGRO_BITMAP *pictures[2];
   ALLEGRO_BITMAP *target;
   int width, height;
   int i;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_install_keyboard();
   al_install_mouse();
   al_init_image_addon();

   events = al_create_event_queue();

   al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE);

   /* Create two windows. */
   display[0] = al_create_display(W, H);
   pictures[0] = al_load_bitmap("data/mysha.pcx");
   if (!pictures[0]) {
      abort_example("failed to load mysha.pcx\n");
      return 1;
   }

   display[1] = al_create_display(W, H);
   pictures[1] = al_load_bitmap("data/allegro.pcx");
   if (!pictures[1]) {
      abort_example("failed to load allegro.pcx\n");
      return 1;
   }

   /* This is only needed since we want to receive resize events. */
   al_register_event_source(events, al_get_display_event_source(display[0]));
   al_register_event_source(events, al_get_display_event_source(display[1]));
   al_register_event_source(events, al_get_keyboard_event_source());

   while (1) {
      /* read input */
      while (!al_is_event_queue_empty(events)) {
         al_get_next_event(events, &event);
         if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
            ALLEGRO_KEYBOARD_EVENT *key = &event.keyboard;
            if (key->keycode == ALLEGRO_KEY_ESCAPE) {
               goto done;
            }
         }
         if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
            ALLEGRO_DISPLAY_EVENT *de = &event.display;
            al_acknowledge_resize(de->source);
         }
         if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_IN) {
            printf("%p switching in\n", event.display.source);
         }
         if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
            printf("%p switching out\n", event.display.source);
         }
         if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
            int i;
            for (i = 0; i < 2; i++) {
               if (display[i] == event.display.source)
                  display[i] = 0;
            }
            al_destroy_display(event.display.source);
            for (i = 0; i < 2; i++) {
               if (display[i])
                  goto not_done;
            }
            goto done;
         not_done:
            ;
         }
      }

      for (i = 0; i < 2; i++) {
         if (!display[i])
            continue;

         target = al_get_backbuffer(display[i]);
         width = al_get_bitmap_width(target);
         height = al_get_bitmap_height(target);

         al_set_target_bitmap(target);
         al_draw_scaled_bitmap(pictures[0], 0, 0,
            al_get_bitmap_width(pictures[0]),
            al_get_bitmap_height(pictures[0]),
            0, 0,
            width / 2, height,
            0);
         al_draw_scaled_bitmap(pictures[1], 0, 0,
            al_get_bitmap_width(pictures[1]),
            al_get_bitmap_height(pictures[1]),
            width / 2, 0,
            width / 2, height,
            0);

         al_flip_display();
      }

      al_rest(0.001);
   }

done:
   al_destroy_bitmap(pictures[0]);
   al_destroy_bitmap(pictures[1]);

   return 0;
}
int main(int argc, char **argv)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP *bmp;
   ALLEGRO_FONT *f;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   bool redraw;
   int min_w, min_h, max_w, max_h;
   int ret_min_w, ret_min_h, ret_max_w, ret_max_h;
   bool constr_min_w, constr_min_h, constr_max_w, constr_max_h;

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_install_keyboard();
   al_init_image_addon();
   al_init_font_addon();

   al_set_new_display_flags(ALLEGRO_RESIZABLE |
      ALLEGRO_GENERATE_EXPOSE_EVENTS);
   display = al_create_display(640, 480);
   if (!display) {
      abort_example("Unable to set any graphic mode\n");
   }

   bmp = al_load_bitmap("data/mysha.pcx");
   if (!bmp) {
      abort_example("Unable to load image\n");
   }

   f = al_load_font("data/a4_font.tga", 0, 0);
   if (!f) {
      abort_example("Failed to load a4_font.tga\n");
   }

   min_w = 640;
   min_h = 480;
   max_w = 800;
   max_h = 600;
   constr_min_w = constr_min_h = constr_max_w = constr_max_h = true;

   if (!al_set_window_constraints(
          display,
          constr_min_w ? min_w : 0,
          constr_min_h ? min_h : 0,
          constr_max_w ? max_w : 0,
          constr_max_h ? max_h : 0)) {
      abort_example("Unable to set window constraints.\n");
   }

   al_apply_window_constraints(display, true);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_keyboard_event_source());

   redraw = true;
   while (true) {
      if (redraw && al_is_event_queue_empty(queue)) {
         al_clear_to_color(al_map_rgb(255, 0, 0));
         al_draw_scaled_bitmap(bmp,
            0, 0, al_get_bitmap_width(bmp), al_get_bitmap_height(bmp),
            0, 0, al_get_display_width(display), al_get_display_height(display),
            0);

         /* Display screen resolution */
         al_draw_textf(f, al_map_rgb(255, 255, 255), 0, 0, 0,
            "Resolution: %dx%d",
            al_get_display_width(display), al_get_display_height(display));

         if (!al_get_window_constraints(display, &ret_min_w, &ret_min_h,
               &ret_max_w, &ret_max_h))
         {
            abort_example("Unable to get window constraints\n");
         }

         al_draw_textf(f, al_map_rgb(255, 255, 255), 0,
            al_get_font_line_height(f), 0,
            "Min Width: %d, Min Height: %d, Max Width: %d, Max Height: %d",
            ret_min_w, ret_min_h, ret_max_w, ret_max_h);

         al_draw_textf(f, al_map_rgb(255, 255, 255), 0,
            al_get_font_line_height(f) * 2,0,
            "Toggle Restriction: Min Width: Z, Min Height: X, Max Width: C, Max Height: V");

         al_flip_display();
         redraw = false;
      }

      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_DISPLAY_RESIZE) {
         al_acknowledge_resize(event.display.source);
         redraw = true;
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_EXPOSE) {
         redraw = true;
      }
      if (event.type == ALLEGRO_EVENT_KEY_DOWN) {
         if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) {
            break;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_Z) {
            constr_min_w = ! constr_min_w;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_X) {
            constr_min_h = ! constr_min_h;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_C) {
            constr_max_w = ! constr_max_w;
         }
         else if (event.keyboard.keycode == ALLEGRO_KEY_V) {
            constr_max_h = ! constr_max_h;
         }

         redraw = true;

         if (!al_set_window_constraints(display,
               constr_min_w ? min_w : 0,
               constr_min_h ? min_h : 0,
               constr_max_w ? max_w : 0,
               constr_max_h ? max_h : 0)) {
            abort_example("Unable to set window constraints.\n");
         }
         al_apply_window_constraints(display, true);
      }
      if (event.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
   }

   al_destroy_bitmap(bmp);
   al_destroy_display(display);

   return 0;
}
Player::~Player() {
    al_destroy_bitmap(this->pImage);
    al_destroy_bitmap(this->sprite);
}
Beispiel #20
0
MainMenuState::~MainMenuState()
{
    al_destroy_bitmap(background);
}
Beispiel #21
0
	// Method to handle drawing logic of the Character Object
	void DrawObj(ALLEGRO_DISPLAY *screen)
	{
		// X coordinate calculation of selected frame/region
		int PresentFrameX = PresentFrame * F_W;
		// Y coordinate of selected frame/region
		int PresentFrameY = 0;
		// Empty bitmap to store rotated image
		ALLEGRO_BITMAP *rotated = NULL;
		// Creating the new bitmap with width and height same as the selected frame/region
		rotated = al_create_bitmap(F_W, F_H);
		// New bitmap selected for drawing instead of backbuffer
		al_set_target_bitmap(rotated);
		// Particular region/frame is selected and drawn on to the new bitmap
		al_draw_bitmap_region(image, PresentFrameX, PresentFrameY, F_W, F_H, 0, 0, 0);
		// Drawing target changed back to backbuffer of the screen
		al_set_target_bitmap(al_get_backbuffer(screen));


		/* Logic to handle the rotation of the sprite as per Direct
		0 degree is 0 radian
		90 degree is pi / 2
		180 degree is pi
		270 degree is 1.5 * pi
		360 degree is 2 * pi
		Check radian and degree conversion chart
		*/
		switch (Direct)
		{
		case STAND:
			angle = angle; // No rotation
			break;
		case RIGHT:
			angle = 0; // 0 degree rotation
			break;
		case LEFT:
			angle = ALLEGRO_PI; // 180 degree rotation
			break;
		case DOWN:
			angle = ALLEGRO_PI / 2; // 90 degree rotation
			break;
		case UP:
			angle = ALLEGRO_PI * 1.5; // 270 degree rotation
			break;

		}
		// Rotate the new bitmap 'rotated' holding our selected region of the sprite sheet
		// Draw it on to the backbuffer
		al_draw_rotated_bitmap(rotated, F_W / 2, F_H / 2, X, Y, angle, 0);
		// Free resoruce after using ALLEGRO_BITMAP 'rotated'
		al_destroy_bitmap(rotated);
		// Logic to handle frame delay in animation sequence
		if (++DelayCount >= frameDelay)
		{
			// Frame animation sequence logic
			// Increment frame & reset frame counter to 0 after traversing through all frames
			if (++PresentFrame >= NumbOfFrames)PresentFrame = 0;
			// If Character Object is standing, only draw the first frame of the sprite sheet
			if (Direct == STAND){ PresentFrame = 0; DelayCount = frameDelay; }
			// Reset frame delay counter to 0, after it has completed its delay cycle
			DelayCount = 0;
		}
	}
Beispiel #22
0
int main(int argc, char **argv)
{
    //////////////
	if (argc < 2) {
	    cout << "Podaj adres serwera" << endl; return 1;
    }

    string server = string(argv[1]);
    
    if (!connect_to_server(server)) {
        cout << "Połączenie nie powiodło się." << endl; return 1;
    }
    //////////////

   ALLEGRO_DISPLAY *display = NULL;
   ALLEGRO_EVENT_QUEUE *event_queue = NULL;
   ALLEGRO_TIMER *timer = NULL;
   ALLEGRO_BITMAP *bouncer = NULL;
   float bouncer_x = SCREEN_W / 2.0 - BOUNCER_SIZE / 2.0;
   float bouncer_y = SCREEN_H / 2.0 - BOUNCER_SIZE / 2.0;
   bool redraw = true;
 
   if(!al_init()) {
      fprintf(stderr, "failed to initialize allegro!\n");
      return -1;
   }
 
   if(!al_install_mouse()) {
      fprintf(stderr, "failed to initialize the mouse!\n");
      return -1;
   }
 
   timer = al_create_timer(1.0 / FPS);
   if(!timer) {
      fprintf(stderr, "failed to create timer!\n");
      return -1;
   }
 
   display = al_create_display(SCREEN_W, SCREEN_H);
   if(!display) {
      fprintf(stderr, "failed to create display!\n");
      al_destroy_timer(timer);
      return -1;
   }
 
   bouncer = al_create_bitmap(BOUNCER_SIZE, BOUNCER_SIZE);
   if(!bouncer) {
      fprintf(stderr, "failed to create bouncer bitmap!\n");
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
   }
 
   al_set_target_bitmap(bouncer);
 
   al_clear_to_color(al_map_rgb(255, 0, 255));
 
   al_set_target_bitmap(al_get_backbuffer(display));
 
   event_queue = al_create_event_queue();
   if(!event_queue) {
      fprintf(stderr, "failed to create event_queue!\n");
      al_destroy_bitmap(bouncer);
      al_destroy_display(display);
      al_destroy_timer(timer);
      return -1;
   }
 
   al_register_event_source(event_queue, al_get_display_event_source(display));
 
   al_register_event_source(event_queue, al_get_timer_event_source(timer));
 
   al_register_event_source(event_queue, al_get_mouse_event_source());
 
   al_clear_to_color(al_map_rgb(0,0,0));
 
   al_flip_display();
 
   al_start_timer(timer);
 
   while(1)
   {
      ALLEGRO_EVENT ev;
      al_wait_for_event(event_queue, &ev);
 
      /////////////////
 	  int n = service_websockets();
      string s;
      while (receive_packet(s)) {
        cout << "ODEBRAŁEM: " << s << endl;

        stringstream ss;
        
        ss << s;
        string p;
        ss >> p;
        
        if (p == "DRAW") {
            int x,y;
            
            ss >> x; ss >> y;
            al_draw_bitmap(bouncer, x, y, 0);
        }

      }
      /////////////////

      if(ev.type == ALLEGRO_EVENT_TIMER) {
         redraw = true;
      }
      else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
         break;
      }
      else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES ||
              ev.type == ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY) {
 
         bouncer_x = ev.mouse.x;
         bouncer_y = ev.mouse.y;
      }
      else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP) {
            stringstream ss;
            ss << "DRAW " << ev.mouse.x << " " << ev.mouse.y;
            send_packet(ss.str());
      }
 
      if(redraw && al_is_event_queue_empty(event_queue)) {
         redraw = false;
  
         al_flip_display();
      }
   }
Beispiel #23
0
void Menu_Unload(struct Game *game) {
	if (!game->menu.loaded) return;
	if (game->gamestate==GAMESTATE_MENU) Menu_Stop(game);
	al_destroy_bitmap(game->menu.pinkcloud);
	al_destroy_bitmap(game->menu.image);
	al_destroy_bitmap(game->menu.cloud);
	al_destroy_bitmap(game->menu.cloud2);
	al_destroy_bitmap(game->menu.pinkcloud_bitmap);
	al_destroy_bitmap(game->menu.rain_bitmap);
	al_destroy_bitmap(game->menu.mountain);
	al_destroy_bitmap(game->menu.pie_bitmap);
	al_destroy_bitmap(game->menu.logo);
	al_destroy_bitmap(game->menu.logoblur);
	al_destroy_bitmap(game->menu.glass);
	al_destroy_bitmap(game->menu.blurbg);
	al_destroy_bitmap(game->menu.blurbg2);
	al_destroy_font(game->menu.font_title);
	al_destroy_font(game->menu.font_subtitle);
	al_destroy_font(game->menu.font);
	al_destroy_font(game->menu.font_selected);
	al_destroy_sample_instance(game->menu.music);
	al_destroy_sample_instance(game->menu.rain_sound);
	al_destroy_sample_instance(game->menu.click);
	al_destroy_sample(game->menu.sample);
	al_destroy_sample(game->menu.rain_sample);
	al_destroy_sample(game->menu.click_sample);
	game->menu.loaded = false;
}
Beispiel #24
0
static ALLEGRO_BITMAP *d3d_create_bitmap_from_surface(LPDIRECT3DSURFACE9 surface,
   int flags)
{
   ALLEGRO_BITMAP *bitmap;
   ALLEGRO_BITMAP_D3D *d3d_bmp;
   D3DSURFACE_DESC desc;
   D3DLOCKED_RECT surf_locked_rect;
   D3DLOCKED_RECT sys_locked_rect;
   ALLEGRO_STATE backup;
   int format;
   unsigned int y;

   if (surface->GetDesc(&desc) != D3D_OK) {
      ALLEGRO_ERROR("d3d_create_bitmap_from_surface: GetDesc failed.\n");
      return NULL;
   }

   if (surface->LockRect(&surf_locked_rect, 0, D3DLOCK_READONLY) != D3D_OK) {
      ALLEGRO_ERROR("d3d_create_bitmap_from_surface: LockRect failed.\n");
      return NULL;
   }

   al_store_state(&backup, ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);

   format = _al_d3d_format_to_allegro(desc.Format);

   al_set_new_bitmap_format(format);
   al_set_new_bitmap_flags(flags);

   bitmap = al_create_bitmap(desc.Width, desc.Height);
   d3d_bmp = (ALLEGRO_BITMAP_D3D *)bitmap;

   al_restore_state(&backup);

   if (!bitmap) {
      surface->UnlockRect();
      return NULL;
   }

   if (d3d_bmp->system_texture->LockRect(0, &sys_locked_rect, 0, 0) != D3D_OK) {
      surface->UnlockRect();
      al_destroy_bitmap(bitmap);
      ALLEGRO_ERROR("d3d_create_bitmap_from_surface: Lock system texture failed.\n");
      return NULL;
   }

   for (y = 0; y < desc.Height; y++) {
      memcpy(
         ((char*)sys_locked_rect.pBits)+(sys_locked_rect.Pitch*y),
         ((char*)surf_locked_rect.pBits)+(surf_locked_rect.Pitch*y),
         desc.Width*4
      );
   }

   surface->UnlockRect();
   d3d_bmp->system_texture->UnlockRect(0);

   if (d3d_bmp->display->device->UpdateTexture(
         (IDirect3DBaseTexture9 *)d3d_bmp->system_texture,
         (IDirect3DBaseTexture9 *)d3d_bmp->video_texture) != D3D_OK) {
      ALLEGRO_ERROR("d3d_create_bitmap_from_texture: Couldn't update texture.\n");
   }

   return bitmap;
}
Beispiel #25
0
int main (int argc, char **argv)
{
	ALLEGRO_DISPLAY *display = NULL;
	ALLEGRO_EVENT_QUEUE *event_queue = NULL;
	ALLEGRO_BITMAP *background = NULL;
	ALLEGRO_BITMAP *blue_box = NULL;
	bool key[4] = { false, false, false, false };
	bool doexit = false;

	if (!al_init()) {
		fprintf(stderr, "failed to initialize allegro!\n");
		return -1;
	}

	if (!al_init_image_addon()) {
		printf("Failed to initialize the image addon");
		return -1;
	}

	if (!al_install_keyboard()) {
		printf("Failed to initialize the keyboard!\n");
		return -1;
	}

	display = al_create_display(SCREEN_W, SCREEN_H);
	if (!display) {
		fprintf(stderr, "failed to create display!\n");
		return -1;
	}

	// Set up the event queue
	event_queue = al_create_event_queue();
	if (!event_queue) {
		printf("Failed to create event_queue!\n");
		al_destroy_display(display);
		return -1;
	}

	al_register_event_source(event_queue, al_get_display_event_source(display));

	al_register_event_source(event_queue, al_get_keyboard_event_source());

	background = al_load_bitmap("forest.png");
	if (!background) {
		printf("Failed to load background");
		al_destroy_display(display);
		return -1;
	}

	blue_box = al_load_bitmap("BlueBox.png");
	if (!blue_box) {
		printf("Failed to load blueBox");
		al_destroy_bitmap(background);
		al_destroy_display(display);
		return -1;
	}

	//al_draw_bitmap(blue_box, 20, 400, 0);
	Fighter fighter = Fighter(vector_2d(20, 400), vector_2d(0, 0), blue_box);
	
	al_flip_display();

	// Game Loop
	while(true)
	{
		ALLEGRO_EVENT ev;
		al_get_next_event(event_queue, &ev);


		// Update
		fighter.Update(ev);


		// Draw
		al_draw_bitmap(background, 0, 0, 0);
		fighter.Draw();
		al_flip_display();
	}

	fighter.~Fighter();
	al_destroy_bitmap(background);
	al_destroy_display(display);

	return 0;
}
Beispiel #26
0
static void d3d_draw_bitmap_region(
   ALLEGRO_BITMAP *src,
   ALLEGRO_COLOR tint,
   float sx, float sy, float sw, float sh, int flags)
{
   ALLEGRO_BITMAP *dest = al_get_target_bitmap();
   ALLEGRO_BITMAP_D3D *d3d_dest = (ALLEGRO_BITMAP_D3D *)dest;
   ALLEGRO_BITMAP_D3D *d3d_src = (ALLEGRO_BITMAP_D3D *)src;

   if (!_al_d3d_render_to_texture_supported()) {
      _al_draw_bitmap_region_memory(src, tint,
         (int)sx, (int)sy, (int)sw, (int)sh, 0, 0,
         (int)flags);
      return;
   }
   
   if (d3d_dest->display->device_lost)
      return;

   _al_d3d_set_bitmap_clip(dest);

   /* For sub-bitmaps */
   if (src->parent) {
      sx += src->xofs;
      sy += src->yofs;
      src = src->parent;
      d3d_src = (ALLEGRO_BITMAP_D3D *)src;
   }
   if (dest->parent) {
      dest = dest->parent;
      d3d_dest = (ALLEGRO_BITMAP_D3D *)dest;
   }

   if (d3d_src->is_backbuffer) {
      IDirect3DSurface9 *surface;
      D3DSURFACE_DESC desc;
      if (d3d_src->display->render_target->GetDesc(&desc) != D3D_OK) {
         ALLEGRO_ERROR("d3d_draw_bitmap_region: GetDesc failed.\n");
         return;
      }
      if (desc.MultiSampleType == D3DMULTISAMPLE_NONE) {
         surface = d3d_src->display->render_target;
      }
      else {
         RECT r;
         if (d3d_src->display->device->CreateRenderTarget(
		desc.Width,
		desc.Height,
		desc.Format,
		D3DMULTISAMPLE_NONE,
		0,
		TRUE,
		&surface,
		NULL
	) != D3D_OK) {
            ALLEGRO_ERROR(
	    	"d3d_draw_bitmap_region: CreateRenderTarget failed.\n");
            return;
         }
	 r.top = 0;
	 r.left = 0;
	 r.right = desc.Width;
	 r.bottom = desc.Height;
	 if (d3d_src->display->device->StretchRect(
	 	d3d_src->display->render_target,
		&r,
		surface,
		&r,
		D3DTEXF_NONE
	 ) != D3D_OK) {
	    ALLEGRO_ERROR("d3d_draw_bitmap_region: StretchRect failed.\n");
	    surface->Release();
	    return;
	 }
      }
      ALLEGRO_BITMAP *tmp_bmp = d3d_create_bitmap_from_surface(
         surface,
         src->flags);
      if (tmp_bmp) {
         d3d_draw_bitmap_region((ALLEGRO_BITMAP *)tmp_bmp, tint,
            sx, sy, sw, sh, flags);
         al_destroy_bitmap(tmp_bmp);
	 if (desc.MultiSampleType != D3DMULTISAMPLE_NONE) {
	    surface->Release();
	 }
      }
      return;
   }

   _al_d3d_set_blender(d3d_dest->display);

   d3d_draw_textured_quad(
      d3d_dest->display, d3d_src, tint,
      sx, sy, sw, sh, flags);

   d3d_dest->modified = true;
}
Beispiel #27
0
void Menu::Finish()
{
	al_destroy_bitmap( background );
	AUDIO->StopMusic();
}
Beispiel #28
0
static void load_jpg_entry_helper(ALLEGRO_FILE *fp,
                                  struct load_jpg_entry_helper_data *data)
{
    struct jpeg_decompress_struct cinfo;
    struct my_err_mgr jerr;
    ALLEGRO_LOCKED_REGION *lock;
    int w, h, s;

    data->error = false;

    cinfo.err = jpeg_std_error(&jerr.pub);
    jerr.pub.error_exit = my_error_exit;
    if (setjmp(jerr.jmpenv) != 0) {
        /* Longjmp'd. */
        data->error = true;
        goto longjmp_error;
    }

    data->buffer = _AL_MALLOC(BUFFER_SIZE);
    if (!data->buffer) {
        data->error = true;
        goto error;
    }

    jpeg_create_decompress(&cinfo);
    jpeg_packfile_src(&cinfo, fp, data->buffer);
    jpeg_read_header(&cinfo, true);
    jpeg_start_decompress(&cinfo);

    w = cinfo.output_width;
    h = cinfo.output_height;
    s = cinfo.output_components;

    /* Only one and three components make sense in a JPG file. */
    if (s != 1 && s != 3) {
        data->error = true;
        goto error;
    }

    data->bmp = al_create_bitmap(w, h);
    if (!data->bmp) {
        data->error = true;
        goto error;
    }

    /* Allegro's pixel format is endian independent, so that in
     * ALLEGRO_PIXEL_FORMAT_RGB_888 the lower 8 bits always hold the Blue
     * component.  On a little endian system this is in byte 0.  On a big
     * endian system this is in byte 2.
     *
     * libjpeg expects byte 0 to hold the Red component, byte 1 to hold the
     * Green component, byte 2 to hold the Blue component.  Hence on little
     * endian systems we need the opposite format, ALLEGRO_PIXEL_FORMAT_BGR_888.
     */
#ifdef ALLEGRO_BIG_ENDIAN
    lock = al_lock_bitmap(data->bmp, ALLEGRO_PIXEL_FORMAT_RGB_888,
                          ALLEGRO_LOCK_WRITEONLY);
#else
    lock = al_lock_bitmap(data->bmp, ALLEGRO_PIXEL_FORMAT_BGR_888,
                          ALLEGRO_LOCK_WRITEONLY);
#endif
    al_set_target_bitmap(data->bmp);

    if (s == 3) {
        /* Colour. */
        int y;

        for (y = cinfo.output_scanline; y < h; y = cinfo.output_scanline) {
            unsigned char *out[1];
            out[0] = ((unsigned char *)lock->data) + y * lock->pitch;
            jpeg_read_scanlines(&cinfo, (void *)out, 1);
        }
    }
    else if (s == 1) {
        /* Greyscale. */
        unsigned char *in;
        unsigned char *out;
        int x, y;

        data->row = _AL_MALLOC(w);
        for (y = cinfo.output_scanline; y < h; y = cinfo.output_scanline) {
            jpeg_read_scanlines(&cinfo, (void *)&data->row, 1);
            in = data->row;
            out = ((unsigned char *)lock->data) + y * lock->pitch;
            for (x = 0; x < w; x++) {
                *out++ = *in;
                *out++ = *in;
                *out++ = *in;
                in++;
            }
        }
    }

error:
    jpeg_finish_decompress(&cinfo);

longjmp_error:
    jpeg_destroy_decompress(&cinfo);

    if (data->bmp) {
        if (al_is_bitmap_locked(data->bmp)) {
            al_unlock_bitmap(data->bmp);
        }
        if (data->error) {
            al_destroy_bitmap(data->bmp);
            data->bmp = NULL;
        }
    }

    _AL_FREE(data->buffer);
    _AL_FREE(data->row);
}
Beispiel #29
0
// Funcao principal.
int main(void)
{
	int bitmapSize;

	srand(time(0));

    // Funcao de inicializacao da Allegro
	al_init();

	// Chamada de funcao para forcar o uso de OpenGL ao inves de DirectX (DirectX eh o default)
	al_set_new_display_flags(ALLEGRO_OPENGL);

	// Funcao para criar uma janela com as dimensoes passadas como parametro, que torna-se
	// automaticamente ativa, com o backbuffer selecionado para desenho. Os parametros
	// da janela sao determinados pelas ultimas chamadas a "al_set_new_display_*".
        ALLEGRO_DISPLAY *display = al_create_display(600, 600);

	height = 600;

	// Inicializa the "Image IO addon", que tem funcoes declaradas no seguinte
	// header: #include <allegro5/allegro_image.h>
	al_init_image_addon();

	// Prototipo: ALLEGRO_BITMAP *al_load_bitmap(const char *filename)
	// Carrega uma imagem para a struct ALLEGRO_BITMAP. O tipo do
	// arquivo é determinado pela extensao (bmp ou png).
	parent = al_load_bitmap("char9.png");
	if (!parent) {
		std::cout << "Error loading data/char9.png\n";
      return 1;
	}

	add_sprites(parent);

	// Funcao usada para especificar o titulo da janela.
	//al_set_window_title("Teste da Allegro com Sprite Animada");

	// Funcao que instala um driver de teclado. Se der problema, retorna false, senao retorna true.
	if ( !al_install_keyboard() ) {
		return 1; // encerra se deu problema
	}

	// Funcao que instala um driver de mouse. Se der problema, retorna false, senao retorna true.
	if ( !al_install_mouse() ){
		return 1; // encerra se deu problema
	}

	// ALLEGRO_TIMER* al_install_timer(double speed_secs)
	// Funcao que instala um novo timer, retornando o ponteiro para o mesmo. Se der
	// problema, retorna NULL. O valor passado como parametro deve ser positivo.
	// O novo timer (ou controlador de tempo) é inicializado parado.
	ALLEGRO_TIMER *timer = al_create_timer(1.0 / FPS);

	// Funcao que cria uma fila de eventos nova e vazia, retornando o ponteiro para o objeto criado,
	// ou NULL se ocorreu um erro.
	event_queue = al_create_event_queue();
	if (event_queue==NULL) {
		return 1; // encerra se deu problema
	}

	// al_register_event_source(): registra a fonte de eventos com a fila de eventos especificada.
	// al_get_mouse_event_source(): recupera a fonte de eventos do mouse.
	// al_get_keyboard_event_source(): recupera a fonte de eventos do teclado.
	// al_get_display_event_source(): recupera a fonte de evento associada a janela.
	// al_get_timer_event_source(ALLEGRO_TIMER *timer): recupera a fonte de eventos associada.
	al_register_event_source(event_queue, al_get_mouse_event_source());
	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));

	// void al_start_timer(ALLEGRO_TIMER *timer) inicia o timer passado por parametro.
	// A partir disso, o contador do timer vai incrementar em um frequencia constante
	// e vai comecar a gerar eventos. Inicializar um timer que ja foi inicializado nao
	// faz nada.
	al_start_timer(timer);

	// Funcao que estabelece o loop do programa, que fica a espera de eventos
	main_loop();

	al_destroy_bitmap(parent);
    return 0;
}
Beispiel #30
0
/*
* Frees memory allocated to image resources.
*/
Tetris::Utils::ImageManager::~ImageManager() {
	al_destroy_bitmap(gameMusic);
	al_destroy_bitmap(Tetris);
	al_destroy_bitmap(wall);
}