Beispiel #1
0
/* stretch_blit_to_hdc:
 *  Blits an Allegro BITMAP to a Windows DC. Has a syntax similar to
 *  stretch_blit().
 */
static void local_stretch_blit_to_hdc(ALLEGRO_BITMAP *bitmap, HDC dc,
   int src_x, int src_y, int src_w, int src_h,
   int dest_x, int dest_y, int dest_w, int dest_h)
{
   const int bitmap_h = al_get_bitmap_height(bitmap);
   const int bottom_up_src_y = bitmap_h - src_y - src_h;
   BYTE *pixels;
   BITMAPINFO *bi;

   bi = get_bitmap_info(bitmap);
   pixels = get_dib_from_bitmap_32(bitmap);

   /* Windows treats all source bitmaps as bottom-up when using StretchDIBits
    * unless the source (x,y) is (0,0).  To work around this buggy behavior, we
    * can use negative heights to reverse the direction of the blits.
    *
    * See <http://wiki.allegro.cc/StretchDIBits> for a detailed explanation.
    */
   if (bottom_up_src_y == 0 && src_x == 0 && src_h != bitmap_h) {
      StretchDIBits(dc, dest_x, dest_h+dest_y-1, dest_w, -dest_h,
	 src_x, bitmap_h - src_y + 1, src_w, -src_h, pixels, bi,
	 DIB_RGB_COLORS, SRCCOPY);
   }
   else {
      StretchDIBits(dc, dest_x, dest_y, dest_w, dest_h,
	 src_x, bottom_up_src_y, src_w, src_h, pixels, bi,
	 DIB_RGB_COLORS, SRCCOPY);
   }

   al_free(pixels);
   al_free(bi);
}
Beispiel #2
0
// ------------ begin of function RockRes::get_bitmap_recno -----------//
// return rockBitmapRecno
short RockRes::get_bitmap_recno(short rockId, char curFrame)
{
	RockInfo *rockInfo = get_rock_info(rockId);
	short rockBitmapRecno = rockInfo->first_bitmap_recno+curFrame-1;

#ifdef DEBUG
	// --------- validate curFrame with frame ----------//
	RockBitmapInfo *rockBitmapInfo = get_bitmap_info(rockBitmapRecno);
	err_when( rockBitmapInfo->frame != curFrame );
#endif

	return rockBitmapRecno;
}
Beispiel #3
0
// ------------ begin of function RockRes::choose_next -----------//
// choose the next frame
// <short> rockId        rock Id
// <char> curFrame       the current frame no.
// <long> path           a random number, related to the probability of choosing alt_next
//                       eg. choose_next(..,.., misc.random(x)); prob of using alt_next is 1/x
// return next frame no.
char RockRes::choose_next(short rockId, char curFrame, long path)
{
#ifdef DEBUG
	// -------- validate rockRecno ---------//
	RockInfo *rockInfo = get_rock_info(rockId);
	// -------- validate curFrame ----------//
	err_when(curFrame <= 0 || curFrame > rockInfo->max_frame);
#endif

	RockBitmapInfo *rockBitmapInfo = get_bitmap_info(get_bitmap_recno(rockId, curFrame));

	// -------- validate frame, next_frame and alt_next in rockBitmapInfo -------/
//	err_when(get_anim_info(get_anim_recno(rockRecno, rockBitmapInfo->next_frame))->frame != rockBitmapInfo->next_frame);
//	err_when(get_anim_info(get_anim_recno(rockRecno, rockBitmapInfo->alt_next))->frame != rockBitmapInfo->alt_next);

	return rockBitmapInfo->choose_next(path);
}
Beispiel #4
0
// ------------ begin of function RockRes::draw -----------//
// draw the whole rock at location (xLoc, yLoc)
// <short> rockId  			rock Id
// <short> xLoc,yLoc,curZ  where the rock is drawn
// <char> curFrame         frame no.
void RockRes::draw(short rockId, short xLoc, short yLoc, short curZ, char curFrame)
{
	RockInfo *rockInfo = get_rock_info(rockId);
	get_bitmap_info(get_bitmap_recno(rockId, curFrame))->draw(rockInfo, xLoc, yLoc, curZ );
}