rnd-20100315-1-src
[rocksndiamonds.git] / src / game_sp / DDSpriteBuffer.c
1 // ----------------------------------------------------------------------------
2 // DDSpriteBuffer.c
3 // ----------------------------------------------------------------------------
4
5 #include "DDSpriteBuffer.h"
6
7
8 long mXSpriteCount, mYSpriteCount;
9 long mSpriteWidth, mSpriteHeight;
10 long mDestXOff, mDestYOff;
11
12 void DDSpriteBuffer_Init()
13 {
14   mSpriteWidth  = TILEX;
15   mSpriteHeight = TILEY;
16   mXSpriteCount = 16;
17   mYSpriteCount = 16;
18 }
19
20 static void Blt(int pX, int pY, Bitmap *bitmap, int SpriteX, int SpriteY)
21 {
22   MyRECT DR, SR;
23
24   int scx = (mScrollX_last < 0 ? 0 : mScrollX_last);
25   int scy = (mScrollY_last < 0 ? 0 : mScrollY_last);
26   int sx1 = scx - 2 * TILEX;
27   int sy1 = scy - 2 * TILEY;
28   int sx2 = scx + SXSIZE + 1 * TILEX;
29   int sy2 = scy + SYSIZE + 1 * TILEY;
30
31   int sx = pX - sx1;
32   int sy = pY - sy1;
33
34   if (NoDisplayFlag)
35     return;
36
37   /* do not draw fields that are outside the visible screen area */
38   if (pX < sx1 || pX > sx2 || pY < sy1 || pY > sy2)
39     return;
40
41   DR.left = pX + mDestXOff;
42   DR.top = pY + mDestYOff;
43   DR.right = pX + mSpriteWidth + mDestXOff;
44   DR.bottom = pY + mSpriteHeight + mDestYOff;
45
46   SR.left = SpriteX;
47   SR.top = SpriteY;
48   SR.right = SR.left + mSpriteWidth;
49   SR.bottom = SR.top + mSpriteHeight;
50
51   BlitBitmap(bitmap, screenBitmap,
52              SR.left, SR.top,
53              mSpriteWidth, mSpriteHeight,
54              sx, sy);
55 }
56
57 void DDSpriteBuffer_BltImg(int pX, int pY, int graphic, int sync_frame)
58 {
59   struct GraphicInfo_SP g;
60
61   if (NoDisplayFlag)
62     return;
63
64   getGraphicSource_SP(&g, graphic, sync_frame, -1, -1);
65
66   Blt(pX, pY, g.bitmap, g.src_x, g.src_y);
67 }