Esempio n. 1
0
int draw_classic_symbols(Game *g, Board *b)
{
    // create symbols
    b->symbol_bmp[SYM_FORBIDDEN] = al_create_bitmap(b->clue_unit_size, b->clue_unit_size);
    b->symbol_bmp[SYM_SWAPPABLE] = al_create_bitmap(3*b->clue_unit_size + 2*b->clue_unit_space, b->clue_unit_size);
    b->symbol_bmp[SYM_ONE_SIDE] = al_create_bitmap(b->clue_unit_size, b->clue_unit_size);
    b->symbol_bmp[SYM_ONLY_ONE] = al_create_bitmap(b->clue_unit_size, 3*b->clue_unit_size + 2*b->clue_unit_space);

    if( (!b->symbol_bmp[SYM_FORBIDDEN]) || (!b->symbol_bmp[SYM_SWAPPABLE]) || (!b->symbol_bmp[SYM_ONE_SIDE]) || (!b->symbol_bmp[SYM_ONLY_ONE])){
        fprintf(stderr, "Error creating bitmap.\n");
        return -1;
    }
    
    al_set_target_bitmap(b->symbol_bmp[SYM_FORBIDDEN]);
    al_clear_to_color(NULL_COLOR);
    al_draw_scaled_bitmap(symbol_bmp[SYM_FORBIDDEN], 0, 0, 80, 80, 0,0,b->clue_unit_size, b->clue_unit_size, 0);
    
    al_set_target_bitmap(b->symbol_bmp[SYM_SWAPPABLE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_scaled_bitmap(symbol_bmp[SYM_SWAPPABLE], 0, 0, 3*80, 80, 0,0,3*b->clue_unit_size, b->clue_unit_size, 0);
    
    al_set_target_bitmap(b->symbol_bmp[SYM_ONE_SIDE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_scaled_bitmap(symbol_bmp[SYM_ONE_SIDE], 0, 0, 80, 80, 0,0,b->clue_unit_size, b->clue_unit_size, 0);
    
    al_set_target_bitmap(b->symbol_bmp[SYM_ONLY_ONE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_scaled_bitmap(symbol_bmp[SYM_ONLY_ONE], 0, 0, 80, 3*80, 0,0,b->clue_unit_size, 3*b->clue_unit_size, 0);
    
    return 0;
}
Esempio n. 2
0
Overlay::Overlay(renderer* parent) : parent(parent)
{
	{
		CoreSuspender suspend;
		//parent->zoom(df::zoom_commands::zoom_reset);
		good_viewscreen = false;
		ReadTileLocations();
		copy_from_inner(); 
	}

	front_mutex = al_create_mutex();

	int32_t flags = al_get_new_bitmap_flags();
	if(al_get_current_display() != NULL){
		al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_ALPHA_TEST);
	}
	front = al_create_bitmap(0,0);
	if(al_get_current_display() != NULL){
		al_set_new_bitmap_flags(al_get_bitmap_flags(al_get_backbuffer(al_get_current_display())));
	}
	back = al_create_bitmap(0,0);
	al_set_new_bitmap_flags(flags);

	Flip();
};
Esempio n. 3
0
TRANSITION *create_transition(GAMESTATE * from, GAMESTATE * to,
                              double duration)
{
   TRANSITION *t = malloc(sizeof(TRANSITION));

   t->from = from;
   t->to = to;
   t->duration = duration;
   t->progress = 0.0f;

   t->from_bmp = al_create_bitmap(screen_width, screen_height);
   al_set_target_bitmap(t->from_bmp);
   if (from) {
      from->draw();
   } else {
      al_clear_to_color(al_map_rgb(0, 0, 0));
   }
   al_set_target_backbuffer(screen);

   t->to_bmp = al_create_bitmap(screen_width, screen_height);
   al_set_target_bitmap(t->to_bmp);

   if (to) {
      to->draw();
   } else {
      al_clear_to_color(al_map_rgb(0, 0, 0));
   }
   al_set_target_backbuffer(screen);

   return t;
}
bool Player::load(void)
{
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);

   bitmap = al_load_bitmap(getResource("gfx/ship.tga"));
   if (!bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship.tga"));
      return false;
   }

   trans_bitmap = al_create_bitmap(al_get_bitmap_width(bitmap),
      al_get_bitmap_height(bitmap));
   if (!trans_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/ship_trans.tga"));
      al_destroy_bitmap(bitmap);
      return false;
   }

   /* Make a translucent copy of the ship */
   al_set_target_bitmap(trans_bitmap);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_tinted_bitmap(bitmap, al_map_rgba(255, 255, 255, 160),
      0, 0, 0);
   al_restore_state(&state);

   trail_bitmap = al_load_bitmap(getResource("gfx/trail.tga"));
   if (!trail_bitmap) {
      debug_message("Error loading %s\n", getResource("gfx/trail.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      return false;
   }

   icon = al_load_bitmap(getResource("gfx/ship_icon.tga"));
   if (!icon) {
      debug_message("Error loading %s\n", getResource("gfx/icon.tga"));
      al_destroy_bitmap(bitmap);
      al_destroy_bitmap(trans_bitmap);
      al_destroy_bitmap(trail_bitmap);
      return false;
   }

   highscoreBitmap = al_create_bitmap(300, 200);
   al_set_target_bitmap(highscoreBitmap);
   al_clear_to_color(al_map_rgba(0, 0, 0, 0));

   al_restore_state(&state);

   draw_radius = al_get_bitmap_width(bitmap)/2;
   radius = draw_radius / 2;

   newGame();
   reset();

   return true;
}
Esempio n. 5
0
void mapper_replace_tiles(ALLEGRO_BITMAP * bp)
{
	int i, j;
	T3F_ANIMATION * ap = NULL;
	ALLEGRO_BITMAP * newbp = NULL;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	int current_tile = mapper_current_tile;

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER | ALLEGRO_STATE_TRANSFORM);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	for(i = 0; i < al_get_bitmap_height(bp) / mapper_tile_height; i++)
	{
		for(j = 0; j < al_get_bitmap_width(bp) / mapper_tile_width; j++)
		{
			if(current_tile < mapper_tileset->tiles)
			{
				ap = t3f_create_animation();
				if(ap)
				{
					newbp = al_create_bitmap(mapper_tile_width, mapper_tile_height);
					if(newbp)
					{
						al_set_target_bitmap(newbp);
						al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
						al_draw_bitmap(bp, -j * mapper_tile_width, -i * mapper_tile_height, 0);
						t3f_animation_add_bitmap(ap, newbp);
						t3f_animation_add_frame(ap, 0, 0, 0, 0, mapper_tile_width, mapper_tile_height, 0, 1, 0);
						t3f_destroy_animation(mapper_tileset->tile[current_tile]->ap);
						mapper_tileset->tile[current_tile]->ap = ap;
					}
				}
				current_tile++;
			}
			else
			{
				ap = t3f_create_animation();
				if(ap)
				{
					newbp = al_create_bitmap(mapper_tile_width, mapper_tile_height);
					if(newbp)
					{
						al_set_target_bitmap(newbp);
						al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
						al_draw_bitmap(bp, -j * mapper_tile_width, -i * mapper_tile_height, 0);
						t3f_animation_add_bitmap(ap, newbp);
						t3f_animation_add_frame(ap, 0, 0, 0, 0, mapper_tile_width, mapper_tile_height, 0, 1, 0);
						t3f_add_tile(mapper_tileset, ap);
					}
				}
			}
		}
	}
	al_restore_state(&old_state);
}
void _al_win_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bmp)
{
   ALLEGRO_BITMAP *sm_bmp, *big_bmp;
   HICON sm_icon, big_icon, old_small, old_big;
   ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)display;
   ALLEGRO_STATE backup;
   int sm_w, sm_h, big_w, big_h;

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);

   sm_w = GetSystemMetrics(SM_CXSMICON);
   sm_h = GetSystemMetrics(SM_CYSMICON);
   big_w = GetSystemMetrics(SM_CXICON);
   big_h = GetSystemMetrics(SM_CYICON);

   sm_bmp = al_create_bitmap(sm_w, sm_h);
   al_set_target_bitmap(sm_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, sm_w, sm_h, 0);

   big_bmp = al_create_bitmap(big_w, big_h);
   al_set_target_bitmap(big_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, big_w, big_h, 0);

   al_restore_state(&backup);

   sm_icon = _al_win_create_icon(win_display->window, sm_bmp, 0, 0, false, false);
   big_icon = _al_win_create_icon(win_display->window, big_bmp, 0, 0, false, false);

   old_small = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_SMALL, (LPARAM)sm_icon);
   old_big = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_BIG, (LPARAM)big_icon);

   if (old_small)
      DestroyIcon(old_small);
   if (old_big)
      DestroyIcon(old_big);

   al_destroy_bitmap(sm_bmp);
   al_destroy_bitmap(big_bmp);
}
Esempio n. 7
0
int init_bitmaps_classic(Board *b){
    ALLEGRO_BITMAP *test_bmp;
    int i,j;
    ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
    al_set_target_bitmap(NULL);
    
    // tile_file.bmp should be a bmp with 80x80 tiles, 10 rows of 8 tiles
    // the first row of tiles is ignored. Rows 2 to 9 are the game tiles
    // the last row should contain the extra symbols
    // b->clue_unit_space must be 0
    
    if( !(test_bmp = al_load_bitmap("tile_file.bmp")) ){
        fprintf(stderr, "Error loading tile_file.bmp.\n");
        return -1;
    }
    ALLEGRO_COLOR trans = al_get_pixel (test_bmp, 2*80, 9*80 + 40);
    al_convert_mask_to_alpha(test_bmp, trans);
    
    for(i=0;i<8;i++){
        for(j=0;j<8;j++){
            // create basic bitmaps from big file
            basic_bmp[i][j] = al_create_bitmap(80, 80);
            al_set_target_bitmap(basic_bmp[i][j]);
            al_clear_to_color(NULL_COLOR);
            al_draw_bitmap_region(test_bmp, j*80, (i+1)*80, 80, 80, 0,0,0);
        }
    }
    
    // create symbols
    symbol_bmp[SYM_FORBIDDEN] = al_create_bitmap(80,80);
    al_set_target_bitmap(symbol_bmp[SYM_FORBIDDEN]);
    al_clear_to_color(NULL_COLOR);
    al_draw_bitmap_region(test_bmp, 80, 9*80, 80, 80, 0, 0, 0);
    
    symbol_bmp[SYM_SWAPPABLE] = al_create_bitmap(3*80, 80);
    al_set_target_bitmap(symbol_bmp[SYM_SWAPPABLE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_bitmap_region(test_bmp, 2*80, 9*80, 3*80, 80, 0, 0,0);
    
    symbol_bmp[SYM_ONE_SIDE] = al_create_bitmap(80,80);
    al_set_target_bitmap(symbol_bmp[SYM_ONE_SIDE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_bitmap_region(test_bmp, 5*80, 9*80, 80, 80, 0, 0, 0);
    
    symbol_bmp[SYM_ONLY_ONE] = al_create_bitmap(80, 3*80);
    al_set_target_bitmap(symbol_bmp[SYM_ONLY_ONE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_bitmap_region(test_bmp, 6*80, 9*80, 80, 80, 0, 120, 0);
    
    al_set_target_bitmap(dispbuf);
    return 0;
};
bool Imgui_ImplA5_CreateDeviceObjects()
{
    ImGuiIO &io = ImGui::GetIO();

    // Build texture
    unsigned char *pixels;
    int width, height;
    io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);

    // Create texture
    int flags = al_get_new_bitmap_flags();
    int fmt = al_get_new_bitmap_format();
    al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP|ALLEGRO_MIN_LINEAR|ALLEGRO_MAG_LINEAR);
    al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE);
    ALLEGRO_BITMAP* img = al_create_bitmap(width, height);
    al_set_new_bitmap_flags(flags);
    al_set_new_bitmap_format(fmt);
    if (!img) 
        return false;

    ALLEGRO_LOCKED_REGION *locked_img = al_lock_bitmap(img, al_get_bitmap_format(img), ALLEGRO_LOCK_WRITEONLY);
    if (!locked_img) 
    {
        al_destroy_bitmap(img);
        return false;
    }
    memcpy(locked_img->data, pixels, sizeof(int)*width*height);
    al_unlock_bitmap(img);

    // Convert software texture to hardware texture.
    ALLEGRO_BITMAP* cloned_img = al_clone_bitmap(img);
    al_destroy_bitmap(img);
    if (!cloned_img) 
        return false;

    // Store our identifier
    io.Fonts->TexID = (void*)cloned_img;
    g_Texture = cloned_img;

    // Cleanup (don't clear the input data if you want to append new fonts later)
    io.Fonts->ClearInputData();
    io.Fonts->ClearTexData();

    // Create an invisible mouse cursor
    // Because al_hide_mouse_cursor() seems to mess up with the actual inputs..
    ALLEGRO_BITMAP* mouse_cursor = al_create_bitmap(8,8);
    g_MouseCursorInvisible = al_create_mouse_cursor(mouse_cursor, 0, 0);
    al_destroy_bitmap(mouse_cursor);

    return true;
}
Esempio n. 9
0
int draw_symbols(Game *g, Board *b)
{
    float cus = b->clue_unit_size;
    
    // create symbols
    b->symbol_bmp[SYM_FORBIDDEN] = al_create_bitmap(cus, cus);
    b->symbol_bmp[SYM_SWAPPABLE] = al_create_bitmap(3*cus + 2*b->clue_unit_space, cus);
    b->symbol_bmp[SYM_ONE_SIDE] = al_create_bitmap(cus, cus);
    b->symbol_bmp[SYM_ONLY_ONE] = al_create_bitmap(cus, 3*cus + 2*b->clue_unit_space);
    
    if( (!b->symbol_bmp[SYM_FORBIDDEN]) || (!b->symbol_bmp[SYM_SWAPPABLE]) || (!b->symbol_bmp[SYM_ONE_SIDE]) || (!b->symbol_bmp[SYM_ONLY_ONE])){
        fprintf(stderr, "Error creating bitmap.\n");
        return -1;
    }
    
    al_set_target_bitmap(b->symbol_bmp[SYM_FORBIDDEN]);
    al_clear_to_color(NULL_COLOR);
    al_draw_line(0, 0, cus, cus,SYMBOL_COLOR,cus*0.05);
    al_draw_line(0, cus, cus,0, SYMBOL_COLOR,cus*0.05);
    
    al_set_target_bitmap(b->symbol_bmp[SYM_SWAPPABLE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_line(cus*0.7,cus*0.9, cus*(3-0.7),cus*0.9, SYMBOL_COLOR, 2);
    draw_horizontal_arrow((3*cus + 2*b->clue_unit_space)/2, cus*0.9, cus/2, cus*0.9, SYMBOL_COLOR, cus*0.05);
    draw_horizontal_arrow((3*cus + 2*b->clue_unit_space)/2, cus*0.9, (3*cus + 2*b->clue_unit_space)-cus/2, cus*0.9, SYMBOL_COLOR, cus*0.05);
    
    
    al_set_target_bitmap(b->symbol_bmp[SYM_ONE_SIDE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_filled_circle(cus/2, cus*0.8, 0.05*cus, SYMBOL_COLOR);
    al_draw_filled_circle(cus/2 - 0.2*cus, cus*0.8, 0.05*cus, SYMBOL_COLOR);
    al_draw_filled_circle(cus/2 + 0.2*cus, cus*0.8, 0.05*cus, SYMBOL_COLOR);

//    al_draw_textf(tile_font3, WHITE_COLOR, cus/2,cus/2-al_get_font_line_height(tile_font3)/2, ALLEGRO_ALIGN_CENTER, "%s", "...");
    draw_horizontal_arrow(cus*0.2, cus*0.5, cus*0.8, cus*0.5, SYMBOL_COLOR, cus*0.05);
    
    al_set_target_bitmap(b->symbol_bmp[SYM_ONLY_ONE]);
    al_clear_to_color(NULL_COLOR);
    al_draw_line(cus*0.975, 2.5*cus + 2*b->clue_unit_space, cus*0.975, 1.5*cus + b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    draw_horizontal_arrow(cus, 2.5*cus + 2*b->clue_unit_space, cus*0.7, 2.5*cus + 2*b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    draw_horizontal_arrow(cus, 1.5*cus + b->clue_unit_space, cus*0.7, 1.5*cus + b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    
    al_draw_line(cus*0.025, 2.5*cus + 2*b->clue_unit_space, cus*0.025, 1.5*cus + b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    draw_horizontal_arrow(0, 2.5*cus + 2*b->clue_unit_space, cus*0.3, 2.5*cus + 2*b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    draw_horizontal_arrow(0, 1.5*cus + b->clue_unit_space, cus*0.3, 1.5*cus + b->clue_unit_space, SYMBOL_COLOR, cus*0.05);
    
    al_draw_filled_circle(cus/2, 2*cus + 1.5*b->clue_unit_space, cus*0.15, SYMBOL_COLOR);
    al_draw_line(cus/2, (2-0.08)*cus + 1.5*b->clue_unit_space, cus/2, (2+0.08)*cus + 1.5*b->clue_unit_space, WHITE_COLOR, cus*0.05);

    return 0;
}
Esempio n. 10
0
/* Initialize the example. */
static void init(void)
{
   ex.BUTTONS_X = 40 + 110 * 4;
   ex.FPS = 60;

   ex.myfont = al_load_font("data/font.tga", 0, 0);
   if (!ex.myfont) {
      abort_example("data/font.tga not found\n");
   }
   ex.example = create_example_bitmap();

   ex.offscreen = al_create_bitmap(640, 480);
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   ex.memory = al_create_bitmap(640, 480);
}
Esempio n. 11
0
/* Create an example bitmap. */
static ALLEGRO_BITMAP *create_example_bitmap(void)
{
   ALLEGRO_BITMAP *bitmap;
   int i, j;
   ALLEGRO_LOCKED_REGION *locked;
   unsigned char *data;

   bitmap = al_create_bitmap(100, 100);
   locked = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_WRITEONLY);
   data = locked->data;
 
   for (j = 0; j < 100; j++) {
      for (i = 0; i < 100; i++) {
         int x = i - 50, y = j - 50;
         int r = sqrt(x * x + y * y);
         float rc = 1 - r / 50.0;
         if (rc < 0)
            rc = 0;
         data[i * 4 + 0] = i * 255 / 100;
         data[i * 4 + 1] = j * 255 / 100;
         data[i * 4 + 2] = rc * 255;
         data[i * 4 + 3] = rc * 255;
      }
      data += locked->pitch;
   }
   al_unlock_bitmap(bitmap);

   return bitmap;
}
Esempio n. 12
0
bool BigBitmap::Draw_bitmap_region(float sx, float sy, float sw, float sh, float dx, float dy, int flags)
{

    int start_w = floor(sx / region_size_w);
    start_w = (start_w < 0 ? 0 : start_w);
    int start_h = floor(sy / region_size_h);
    start_h = (start_h < 0 ? 0 : start_h);
    int fin_w = ceil((sx + sw) / region_size_w);
    fin_w = ( fin_w > w_regions ? w_regions : fin_w);
    int fin_h = ceil((sy + sh) / region_size_h);
    fin_h = ( fin_h > h_regions ? h_regions : fin_h);
    int offset_w = sx - start_w*region_size_w,
    offset_h = sy - start_h*region_size_h;

    if(tmpbmp != nullptr)
        al_destroy_bitmap(tmpbmp);

    ALLEGRO_BITMAP *restoreto = al_get_target_bitmap();
    tmpbmp = al_create_bitmap(sw, sh);
    al_set_target_bitmap(tmpbmp);
    al_clear_to_color(al_map_rgb(0,0,0));

    for(int h = start_h; h < fin_h; h++)
    {
        for(int w = start_w; w < fin_w; w++)
        {
            al_draw_bitmap(bitmaps[h*w_regions + w], (w-start_w)*region_size_w - offset_w, (h-start_h)*region_size_h - offset_h, 0);

        }
    }

    al_set_target_bitmap(restoreto);
    al_draw_bitmap(tmpbmp, dx, dy, flags);
    return true;
}
Esempio n. 13
0
static ALLEGRO_BITMAP *example_bitmap(int w, int h)
{
   int i, j;
   float mx = w * 0.5;
   float my = h * 0.5;
   ALLEGRO_STATE state;
   ALLEGRO_BITMAP *pattern = al_create_bitmap(w, h);
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(pattern);
   al_lock_bitmap(pattern, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
   for (i = 0; i < w; i++) {
      for (j = 0; j < h; j++) {
         float a = atan2(i - mx, j - my);
         float d = sqrt(pow(i - mx, 2) + pow(j - my, 2));
         float sat = pow(1.0 - 1 / (1 + d * 0.1), 5);
         float hue = 3 * a * 180 / ALLEGRO_PI;
         hue = (hue / 360 - floorf(hue / 360)) * 360;
         al_put_pixel(i, j, al_color_hsv(hue, sat, 1));
      }
   }
   al_put_pixel(0, 0, al_map_rgb(0, 0, 0));
   al_unlock_bitmap(pattern);
   al_restore_state(&state);
   return pattern;
}
Esempio n. 14
0
int main(int argc, char **argv)
{
	al_init();
	al_init_image_addon();

	al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP | ALLEGRO_NO_PREMULTIPLIED_ALPHA);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);

	ALLEGRO_BITMAP *tm = al_load_bitmap("tilemap.png");
	int w = al_get_bitmap_width(tm);
	int h = al_get_bitmap_height(tm);
	int wt = w / 16;
	int ht = h / 16;
	ALLEGRO_BITMAP *b = al_create_bitmap(16, 16);
	al_set_target_bitmap(b);

	for (int y = 0; y < ht; y++) {
		for (int x = 0; x < wt; x++) {
			al_clear_to_color(al_map_rgba_f(0, 0, 0, 0));
			al_draw_bitmap_region(tm, x*16, y*16, 16, 16, 0, 0, 0);
			char name[200];
			sprintf(name, "out/%d-%d.png", x, y);
			al_save_bitmap(name, b);
		}
	}
}
Esempio n. 15
0
    void ScrollableArea::Change_coords(float x1, float y1, float width, float height)
    {
        wd_Change_coords(x1,y1,width, height);
        if(wd_bmp != nullptr)
        {
            al_destroy_bitmap(wd_bmp);
        }
        wd_bmp = al_create_bitmap(wd_width, wd_height);

        scb_vertical->Change_coords(wd_width - scb_thickness,0,scb_thickness,
                                       wd_height- scb_thickness);

        scb_horizontal->Change_coords(0,wd_height - scb_thickness, wd_width - scb_thickness,
                                       scb_thickness);

        scb_vertical->wd_md->Change_coords(wd_x2 - scb_thickness, wd_y1, scb_thickness,
                                       wd_height- scb_thickness);
        scb_horizontal->wd_md->Change_coords(wd_x1, wd_y2 - scb_thickness, wd_width - scb_thickness,
                                       scb_thickness);

        /*float __S = scb_thickness;
        scb_thickness = 1;*/
        zoomresetb->wd_md->Change_coords(wd_x2 - (scb_thickness/4)*3, wd_y2 - (scb_thickness/4)*3, scb_thickness/2, scb_thickness/2);
        //scb_thickness = __S;

        wd_md->Change_coords(wd_x1, wd_y1, wd_width - scb_thickness, wd_height - scb_thickness);

        I_added_new_widgets();
    }
ALLEGRO_BITMAP *create_pixel_pattern_1(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int checker_size)
{
   int bitmap_size = 64;
   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size, bitmap_size);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   int num_rows_cols = bitmap_size / checker_size;
   for (int row=0; row<num_rows_cols; row++)
      for (int col=0; col<num_rows_cols; col++)
      {
         if ((row+col) % 2 == 1) continue; // skip if the square is even

         // draw a square of n x n size, at (x, y)
         for (int yy=0; yy<checker_size; yy++)
            for (int xx=0; xx<checker_size; xx++)
            {
               al_put_pixel(col*checker_size + xx, row*checker_size + yy, pixel1_color);
            }
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
Esempio n. 17
0
Buffer* inicializa_buffer( ALLEGRO_DISPLAY *display, ALLEGRO_FONT* fonte, int largura, int altura, 
						   Escudo* escudo[], int n_escudos, Tanque *tanque, wave* invasores, nave* ovni, 
						   int* vidas, int* score, bool* game_on, SOUND_MANAGER* sound_mng){

	Buffer* buffer = (Buffer*) malloc (sizeof(Buffer));

	buffer->sound_mng = sound_mng;

	buffer->vidas = vidas;
	buffer->score = score;
	buffer->game_on = game_on;
	buffer->largura_inicial = largura;
	buffer->altura_inicial = altura;

	buffer->display = display;
	buffer->fonte = fonte;
	buffer->buffer = al_create_bitmap(largura, altura);

	buffer->escudo = escudo;
	buffer->n_escudos = n_escudos;
	buffer->tanque = tanque;
	buffer->invasores = invasores;
	buffer->ovni = ovni;

	return buffer;
}
Esempio n. 18
0
IntroSequence::IntroSequence(GameSequence *previous, float zoom,
                             float zoomspeed, int players, int level, int lives,
                             bool dca, bool wall)
    : GameSequence(previous) {
  width = GameManager::display_width;
  height = GameManager::display_height;

  iLogo = al_load_bitmap("assets/intro/intro_logo.bmp");
  iZoomMax = iZoom = (zoom);
  iZoomSpeed = (zoomspeed);
  iDoublebuffer = al_create_bitmap(width, maxi - mini);

  playerschoice = players;
  levelchoice = level;
  liveschoice = lives;
  dcachoice = dca;
  wallchoice = wall;
  assert(GameManager::num_joysticks_loaded >= 0 &&
         GameManager::num_joysticks_loaded <= 4);

  // setup player_controls based on number of joysticks, if there are joysticks use them first, otherwise use keyboard
  int playercontrol;
  for (playercontrol = 0; playercontrol < GameManager::num_joysticks_loaded; playercontrol++)
    playercontrols[playercontrol] = static_cast<CONTROL_ID>(4 + playercontrol);

  for (playercontrol = GameManager::num_joysticks_loaded; playercontrol < NB_MAX_PLAYERS; playercontrol++)
    playercontrols[playercontrol] = static_cast<CONTROL_ID>(playercontrol - GameManager::num_joysticks_loaded);
}
Esempio n. 19
0
void _al_win_set_display_icon(ALLEGRO_DISPLAY *display, ALLEGRO_BITMAP *bmp)
{
   ALLEGRO_BITMAP *scaled_bmp;
   HICON icon, old_small, old_big;
   ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)display;
   ALLEGRO_STATE backup;

   al_store_state(&backup, ALLEGRO_STATE_BITMAP | ALLEGRO_STATE_BLENDER);

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);
   scaled_bmp = al_create_bitmap(32, 32);
   al_set_target_bitmap(scaled_bmp);
   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO, al_map_rgb(255, 255, 255));
   al_draw_scaled_bitmap(bmp, 0, 0,
      al_get_bitmap_width(bmp),
      al_get_bitmap_height(bmp),
      0, 0, 32, 32, 0);

   al_restore_state(&backup);

   icon = _al_win_create_icon(win_display->window, scaled_bmp, 0, 0, false);

   old_small = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_SMALL, (LPARAM)icon);
   old_big = (HICON)SendMessage(win_display->window, WM_SETICON,
      ICON_BIG, (LPARAM)icon);

   if (old_small)
      DestroyIcon(old_small);
   if (old_big)
      DestroyIcon(old_big);

   al_destroy_bitmap(scaled_bmp);
}
Esempio n. 20
0
void c_minimap::reload(void)
{
	ALLEGRO_BITMAP * backup = al_get_target_bitmap();
	if(minimap_bitmap)
		al_destroy_bitmap(minimap_bitmap);
	minimap_bitmap = al_create_bitmap(user_config.minimap_size,user_config.minimap_size);
	if(!map_list.biome_map)
		return;
	int bigsize = al_get_bitmap_width(map_list.biome_map);
	if (bigsize < al_get_bitmap_height(map_list.biome_map))
		bigsize = al_get_bitmap_height(map_list.biome_map);
	scale = (double)user_config.minimap_size / (double)bigsize;
	al_set_target_bitmap(minimap_bitmap);
	al_draw_scaled_bitmap(map_list.biome_map,
		0,
		0,
		al_get_bitmap_width(map_list.biome_map),
		al_get_bitmap_height(map_list.biome_map),
		0,
		0,
		al_get_bitmap_width(map_list.biome_map)* scale,
		al_get_bitmap_height(map_list.biome_map) * scale,
		0);
	al_set_target_bitmap(backup);
}
ALLEGRO_BITMAP *create_pixel_pattern_4(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, float slope)
{
   //TODO this function is not complete, and may not return expected results when other values than the default values are given. 
   // Further development is needed to provide this flexibility to the function, but at the default values, it returns the intended
   // pattern

   int bitmap_size_x = x_distance * 8;
   int bitmap_size_y = x_distance * 8;

   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   if (x_distance < 0) { al_restore_state(&state); return surface; }
   while (slope < 0) { slope += x_distance; }

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   for (int y=0; y<bitmap_size_y; y+=1)
      for (int x=0; x<bitmap_size_x; x+=x_distance)
      {
         al_put_pixel(x + ((int)(y*slope))%x_distance, y, pixel1_color);
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
ALLEGRO_BITMAP *create_pixel_pattern_3(ALLEGRO_COLOR pixel1_color, ALLEGRO_COLOR pixel2_color, int x_distance, int y_distance)
{
   int bitmap_size_x = x_distance * 8;
   int bitmap_size_y = y_distance * 8;
   ALLEGRO_BITMAP *surface = al_create_bitmap(bitmap_size_x, bitmap_size_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(surface);

   // clear to the back color
   al_clear_to_color(pixel2_color);

   // begin drawing the surface
   int slope = (int)(x_distance * 1.5);
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY); // is ALLEGRO_PIXEL_FORMAT_ANY correct?
   for (int y=0; y<bitmap_size_y; y+=y_distance)
      for (int x=0; x<bitmap_size_x; x+=x_distance)
      {
         al_put_pixel(x + (y*slope)%x_distance, y, pixel1_color);
      }
   al_unlock_bitmap(surface);

   al_restore_state(&state);
   return surface;
}
ALLEGRO_BITMAP *generate_triangle_bitmap(float x1, float y1, float x2, float y2, float x3, float y3, ALLEGRO_COLOR col)
{
   // find the width and height of the bitmap (this could be more comprehensive? What about -negative points?)
   float max_x = std::max(std::max(x1, x2), x2);
   float max_y = std::max(std::max(y1, y2), y3);

   // start drawing
   ALLEGRO_BITMAP *surface = al_create_bitmap(max_x, max_y);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_clear_to_color(color::transparent);
   al_set_target_bitmap(surface);

   // build our triangle
   ALLEGRO_VERTEX v[3];
   v[0] = build_vertex(x1, y1, 0, col, 0, 0);
   v[1] = build_vertex(x2, y2, 0, col, 0, 0);
   v[2] = build_vertex(x3, y3, 0, col, 0, 0);

   // draw the triangle
   al_draw_prim(v, NULL, NULL, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

   // restore drawing state
   al_restore_state(&state);
   return surface;
}
Esempio n. 24
0
void RenderTarget::resize(int32_t w, int32_t h) {
	ALLEGRO_BITMAP *newBitmap = al_create_bitmap(w, h);

	// Check if we have changed Smooth2D in between creating this rendertarget
	// and calling this function. If so, we need to clone this bitmap, because
	// bitmap resize operation flags have changed.
	ALLEGRO_BITMAP *bitmapToDrawResized;
	int bmFlags = al_get_bitmap_flags(this->bitmap);
	int32_t origW = this->width();
	int32_t origH = this->height();
	bool smooth2d = CBEnchanted::instance()->isSmooth2D();
	if ((!smooth2d && (bmFlags & ALLEGRO_MAG_LINEAR) == ALLEGRO_MAG_LINEAR) ||
		(smooth2d && (bmFlags & ALLEGRO_MAG_LINEAR) != ALLEGRO_MAG_LINEAR))
	{
		// We need to clone.
		bitmapToDrawResized = al_clone_bitmap(this->bitmap);
		al_destroy_bitmap(this->bitmap);
	}
	else {
		// Phew, no need to clone.
		bitmapToDrawResized = this->bitmap;
	}
	al_set_target_bitmap(newBitmap);
	al_clear_to_color(al_map_rgb(0, 0, 0));
	int32_t a, b, c;
	al_get_blender(&a, &b, &c);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
	al_draw_scaled_bitmap(bitmapToDrawResized, 0, 0, origW, origH, 0, 0, w, h, 0);
	al_set_blender(a, b, c);
	al_destroy_bitmap(bitmapToDrawResized);
	this->bitmap = newBitmap;
	bindRenderTarget = this;
}
ALLEGRO_BITMAP *generate_gradient_bitmap(float size, ALLEGRO_COLOR top_color, ALLEGRO_COLOR bottom_color, int padding)
{
   // set everything up for rendering
   int w = size;
   int h = size;
   ALLEGRO_BITMAP *surface = al_create_bitmap(w, h);
   ALLEGRO_STATE previous_state;
   al_store_state(&previous_state, ALLEGRO_STATE_TARGET_BITMAP);

   // start drawing on the bitmap
   al_set_target_bitmap(surface);
   al_clear_to_color(color::transparent);

   // build the gradient as a primitive
   ALLEGRO_VERTEX v[4];
   v[0] = build_vertex(0+padding, 0+padding, 0, top_color, 0, 0);
   v[1] = build_vertex(w-padding, 0+padding, 0, top_color, 0, 0);
   v[2] = build_vertex(w-padding, h-padding, 0, bottom_color, 0, 0);
   v[3] = build_vertex(0+padding, h-padding, 0, bottom_color, 0, 0);

   // draw it to the surface
   al_draw_prim(v, NULL, NULL, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);

   // restore everything back to where it was
   al_restore_state(&previous_state);

   // return the generated image
   return surface; 
}
ALLEGRO_BITMAP *generate_noise_bitmap(float w, float h, float min_intensity, float max_intensity)
{
   // set everything up
   ALLEGRO_BITMAP *surface = al_create_bitmap(w, h);
   ALLEGRO_STATE state;
   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);

   // set the drawing surface
   al_set_target_bitmap(surface);

   // write the (randomly colored) pixels
   al_lock_bitmap(surface, ALLEGRO_PIXEL_FORMAT_ARGB_8888, ALLEGRO_LOCK_WRITEONLY);
   for (int x=0; x<w; x++)
   {
      for (int y=0; y<h; y++)
      {
         float val = random_float(min_intensity, max_intensity);
         al_put_pixel(x, y, al_map_rgba_f(val, val, val, 1.0));
      }
   }
   al_unlock_bitmap(surface);

   // return everything back to the way it was
   al_restore_state(&state);

   // return the generated image
   return surface;
}
Player::Player() {

    std::string tmplocation("/tmp/player.png");

    this->dimensions = rectangle( { 0.0f, 0.0f, 0.0f, 0.0f });
    this->forces = point( { 0.0f, 0.0f });

    if (downloadResourceFromInternet(tmplocation,
            "http://force.mjay.me/spritesheetmegaman1.png") == 200) {
        this->sprite = al_load_bitmap(tmplocation.c_str());

        // Next, we make small bitmap.
        this->pImage = al_create_bitmap(60, 64);
        this->dimensions.width = al_get_bitmap_width(this->pImage);
        this->dimensions.height = al_get_bitmap_height(this->pImage);

        al_set_target_bitmap(this->pImage);

        // Make sure, its actually transparent, by creating an alpha channel
        // in the background.
        al_clear_to_color(al_map_rgb(255, 255, 255));
        al_convert_mask_to_alpha(this->pImage, al_map_rgb(255, 255, 255));

        al_draw_bitmap_region(this->sprite, this->dimensions.x,
                this->dimensions.y, this->dimensions.width,
                this->dimensions.height, 0, 0, 0);

    }
}
Esempio n. 28
0
int main()
{
	al_init();
	al_init_image_addon();

	ALLEGRO_BITMAP *logo = al_load_bitmap("logo_no_alpha.png");
	ALLEGRO_BITMAP *shine = al_load_bitmap("shine.png");
	int w = al_get_bitmap_width(logo);
	int h = al_get_bitmap_height(logo);
	ALLEGRO_BITMAP *buf = al_create_bitmap(w, h);


	for (int i = 0; i < 20; i++) {
		char filename[100];
		sprintf(filename, "frame%02d.png", i);
		al_set_target_bitmap(buf);
		al_clear_to_color(al_map_rgb(0x22, 0x22, 0x22));
		float f = (rand() % 1000) / 1000.0 / 2.0;
		if (rand() % 2) {
			f = f + 0.5;
			al_draw_tinted_bitmap(shine, al_map_rgba_f(f, f, f, f), 0, 0, 0);
		}
		else {
			al_draw_bitmap(shine, 0, 0, 0);
			al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
			al_draw_tinted_bitmap(shine, al_map_rgba_f(f, f, f, f), 0, 0, 0);
			al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
		}
		al_draw_bitmap(logo, 0, 0, 0);
		al_save_bitmap(filename, buf);
	}
}
Esempio n. 29
0
void Menu::GenerateBackground()
{
	backgroundindex = rand() % 3;

	if( background == nullptr )
    {
        background = al_create_bitmap( 1024, 512 );
    }
	DISPLAY->SetTarget( background );

	int iw = al_get_bitmap_width( GameResources::BackgroundTiles.at(backgroundindex) );
	int ih = al_get_bitmap_height( GameResources::BackgroundTiles.at(backgroundindex) );
	int bx = 0;
	int by = 0;

	al_hold_bitmap_drawing( true );
	while( by < 512 )
	{
		while( bx < 1024 )
		{
			al_draw_bitmap( GameResources::BackgroundTiles.at(backgroundindex), bx, by, 0 );
			bx += iw;
		}
		by += ih;
		bx = 0;
	}
	al_hold_bitmap_drawing( false );

	DISPLAY->ClearTarget();
}
Esempio n. 30
0
static ALLEGRO_BITMAP *create_bitmap(void)
{
    const int checkers_size = 8;
    const int bitmap_size = 24;
    ALLEGRO_BITMAP *bitmap;
    ALLEGRO_LOCKED_REGION *locked;
    int x, y, p;
    unsigned char *rgba;

    bitmap = al_create_bitmap(bitmap_size, bitmap_size);
    locked = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ABGR_8888, 0);
    rgba = locked->data;
    p = locked->pitch;
    for (y = 0; y < bitmap_size; y++) {
        for (x = 0; x < bitmap_size; x++) {
            int c = (((x / checkers_size) + (y / checkers_size)) & 1) * 255;
            rgba[y * p + x * 4 + 0] = 0;
            rgba[y * p + x * 4 + 1] = 0;
            rgba[y * p + x * 4 + 2] = 0;
            rgba[y * p + x * 4 + 3] = c;
        }
    }
    al_unlock_bitmap(bitmap);
    return bitmap;
}