1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
11 unsigned int frame; /* current screen frame */
12 unsigned int screen_x; /* current scroll position */
13 unsigned int screen_y;
15 /* tiles currently on screen */
16 static unsigned short screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
19 /* copy the entire screen to the window at the scroll position
21 * perhaps use mit-shm to speed this up
26 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
27 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
29 if (x < 2 * TILEX && y < 2 * TILEY)
31 BlitBitmap(screenBitmap, window, x, y,
32 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
34 else if (x < 2 * TILEX && y >= 2 * TILEY)
36 BlitBitmap(screenBitmap, window, x, y,
37 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
39 BlitBitmap(screenBitmap, window, x, 0,
40 SCR_FIELDX * TILEX, y - 2 * TILEY,
41 SX, SY + MAX_BUF_YSIZE * TILEY - y);
43 else if (x >= 2 * TILEX && y < 2 * TILEY)
45 BlitBitmap(screenBitmap, window, x, y,
46 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
48 BlitBitmap(screenBitmap, window, 0, y,
49 x - 2 * TILEX, SCR_FIELDY * TILEY,
50 SX + MAX_BUF_XSIZE * TILEX - x, SY);
54 BlitBitmap(screenBitmap, window, x, y,
55 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
57 BlitBitmap(screenBitmap, window, 0, y,
58 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
59 SX + MAX_BUF_XSIZE * TILEX - x, SY);
60 BlitBitmap(screenBitmap, window, x, 0,
61 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
62 SX, SY + MAX_BUF_YSIZE * TILEY - y);
63 BlitBitmap(screenBitmap, window, 0, 0,
64 x - 2 * TILEX, y - 2 * TILEY,
65 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
70 /* draw differences between game tiles and screen tiles
72 * implicitly handles scrolling and restoring background under the sprites
74 * perhaps use mit-shm to speed this up
77 static void animscreen(void)
79 unsigned int x, y, dx, dy;
81 unsigned int left = screen_x / TILEX;
82 unsigned int top = screen_y / TILEY;
84 for (y = top; y < top + MAX_BUF_YSIZE; y++)
86 dy = y % MAX_BUF_YSIZE;
87 for (x = left; x < left + MAX_BUF_XSIZE; x++)
89 dx = x % MAX_BUF_XSIZE;
90 obj = map_obj[frame][Draw[y][x]];
92 if (screentiles[dy][dx] != obj)
94 screentiles[dy][dx] = obj;
95 BlitBitmap(objBitmap, screenBitmap,
96 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
97 TILEX, TILEY, dx * TILEX, dy * TILEY);
104 /* blit players to the screen
106 * handles transparency and movement
109 static void blitplayer(struct PLAYER *ply)
111 unsigned int x, y, dx, dy;
112 unsigned short obj, spr;
113 int src_x, src_y, dest_x, dest_y;
118 x = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
119 y = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
123 if ((unsigned int)(dx - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
124 (unsigned int)(dy - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
126 spr = map_spr[ply->num][frame][ply->anim];
127 x %= MAX_BUF_XSIZE * TILEX;
128 y %= MAX_BUF_YSIZE * TILEY;
129 dx %= MAX_BUF_XSIZE * TILEX;
130 dy %= MAX_BUF_YSIZE * TILEY;
133 /* draw the player to current location */
134 BlitBitmap(sprBitmap, screenBitmap,
135 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
137 /* draw the player to opposite wrap-around column */
138 BlitBitmap(sprBitmap, screenBitmap,
139 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
140 x - MAX_BUF_XSIZE * TILEX, y),
141 /* draw the player to opposite wrap-around row */
142 BlitBitmap(sprBitmap, screenBitmap,
143 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
144 x, y - MAX_BUF_YSIZE * TILEY);
146 /* draw the field the player is moving from (masked over the player) */
147 obj = screentiles[y / TILEY][x / TILEX];
148 src_x = (obj / 512) * TILEX;
149 src_y = (obj % 512) * TILEY / 16;
150 dest_x = (x / TILEX) * TILEX;
151 dest_y = (y / TILEY) * TILEY;
153 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
154 dest_x - src_x, dest_y - src_y);
155 BlitBitmapMasked(objBitmap, screenBitmap,
156 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
158 /* draw the field the player is moving to (masked over the player) */
159 obj = screentiles[dy / TILEY][dx / TILEX];
160 src_x = (obj / 512) * TILEX;
161 src_y = (obj % 512) * TILEY / 16;
162 dest_x = (dx / TILEX) * TILEX;
163 dest_y = (dy / TILEY) * TILEY;
165 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
166 dest_x - src_x, dest_y - src_y);
167 BlitBitmapMasked(objBitmap, screenBitmap,
168 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
174 obj = screentiles[y / TILEY][x / TILEX];
175 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
176 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
177 -(x % TILEX), -(y % TILEY));
179 obj = screentiles[dy / TILEY][dx / TILEX];
180 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
181 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
182 (MAX_BUF_XSIZE * TILEX - x) % TILEX,
183 (MAX_BUF_YSIZE * TILEY - y) % TILEY);
185 else if (sprmaskBitmap)
187 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
188 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
192 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
195 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
197 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
198 BlitBitmapMasked(sprBitmap, screenBitmap,
199 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
202 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
203 x - MAX_BUF_XSIZE * TILEX, y);
204 BlitBitmapMasked(sprBitmap, screenBitmap,
205 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
206 x - MAX_BUF_XSIZE * TILEX, y);
208 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
209 x, y - MAX_BUF_YSIZE * TILEY);
210 BlitBitmapMasked(sprBitmap, screenBitmap,
211 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
212 x, y - MAX_BUF_YSIZE * TILEY);
214 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
217 screentiles[y / TILEY][x / TILEX] = -1; /* mark screen as dirty */
218 screentiles[dy / TILEY][dx / TILEX] = -1;
222 void game_initscreen(void)
230 for (y = 0; y < MAX_BUF_YSIZE; y++)
231 for (x = 0; x < MAX_BUF_XSIZE; x++)
232 screentiles[y][x] = -1;
234 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
238 void game_animscreen(void)
242 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
243 + ((SCR_FIELDX - 1) * TILEX) / 2;
244 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
245 + ((SCR_FIELDY - 1) * TILEY) / 2;
247 if (x > lev.width * TILEX)
248 x = lev.width * TILEX;
249 if (y > lev.height * TILEY)
250 y = lev.height * TILEY;
252 if (x < SCR_FIELDX * TILEX)
253 x = SCR_FIELDX * TILEY;
254 if (y < SCR_FIELDY * TILEY)
255 y = SCR_FIELDY * TILEY;
257 screen_x = x - (SCR_FIELDX - 1) * TILEX;
258 screen_y = y - (SCR_FIELDY - 1) * TILEY;