示例#1
0
bool Projectile::collides(Gamestate *state, EntityPtr otherentity, double angle)
{
    MovingEntity *m = state->get<MovingEntity>(otherentity);
    Rect self = state->engine->maskloader.get_rect(getsprite(state, true)).offset(x, y);
    Rect other = state->engine->maskloader.get_rect(m->getsprite(state, true)).offset(m->x, m->y);

    double maxdist = std::max(std::hypot(self.w, self.h), std::hypot(other.w, other.h));
    if (std::hypot(self.x - other.x, self.y - other.y) <= maxdist)
    {
        // We're close enough that an actual collision might happen
        // Check the sprites
        ALLEGRO_BITMAP *selfsprite = state->engine->maskloader.requestsprite(getsprite(state, true));
        ALLEGRO_BITMAP *othersprite = state->engine->maskloader.requestsprite(m->getsprite(state, true));

        double cosa = std::cos(angle);
        double sina = std::sin(angle);

        double tmpx, tmpy;

        for (int i=0; i<self.w; ++i)
        {
            for (int j=0; j<self.h; ++j)
            {
                tmpx = self.x + cosa*i - sina*j;
                tmpy = self.y + sina*i + cosa*j;
                if (al_get_pixel(selfsprite, i, j).a != 0 and al_get_pixel(othersprite, tmpx - other.x, tmpy - other.y).a != 0)
                {
                    return true;
                }
            }
        }
    }
    return false;
}
示例#2
0
文件: rkr.cpp 项目: SocratesDz/kyks
// Colision de píxel perfecto
bool PixelCol(ALLEGRO_BITMAP *player, ALLEGRO_BITMAP *enemy, float x, float y, float w, float h, float ex, float ey, float ew, float eh)
{
	// El valor más alto entre la parte de arriba del jugador y del enemigo
	float top = fmax(y, ey);
	// El valor más bajo entre la parte de abajo del jugador y del enemigo
	float bottom = fmin(y + h, ey + eh);
	// El valor más alto entre la parte izquierda del jugador y del enemigo
	float left = fmax(x, ex);
	// El valor más bajo entre la parte derecha del jugador y del enemigo
	float right = fmin(x + w, ex + ew);
	
	// Hace un par de for's para revisar si hace colisión
	for(int i = top; i < bottom; i++)
	{
		for(int j = left; j < right; j++)
		{
			al_lock_bitmap(player, al_get_bitmap_format(player), ALLEGRO_LOCK_READONLY);
			al_lock_bitmap(enemy, al_get_bitmap_format(enemy), ALLEGRO_LOCK_READONLY);
			ALLEGRO_COLOR color = al_get_pixel(player, j - x, i - y);
			ALLEGRO_COLOR color2 = al_get_pixel(enemy, j - ex, i - ey);
			
			// Si el color alpha del jugador es diferente de 0 y el color alpha del enemigo es diferente de 0,
			// y están en la misma posición, entonces detecta una colisión
			if(color.a != 0 && color2.a != 0)
				return true;
		}
	}
	
	// Pero de lo contrario, devuelve false
	return false;
}
示例#3
0
ALLEGRO_BITMAP * t3f_resize_bitmap(ALLEGRO_BITMAP * bp, int w, int h)
{
	ALLEGRO_BITMAP * rbp = NULL;
	int start_w = al_get_bitmap_width(bp);
	int start_h = al_get_bitmap_height(bp);
	int x, y;
	float pixx, pixx_f, pixy, pixy_f;
	ALLEGRO_COLOR a, b, c, d, ab, cd, result;
	ALLEGRO_STATE old_state;

	/* don't resize if size is already correct */
	if(w == start_w && h == start_h)
	{
		return al_clone_bitmap(bp);
	}

	/* scale with software filtering */
	rbp = al_create_bitmap(w, h);
	if(!rbp)
	{
		printf("failed to create return bitmap\n");
		return NULL;
	}
	al_lock_bitmap(rbp, ALLEGRO_LOCK_READWRITE, ALLEGRO_PIXEL_FORMAT_ANY);
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
	al_set_target_bitmap(rbp);
	for(y = 0; y < h; y++)
	{
		pixy = ((float)y / h) * ((float)start_h - 1);
		pixy_f = floor(pixy);
		for(x = 0; x < w; x++)
		{
			pixx = ((float)x / w) * ((float)start_w - 1);
			pixx_f = floor(pixx);

			a = al_get_pixel(bp, pixx_f, pixy_f);
			b = al_get_pixel(bp, pixx_f + 1, pixy_f);
			c = al_get_pixel(bp, pixx_f, pixy_f + 1);
			d = al_get_pixel(bp, pixx_f + 1, pixy_f + 1);

			ab = interpolate(a, b, pixx - pixx_f);
			cd = interpolate(c, d, pixx - pixx_f);
			result = interpolate(ab, cd, pixy - pixy_f);

			al_put_pixel(x, y, result);
		}
	}
	al_unlock_bitmap(rbp);
	al_restore_state(&old_state);
	return rbp;
}
示例#4
0
//Creates a mask for pixel perfect collision
Mask *
mask_new(ALLEGRO_BITMAP *btm) {
	Mask *temp;
	int x, y;
	int width = al_get_bitmap_width(btm);
	int height = al_get_bitmap_height(btm);

	ALLEGRO_COLOR pixel;
	temp = mask_create(width, height);

	if (!temp)
		return NULL;

	mask_clear(temp);

	for(x = 0; x < width; x++) {
		for(y = 0; y < height; y++) {
			pixel = al_get_pixel(btm, x, y);
			if (pixel.a != 0) {
				temp->bits[x][y] = 1;
			}
		}
	}
	return temp;
}
示例#5
0
文件: video.c 项目: oitofelix/mininim
ALLEGRO_BITMAP *
apply_palette (ALLEGRO_BITMAP *bitmap, palette p)
{
  if (! bitmap) return NULL;

  ALLEGRO_BITMAP *cached = get_cached_palette (bitmap, p);
  if (cached) return cached;

  int x, y;
  ALLEGRO_BITMAP *rbitmap = clone_bitmap (bitmap);
  int w = al_get_bitmap_width (bitmap);
  int h = al_get_bitmap_height (bitmap);
  al_lock_bitmap (rbitmap, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
  set_target_bitmap (rbitmap);
  for (y = 0; y < h; y++)
    for (x = 0; x < w; x++)
      al_put_pixel (x, y, p (al_get_pixel (rbitmap, x, y)));
  al_unlock_bitmap (rbitmap);

  struct palette_cache pc;
  pc.ib = bitmap;
  pc.pal = p;
  pc.ob = rbitmap;

  palette_cache =
    add_to_array (&pc, 1, palette_cache, &palette_cache_nmemb,
                  palette_cache_nmemb, sizeof (pc));

  qsort (palette_cache, palette_cache_nmemb, sizeof (pc),
         compare_palette_caches);

  return rbitmap;
}
示例#6
0
/* Function: al_convert_mask_to_alpha
 */
void al_convert_mask_to_alpha(ALLEGRO_BITMAP *bitmap, ALLEGRO_COLOR mask_color)
{
   ALLEGRO_LOCKED_REGION *lr;
   int x, y;
   ALLEGRO_COLOR pixel;
   ALLEGRO_COLOR alpha_pixel;
   ALLEGRO_STATE state;

   if (!(lr = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY, 0))) {
      ALLEGRO_ERROR("Couldn't lock bitmap.");
      return;
   }

   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
   al_set_target_bitmap(bitmap);

   alpha_pixel = al_map_rgba(0, 0, 0, 0);

   for (y = 0; y < bitmap->h; y++) {
      for (x = 0; x < bitmap->w; x++) {
         pixel = al_get_pixel(bitmap, x, y);
         if (memcmp(&pixel, &mask_color, sizeof(ALLEGRO_COLOR)) == 0) {
            al_put_pixel(x, y, alpha_pixel);
         }
      }
   }

   al_unlock_bitmap(bitmap);

   al_restore_state(&state);
}
ALLEGRO_MOUSE_CURSOR *_al_xwin_create_mouse_cursor(ALLEGRO_BITMAP *bmp,
   int x_focus, int y_focus)
{
   ALLEGRO_SYSTEM_XGLX *system = (ALLEGRO_SYSTEM_XGLX *)al_get_system_driver();
   Display *xdisplay = system->x11display;

   int bmp_w;
   int bmp_h;
   ALLEGRO_MOUSE_CURSOR_XGLX *xcursor;
   XcursorImage *image;
   int c, ix, iy;
   bool was_locked;

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

   xcursor = al_malloc(sizeof *xcursor);
   if (!xcursor) {
      return NULL;
   }

   image = XcursorImageCreate(bmp->w, bmp->h);
   if (image == None) {
      al_free(xcursor);
      return NULL;
   }

   was_locked = al_is_bitmap_locked(bmp);
   if (!was_locked) {
      al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
   }

   c = 0;
   for (iy = 0; iy < bmp_h; iy++) {
      for (ix = 0; ix < bmp_w; ix++) {
         ALLEGRO_COLOR col;
         unsigned char r, g, b, a;

         col = al_get_pixel(bmp, ix, iy);
         al_unmap_rgba(col, &r, &g, &b, &a);
         image->pixels[c++] = (a<<24) | (r<<16) | (g<<8) | (b);
      }
   }

   if (!was_locked) {
      al_unlock_bitmap(bmp);
   }

   image->xhot = x_focus;
   image->yhot = y_focus;

   _al_mutex_lock(&system->lock);
   xcursor->cursor = XcursorImageLoadCursor(xdisplay, image);
   _al_mutex_unlock(&system->lock);

   XcursorImageDestroy(image);

   return (ALLEGRO_MOUSE_CURSOR *)xcursor;
}
示例#8
0
文件: bitmap.c 项目: trezker/allua
static int allua_Bitmap_get_pixel(lua_State * L)
{
   ALLUA_bitmap bitmap = allua_check_bitmap(L, 1);
   float x = luaL_checknumber(L, 2);
   float y = luaL_checknumber(L, 3);
   allua_pushColor(L, al_get_pixel(bitmap, x, y));
   return 1;
}
示例#9
0
文件: pos.c 项目: oitofelix/mininim
bool
is_pixel_transparent (ALLEGRO_BITMAP *bitmap, int x, int y)
{
  ALLEGRO_COLOR c = al_get_pixel (bitmap, x, y);
  unsigned char r, g, b, a;
  al_unmap_rgba (c, &r, &g, &b, &a);
  return a < 255;
}
示例#10
0
void animation::add_frame(ALLEGRO_BITMAP *frame) {
    if (frame == NULL) return;
    
    //take a pixel from background color and use it as transparency pixel
    al_convert_mask_to_alpha(frame, al_get_pixel(frame, 0, 0));

    //add frame to collection
    frames.push_back(frame);
}
示例#11
0
static void do_test2(ALLEGRO_COLOR src_col, ALLEGRO_COLOR dst_col,
   ALLEGRO_COLOR blend_col, int src_format, int dst_format,
   int src_mode, int dst_mode, int src_alpha, int dst_alpha,
   int operation)
{
   ALLEGRO_COLOR reference, result, from_display;
   test_index++;

   if (test_only_index && test_index != test_only_index)
      return;

   reference = reference_implementation(
      src_col, dst_col, blend_col, src_format, dst_format,
      src_mode, dst_mode, src_alpha, dst_alpha, operation);

   result = test(src_col, dst_col, blend_col, src_format,
      dst_format, src_mode, dst_mode, src_alpha, dst_alpha,
      operation, false);

   if (!same_color(reference, result)) {
      test(src_col, dst_col, blend_col, src_format,
      dst_format, src_mode, dst_mode, src_alpha, dst_alpha,
      operation, true);
      printf("expected   : ");
      print_color(reference);
      printf("\n");
      printf("FAILED\n");
   }
   else {
      printf(" OK");
      fflush(stdout);
   }

   if (test_display) {
      dst_format = al_get_display_format();
      from_display = al_get_pixel(al_get_backbuffer(), 0, 0);
      reference = reference_implementation(
         src_col, dst_col, blend_col, src_format, dst_format,
         src_mode, dst_mode, src_alpha, dst_alpha, operation);
      
      if (!same_color(reference, from_display)) {
         test(src_col, dst_col, blend_col, src_format,
         dst_format, src_mode, dst_mode, src_alpha, dst_alpha,
         operation, true);
         printf("displayed  : ");
         print_color(from_display);
         printf("\n");
         printf("expected   : ");
         print_color(reference);
         printf("\n");
         printf("(FAILED on display)\n");
      }
   }
}
示例#12
0
void animation::add_frame(frame* f) {
    if (f == NULL) return;
	if (f->bb == NULL) return;
	if (f->image == NULL) return;
    
    //take a pixel from background color and use it as transparency pixel
    al_convert_mask_to_alpha(f->image, al_get_pixel(f->image, 0, 0));

    //add frame to collection
    frames.push_back(f);
}
示例#13
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;
};
示例#14
0
static mrb_value
bitmap_get_pixel(mrb_state *mrb, mrb_value self)
{
  ALLEGRO_BITMAP *b;
  mrb_int x;
  mrb_int y;
  ALLEGRO_COLOR *c;
  Check_Destroyed(mrb, self, bitmap, b);
  mrb_get_args(mrb, "ii", &x, &y);
  c = mrb_malloc(mrb, sizeof(*c));
  *c = al_get_pixel(b, mrbal_clamp_int(x), mrbal_clamp_int(y));
  return mrb_obj_value(Data_Wrap_Struct(mrb, C_ALLEGRO_COLOR, &mrbal_color_data_type, c));
}
示例#15
0
int gdp_colision(Object *tobj,Action *act){
    if(tobj->y < 0)
		return(true);

	if((tobj->y+ (tobj->hd)) > height)
		return(true);

	ALLEGRO_COLOR color,colorwall;
	colorwall = al_map_rgb(0, 0, 0);

	double sx = (double) ambient->w / ambient->wd;
	double sy = (double) ambient->h / ambient->hd;

	int we    = (int) ambient->wd * sx;
	int he    = (int) ambient->hd * sy;

	int xup   = (int) ((tobj->x + tobj->wd-act->rebatex) ) * sx;
    int yup   = (int) ((tobj->y+act->rebatey)) * sy;

	int xdown = (int) (tobj->x+act->rebatex) * sx;
    int ydown = (int) (((tobj->y) + tobj->hd-act->rebatey)) * sy;

	if((xdown >= 0 && ydown >= 0 && xup <= we && yup <= he)){
		if(tobj->d != GDPRIGHT){
			color = al_get_pixel(ambient->model, xdown, ydown);
			if(colorwall.r == color.r && colorwall.g == color.g && colorwall.b == color.b)
				return(true);
		}
		if(tobj->d != GDPLEFT){
			color = al_get_pixel(ambient->model, xup, ydown);
			if(colorwall.r == color.r && colorwall.g == color.g && colorwall.b == color.b)
				return(true);
		}
	}
	else
		return(true);

	return(false);
}
示例#16
0
void _al_point_2d(ALLEGRO_BITMAP* texture, ALLEGRO_VERTEX* v)
{
   int shade = 1;
   int op, src_mode, dst_mode, op_alpha, src_alpha, dst_alpha;
   ALLEGRO_COLOR vc;
   int clip_min_x, clip_min_y, clip_max_x, clip_max_y;
   int x = (int)floorf(v->x);
   int y = (int)floorf(v->x);
   
   al_get_clipping_rectangle(&clip_min_x, &clip_min_y, &clip_max_x, &clip_max_y);
   clip_max_x += clip_min_x;
   clip_max_y += clip_min_y;
   
   if(x < clip_min_x || x >= clip_max_x || y < clip_min_y || y >= clip_max_y)
      return;

   vc = v->color;

   al_get_separate_blender(&op, &src_mode, &dst_mode, &op_alpha, &src_alpha, &dst_alpha);
   if (_AL_DEST_IS_ZERO && _AL_SRC_NOT_MODIFIED) {
      shade = 0;
   }
   
   if (texture) {
      float U = fix_var(v->u, al_get_bitmap_width(texture));
      float V = fix_var(v->v, al_get_bitmap_height(texture));
      ALLEGRO_COLOR color = al_get_pixel(texture, U, V);

      if(vc.r != 1 || vc.g != 1 || vc.b != 1 || vc.a != 1) {
         color.r *= vc.r;
         color.g *= vc.g;
         color.b *= vc.b;
         color.a *= vc.a;
      }

      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   } else {
      ALLEGRO_COLOR color = al_map_rgba_f(vc.r, vc.g, vc.b, vc.a);
      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   }
}
示例#17
0
/* Helper to set a window icon.  We use the _NET_WM_ICON property which is
 * supported by modern window managers.
 *
 * The old method is XSetWMHints but the (antiquated) ICCCM talks about 1-bit
 * pixmaps.  For colour icons, perhaps you're supposed use the icon_window,
 * and draw the window yourself?
 */
static bool xdpy_set_icon_inner(Display *x11display, Window window,
   ALLEGRO_BITMAP *bitmap, int prop_mode)
{
   int w, h;
   int data_size;
   unsigned long *data; /* Yes, unsigned long, even on 64-bit platforms! */
   ALLEGRO_LOCKED_REGION *lr;
   bool ret;

   w = al_get_bitmap_width(bitmap);
   h = al_get_bitmap_height(bitmap);
   data_size = 2 + w * h;
   data = al_malloc(data_size * sizeof(data[0]));
   if (!data)
      return false;

   lr = al_lock_bitmap(bitmap, ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA,
      ALLEGRO_LOCK_READONLY);
   if (lr) {
      int x, y;
      ALLEGRO_COLOR c;
      unsigned char r, g, b, a;
      Atom _NET_WM_ICON;

      data[0] = w;
      data[1] = h;
      for (y = 0; y < h; y++) {
         for (x = 0; x < w; x++) {
            c = al_get_pixel(bitmap, x, y);
            al_unmap_rgba(c, &r, &g, &b, &a);
            data[2 + y*w + x] = (a << 24) | (r << 16) | (g << 8) | b;
         }
      }

      _NET_WM_ICON = XInternAtom(x11display, "_NET_WM_ICON", False);
      XChangeProperty(x11display, window, _NET_WM_ICON, XA_CARDINAL, 32,
         prop_mode, (unsigned char *)data, data_size);

      al_unlock_bitmap(bitmap);
      ret = true;
   }
   else {
      ret = false;
   }

   al_free(data);

   return ret;
}
示例#18
0
void shal_get_pixel(ALLEGRO_BITMAP * bitmap,
                    int x,
                    int y,
                    float * out_r,
                    float * out_g,
                    float * out_b,
                    float * out_a)
{
    ALLEGRO_COLOR out;
    out = al_get_pixel(bitmap, x, y);
    *out_r = out.r;
    *out_g = out.g;
    *out_b = out.b;
    *out_a = out.a;
}
示例#19
0
SpriteSeq SpriteUtil::process(const char * filename, ALLEGRO_COLOR delimiterColor) {

	#ifndef _AL_INIT_IMAGE_ADDON
	#define _AL_INIT_IMAGE_ADDON
	al_init_image_addon();
	#endif

	ALLEGRO_BITMAP *bitmap = al_load_bitmap(filename);

	SpriteSeq spriteSeq(bitmap, 0, 0);

	ALLEGRO_COLOR pixel, lastPixel;
	int lastSource = 0;

	for(int i = 0; i <al_get_bitmap_width(bitmap); i++) {

		pixel = al_get_pixel(bitmap, i, 0);

		if (memcmp(&pixel, &lastPixel, sizeof(ALLEGRO_COLOR))) {

			if (!memcmp(&pixel, &delimiterColor, sizeof(ALLEGRO_COLOR))) {

				i++; // current pixel is the red one, so, advance to next pixel
				
				if (spriteSeq.empty()) {

					spriteSeq.add(Sprite(bitmap, 0, 0, i, al_get_bitmap_height(bitmap)));

				} else {

					spriteSeq.add(Sprite(bitmap, lastSource, 0, i - lastSource, al_get_bitmap_height(bitmap)));
				}

				lastSource = i;
			}

		} else if(i == al_get_bitmap_width(bitmap) - 1) {

			spriteSeq.add(Sprite(bitmap, lastSource, 0, i - lastSource, al_get_bitmap_height(bitmap)));
		}

		lastPixel = pixel;
	}

	al_convert_mask_to_alpha(bitmap, al_map_rgba(255, 0, 0, 255));
	
	return spriteSeq;
}
示例#20
0
static void shader_texture_solid_any_draw_opaque_white(uintptr_t state, int x1, int y, int x2)
{
   state_texture_solid_any_2d* s = (state_texture_solid_any_2d*)state;
   float u = s->u;
   float v = s->v;
   int x;
   ALLEGRO_COLOR color;
   
   for (x = x1; x <= x2; x++) {
      color = al_get_pixel(s->texture, fix_var(u, s->w), fix_var(v, s->h));
      al_put_pixel(x, y - 1, color);
      
      u += s->du_dx;
      v += s->dv_dx;
   }
}
示例#21
0
static void dot_game_create_score_effect(void * data, float x, float y, int number)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	char buf[16] = {0};
	int i, j;
	ALLEGRO_COLOR c;
	unsigned char r, g, b, a;
	float ox;
	float w, h;

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
	sprintf(buf, "%d", number);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_draw_text(app->font[DOT_FONT_16], t3f_color_white, 0, 0, 0, buf);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
	al_restore_state(&old_state);
	al_lock_bitmap(app->bitmap[DOT_BITMAP_SCRATCH], ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
	ox = al_get_text_width(app->font[DOT_FONT_16], buf) / 2;
	w = al_get_text_width(app->font[DOT_FONT_16], buf);
	h = al_get_font_line_height(app->font[DOT_FONT_16]);
	for(i = 0; i < w; i++)
	{
		for(j = 0; j < h; j++)
		{
			c = al_get_pixel(app->bitmap[DOT_BITMAP_SCRATCH], i, j);
			al_unmap_rgba(c, &r, &g, &b, &a);
			if(a > 0)
			{
				dot_create_particle(&app->particle[app->current_particle], x + (float)i - ox, y + j, 0.0, dot_spread_effect_particle(i, w, strlen(buf) * 2.5), dot_spread_effect_particle(j, h, 4.0), -10.0, 0.0, 3.0, 45, app->bitmap[DOT_BITMAP_PARTICLE], c);
				app->current_particle++;
				if(app->current_particle >= DOT_MAX_PARTICLES)
				{
					app->current_particle = 0;
				}
			}
		}
	}
	al_unlock_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
}
示例#22
0
void pp2_intro_setup(void)
{
	int i, j, r;
	ALLEGRO_COLOR color;
	unsigned char cr, cg, cb, ca;

	/* find all pixels */
	for(i = 0; i < 40; i++)
	{
		for(j = 0; j < 40; j++)
		{
			color = al_get_pixel(pp2_bitmap[PP2_BITMAP_T3_LOGO_MEMORY], j * 10 + 5, i * 10 + 5);
			al_unmap_rgba(color, &cr, &cg, &cb, &ca);
			if(ca == 255)
			{
				pp2_intro_pixel[pp2_intro_pixels].x = j * 10 + 120;
				pp2_intro_pixel[pp2_intro_pixels].y = i * 10 + 40;
				pp2_intro_pixel[pp2_intro_pixels].color = color;
				pp2_intro_pixel_list[pp2_intro_pixel_list_size] = pp2_intro_pixels;
				pp2_intro_pixel_list_size++;
				pp2_intro_pixels++;
			}
		}
	}

	/* place pixels */
	for(i = 0; i < pp2_intro_pixels; i++)
	{
		r = rand() % pp2_intro_pixel_list_size;
		pp2_intro_pixel[pp2_intro_pixel_list[r]].vz = 5.0 + (i * 0.05);
		pp2_intro_pixel[pp2_intro_pixel_list[r]].z = 0.0;
		for(j = 0; j < 120 + i / 10; j++)
		{
			pp2_intro_pixel[pp2_intro_pixel_list[r]].z -= pp2_intro_pixel[pp2_intro_pixel_list[r]].vz;
		}

		for(j = r; j < pp2_intro_pixel_list_size - 1; j++)
		{
			pp2_intro_pixel_list[j] = pp2_intro_pixel_list[j + 1];
		}
		pp2_intro_pixel_list_size--;
	}
	qsort(pp2_intro_pixel, pp2_intro_pixels, sizeof(PP2_INTRO_PIXEL), pixel_sorter);
}
示例#23
0
// unused
void convert_grayscale(ALLEGRO_BITMAP *bmp) {
	ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap();
	int x, y, w, h, lum;
	unsigned char r, g, b;
	w = al_get_bitmap_width(bmp);
	h = al_get_bitmap_height(bmp);

	al_set_target_bitmap(bmp);
	al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888, ALLEGRO_LOCK_READWRITE);

	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			al_unmap_rgb(al_get_pixel(bmp, x, y), &r, &g, &b);
			lum = (0.299*r + 0.587*g + 0.114*b)/2; // dividing by two makes it darker, default should be not dividing
			al_put_pixel(x, y, al_map_rgb(lum, lum, lum)); // RGB to grayscale
		}
	}
	al_unlock_bitmap(bmp);
	al_set_target_bitmap(dispbuf);
}
示例#24
0
int furthest_left(ALLEGRO_BITMAP *bmp)
{
	int f = SUBW-1;
	for (int y = 0; y < SUBH; y++) {
		int thisf = SUBW-1;
		for (int x = 0; x < SUBW; x++) {
			ALLEGRO_COLOR pixel = al_get_pixel(bmp, x, y);
			unsigned char r, g, b;
			al_unmap_rgb(pixel, &r, &g, &b);
			if (r == 255 && g == 0 && b == 255)
				continue;
			thisf = x;
			break;
		}
		if (thisf < f)
			f = thisf;
	}

	return f;
}
示例#25
0
/* get_dib_from_bitmap_32:
 *  Creates a Windows device-independent bitmap (DIB) from an Allegro BITMAP.
 *  You have to free the memory allocated by this function.
 *
 *  This version always creates a 32-bit DIB.
 */
static BYTE *get_dib_from_bitmap_32(ALLEGRO_BITMAP *bitmap)
{
   int w, h;
   int x, y;
   int pitch;
   BYTE *pixels;
   BYTE *dst;

   w = al_get_bitmap_width(bitmap);
   h = al_get_bitmap_height(bitmap);
   pitch = w * 4;

   pixels = (BYTE *) al_malloc(h * pitch);
   if (!pixels)
      return NULL;

   for (y = 0; y < h; y++) {
      dst = pixels + y * pitch;

      for (x = 0; x < w; x++) {
         ALLEGRO_COLOR col;
         unsigned char r, g, b, a;

         col = al_get_pixel(bitmap, x, y);
         al_unmap_rgba(col, &r, &g, &b, &a);

         /* BGR */
         dst[0] = b;
         dst[1] = g;
         dst[2] = r;
         dst[3] = a;

         dst += 4;
      }
   }

   return pixels;
}
示例#26
0
static void shader_texture_grad_any_draw_opaque(uintptr_t state, int x1, int y, int x2)
{
   state_texture_grad_any_2d* s = (state_texture_grad_any_2d*)state;
   float u = s->solid.u;
   float v = s->solid.v;
   int x;
   ALLEGRO_COLOR color;
   ALLEGRO_COLOR cur_color = s->solid.cur_color;
   
   for (x = x1; x <= x2; x++) {
      color = al_get_pixel(s->solid.texture, fix_var(u, s->solid.w), fix_var(v, s->solid.h));
      SHADE_COLORS(color, cur_color)
      al_put_pixel(x, y - 1, color);
      
      u += s->solid.du_dx;
      v += s->solid.dv_dx;

      cur_color.r += s->color_dx.r;
      cur_color.g += s->color_dx.g;
      cur_color.b += s->color_dx.b;
      cur_color.a += s->color_dx.a; 
   }
}
示例#27
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;
}
示例#28
0
文件: skin_fx.c 项目: mnstrmnch/meka
static void	SkinFx_UpdateBlood(void)
{
	int i;
	
	// This is the colors originally used when MEKA was working in palette mode
	// Nowadays, I guess the logic should be changed to take a single base color and create altered variations of it
	ALLEGRO_COLOR blood_colors[4];
	blood_colors[0] = COLOR_SKIN_WINDOW_BACKGROUND;
	blood_colors[1] = COLOR_SKIN_WINDOW_BORDER;
	blood_colors[2] = COLOR_SKIN_MENU_SELECTION;
	blood_colors[3] = COLOR_SKIN_MENU_BACKGROUND;

	// Create new drops around cursor
	for (i = 0; i < 4; i ++)
		gui_applet_blood_create(RandomInt(4), gui.mouse.x - 2 + RandomInt(5), gui.mouse.y - 2 + RandomInt(5));
	for (i = 0; i < 2; i ++)
		gui_applet_blood_create(RandomInt(4), gui.mouse.x - 4 + RandomInt(9), gui.mouse.y - 4 + RandomInt(9));
	gui_applet_blood_create(RandomInt(4), gui.mouse.x - 5 + RandomInt(11), gui.mouse.y - 5 + RandomInt(11));

	// Create new drops below currently focused window
	t_gui_box* b = gui.boxes_z_ordered[0];
	if (b && (b->flags & GUI_BOX_FLAGS_ACTIVE))
    {
		for (i = 0; i < 4; i ++)
		{
			gui_applet_blood_create(RandomInt(4), 
				b->frame.pos.x - 2 + RandomInt(b->frame.size.x + 4), b->frame.pos.y + b->frame.size.y + 2);
		}
    }

	// Update drops
	for (i = 0; i < MAX_BLOOD_DROP; i ++)
	{
		t_skinfx_particle* p = &g_skinfx_particles[i];
		p->x += p->vx;
		p->y += p->vy;
		if (p->x < 0 || p->x >= gui.info.screen.x || p->y < 0 || p->y >= gui.info.screen.y)
			p->v = 0;
	}

	al_lock_bitmap(gui_buffer, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READWRITE);
	al_set_target_bitmap(gui_buffer);

	// Save old colors
	for (i = 0; i < MAX_BLOOD_DROP; i ++)
	{
		t_skinfx_particle* p = &g_skinfx_particles[i];
		if (p->v)
			p->save = al_get_pixel(gui_buffer, p->x, p->y);
	}

	// Draw blood drops
	for (i = 0; i < MAX_BLOOD_DROP; i ++)
	{
		t_skinfx_particle* p = &g_skinfx_particles[i];
		if (p->v)
			al_put_pixel(p->x, p->y, blood_colors[p->v]);
	}

	al_unlock_bitmap(gui_buffer);
}
示例#29
0
int main(int argc, char **argv)
{
	if (argc < 3) {
		printf("Usage: infile.png outfile.png\n");
		return 0;
	}

	al_init();
	al_init_image_addon();

	al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
	al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ARGB_8888);

	ALLEGRO_BITMAP *inbmp = al_load_bitmap(argv[1]);

	al_set_target_bitmap(inbmp);

	int x, y;
	for (y = 0; y < al_get_bitmap_height(inbmp);) {
		for (x = 0; x < al_get_bitmap_width(inbmp); x++) {
			ALLEGRO_COLOR pixel = al_get_pixel(inbmp, x, y);
			if (pixel.a == 0) {
				int h = 1;
				do {
					ALLEGRO_COLOR p = al_get_pixel(inbmp, x, y+h);
					if (p.a == 0 || (p.r == 1 && p.g == 1 && p.b == 1))
						h++;
					else
						break;
				} while (1);
				printf("h=%d\n", h);
				
				for (int r = 0; r < h; r++) {
					ALLEGRO_COLOR c;
					if (r < h/2) {
						float p = (float)r / (h/2);
						int diff = MIDDLE-TOP;
						int v = diff*p + TOP;
						c = al_map_rgb(v, v, v);
						printf("v=%d\n", v);
					}
					else {
						float p = 1 - ((float)(r-h/2) / (h/2));
						int diff = MIDDLE-TOP;
						int v = diff*p + TOP;
						c = al_map_rgb(v, v, v);
						printf("v=%d\n", v);
					}
					for (int xx = 0; xx < al_get_bitmap_width(inbmp); xx++) {
						ALLEGRO_COLOR p = al_get_pixel(inbmp, xx, y+r);
						if (p.r == 1 && p.g == 1 && p.b == 1 && p.a == 1) {
							al_put_pixel(xx, y+r, c);
						}
					}
				}
				y += h+1;
				goto loop;
			}
		}
		y++;
loop:;
	}

	al_save_bitmap(argv[2], inbmp);
}
示例#30
0
/* Generates a bitmap with transparent background and the logo text.
 * The bitmap will have screen size. If 'bumpmap' is not NULL, it will
 * contain another bitmap which is a white, blurred mask of the logo
 * which we use for the flash effect.
 */
static ALLEGRO_BITMAP *generate_logo(char const *text,
                                     char const *fontname,
                                     int font_size,
                                     float shadow_offset,
                                     float blur_radius,
                                     float blur_factor,
                                     float light_red,
                                     float light_green,
                                     float light_blue,
                                     ALLEGRO_BITMAP **bumpmap)
{
   ALLEGRO_COLOR transparent = al_map_rgba_f(0, 0, 0, 0);
   int xp, yp, w, h, i, j, x, y, br, bw, dw, dh;
   ALLEGRO_COLOR c;
   ALLEGRO_FONT *logofont;
   ALLEGRO_STATE state;
   ALLEGRO_BITMAP *blur, *light, *logo;
   int left, right, top, bottom;
   float cx, cy;

   dw = al_get_bitmap_width(al_get_target_bitmap());
   dh = al_get_bitmap_height(al_get_target_bitmap());

   cx = dw * 0.5;
   cy = dh * 0.5;

   logofont = al_load_font(fontname, -font_size, 0);
   al_get_text_dimensions(logofont, text, &xp, &yp, &w, &h);

   al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_BLENDER);

   /* Cheap blur effect to create a bump map. */
   blur = al_create_bitmap(dw, dh);
   al_set_target_bitmap(blur);
   al_clear_to_color(transparent);
   br = blur_radius;
   bw = br * 2 + 1;
   c = al_map_rgba_f(1, 1, 1, 1.0 / (bw * bw * blur_factor));
   al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA,
                           ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
   for (i = -br; i <= br; i++) {
      for (j = -br; j <= br; j++) {
         al_draw_text(logofont, c,
                         cx - xp * 0.5 - w * 0.5 + i,
                         cy - yp * 0.5 - h * 0.5 + j, 0, text);
      }
   }

   left = cx - xp * 0.5 - w * 0.5 - br + xp;
   top = cy - yp * 0.5 - h * 0.5 - br + yp;
   right = left + w + br * 2;
   bottom = top + h + br * 2;

   if (left < 0)
      left = 0;
   if (top < 0)
      top = 0;
   if (right > dw - 1)
      right = dw - 1;
   if (bottom > dh - 1)
      bottom = dh - 1;

   /* Cheap light effect. */
   light = al_create_bitmap(dw, dh);
   al_set_target_bitmap(light);
   al_clear_to_color(transparent);
   al_lock_bitmap(blur, ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
   al_lock_bitmap_region(light, left, top,
      1 + right - left, 1 + bottom - top,
      ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_WRITEONLY);
   for (y = top; y <= bottom; y++) {
      for (x = left; x <= right; x++) {
         float r1, g1, b1, a1;
         float r2, g2, b2, a2;
         float r, g, b, a;
         float d;
         ALLEGRO_COLOR c = al_get_pixel(blur, x, y);
         ALLEGRO_COLOR c1 = al_get_pixel(blur, x - 1, y - 1);
         ALLEGRO_COLOR c2 = al_get_pixel(blur, x + 1, y + 1);
         al_unmap_rgba_f(c, &r, &g, &b, &a);
         al_unmap_rgba_f(c1, &r1, &g1, &b1, &a1);
         al_unmap_rgba_f(c2, &r2, &g2, &b2, &a2);

         d = r2 - r1 + 0.5;
         r = clamp(d * light_red);
         g = clamp(d * light_green);
         b = clamp(d * light_blue);

         c = al_map_rgba_f(r, g, b, a);
         al_put_pixel(x, y, c);
      }
   }
   al_unlock_bitmap(light);
   al_unlock_bitmap(blur);

   if (bumpmap)
      *bumpmap = blur;
   else
      al_destroy_bitmap(blur);

   /* Create final logo */
   logo = al_create_bitmap(dw, dh);
   al_set_target_bitmap(logo);
   al_clear_to_color(transparent);

   /* Draw a shadow. */
   c = al_map_rgba_f(0, 0, 0, 0.5 / 9);
   al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA,
                           ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
   for (i = -1; i <= 1; i++)
      for (j = -1; j <= 1; j++)
         al_draw_text(logofont, c,
                         cx - xp * 0.5 - w * 0.5 + shadow_offset + i,
                         cy - yp * 0.5 - h * 0.5 + shadow_offset + j,
                         0, text);

   /* Then draw the lit text we made before on top. */
   al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA,
                           ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
   al_draw_bitmap(light, 0, 0, 0);
   al_destroy_bitmap(light);

   al_restore_state(&state);
   al_destroy_font(logofont);

   return logo;
}