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;
88 for (x = left; x < left + MAX_BUF_XSIZE; x++)
90 int tile = Draw[y][x];
92 dx = x % MAX_BUF_XSIZE;
93 obj = map_obj[frame][tile];
95 if (screentiles[dy][dx] != obj)
98 struct GraphicInfo_EM *g = &graphic_info_em[tile][frame];
99 int dst_x = dx * TILEX;
100 int dst_y = dy * TILEY;
102 if (g->width != TILEX || g->height != TILEY)
103 ClearRectangle(screenBitmap, dst_x, dst_y, TILEX, TILEY);
105 if (g->width > 0 && g->height > 0)
106 BlitBitmap(g->bitmap, screenBitmap,
107 g->src_x + g->src_offset_x, g->src_y + g->src_offset_y,
109 dst_x + g->dst_offset_x, dst_y + g->dst_offset_y);
111 BlitBitmap(objBitmap, screenBitmap,
112 (obj / 512) * TILEX, (obj % 512) * TILEY / 16,
113 TILEX, TILEY, dx * TILEX, dy * TILEY);
116 screentiles[dy][dx] = obj;
123 /* blit players to the screen
125 * handles transparency and movement
128 static void blitplayer(struct PLAYER *ply)
131 int old_x, old_y, new_x, new_y;
132 int src_x, src_y, dst_x, dst_y;
134 struct GraphicInfo_EM *g;
135 unsigned int x1, y1, x2, y2;
139 unsigned short obj, spr;
145 /* some casts to "int" are needed because of negative calculation values */
146 dx = (int)ply->x - (int)ply->oldx;
147 dy = (int)ply->y - (int)ply->oldy;
148 old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
149 old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
150 new_x = old_x + SIGN(dx);
151 new_y = old_y + SIGN(dy);
153 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
154 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
155 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
159 if ((unsigned int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
160 (unsigned int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
162 spr = map_spr[ply->num][frame][ply->anim];
163 x1 %= MAX_BUF_XSIZE * TILEX;
164 y1 %= MAX_BUF_YSIZE * TILEY;
165 x2 %= MAX_BUF_XSIZE * TILEX;
166 y2 %= MAX_BUF_YSIZE * TILEY;
169 /* draw the player to current location */
170 BlitBitmap(sprBitmap, screenBitmap,
171 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
173 /* draw the player to opposite wrap-around column */
174 BlitBitmap(sprBitmap, screenBitmap,
175 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
176 x1 - MAX_BUF_XSIZE * TILEX, y1),
177 /* draw the player to opposite wrap-around row */
178 BlitBitmap(sprBitmap, screenBitmap,
179 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
180 x1, y1 - MAX_BUF_YSIZE * TILEY);
182 /* draw the field the player is moving from (masked over the player) */
184 obj = screentiles[y1 / TILEY][x1 / TILEX];
185 src_x = (obj / 512) * TILEX;
186 src_y = (obj % 512) * TILEY / 16;
187 dst_x = (x1 / TILEX) * TILEX;
188 dst_y = (y1 / TILEY) * TILEY;
192 tile = Draw[old_y][old_x];
193 g = &graphic_info_em[tile][frame];
195 if (g->width > 0 && g->height > 0)
197 src_x = g->src_x + g->src_offset_x;
198 src_y = g->src_y + g->src_offset_y;
199 dst_x = old_x % MAX_BUF_XSIZE * TILEX + g->dst_offset_x;
200 dst_y = old_y % MAX_BUF_YSIZE * TILEY + g->dst_offset_y;
202 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
203 dst_x - src_x, dst_y - src_y);
204 BlitBitmapMasked(g->bitmap, screenBitmap,
205 src_x, src_y, g->width, g->height, dst_x, dst_y);
208 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
209 dst_x - src_x, dst_y - src_y);
210 BlitBitmapMasked(objBitmap, screenBitmap,
211 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
214 /* draw the field the player is moving to (masked over the player) */
216 obj = screentiles[y2 / TILEY][x2 / TILEX];
217 src_x = (obj / 512) * TILEX;
218 src_y = (obj % 512) * TILEY / 16;
219 dst_x = (x2 / TILEX) * TILEX;
220 dst_y = (y2 / TILEY) * TILEY;
224 tile = Draw[new_y][new_x];
225 g = &graphic_info_em[tile][frame];
227 if (g->width > 0 && g->height > 0)
229 src_x = g->src_x + g->src_offset_x;
230 src_y = g->src_y + g->src_offset_y;
231 dst_x = new_x % MAX_BUF_XSIZE * TILEX + g->dst_offset_x;
232 dst_y = new_y % MAX_BUF_YSIZE * TILEY + g->dst_offset_y;
234 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
235 dst_x - src_x, dst_y - src_y);
236 BlitBitmapMasked(g->bitmap, screenBitmap,
237 src_x, src_y, g->width, g->height, dst_x, dst_y);
240 SetClipOrigin(objBitmap, objBitmap->stored_clip_gc,
241 dst_x - src_x, dst_y - src_y);
242 BlitBitmapMasked(objBitmap, screenBitmap,
243 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
250 obj = screentiles[y1 / TILEY][x1 / TILEX];
251 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
252 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
253 -(x1 % TILEX), -(y1 % TILEY));
255 obj = screentiles[y2 / TILEY][x2 / TILEX];
256 XCopyArea(display, objmaskBitmap, spriteBitmap, spriteGC,
257 (obj / 512) * TILEX, (obj % 512) * TILEY / 16, TILEX, TILEY,
258 (MAX_BUF_XSIZE * TILEX - x1) % TILEX,
259 (MAX_BUF_YSIZE * TILEY - y1) % TILEY);
261 else if (sprmaskBitmap)
263 XCopyArea(display, sprmaskBitmap, spriteBitmap, spriteGC,
264 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY, 0, 0);
268 XFillRectangle(display, spriteBitmap, spriteGC, 0, 0, TILEX, TILEY);
271 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, spriteBitmap);
273 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc, x, y);
274 BlitBitmapMasked(sprBitmap, screenBitmap,
275 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
278 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
279 x - MAX_BUF_XSIZE * TILEX, y);
280 BlitBitmapMasked(sprBitmap, screenBitmap,
281 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
282 x1 - MAX_BUF_XSIZE * TILEX, y1);
284 SetClipOrigin(sprBitmap, sprBitmap->stored_clip_gc,
285 x1, y1 - MAX_BUF_YSIZE * TILEY);
286 BlitBitmapMasked(sprBitmap, screenBitmap,
287 (spr / 8) * TILEX, (spr % 8) * TILEY, TILEX, TILEY,
288 x1, y1 - MAX_BUF_YSIZE * TILEY);
290 SetClipMask(sprBitmap, sprBitmap->stored_clip_gc, None);
293 /* mark screen tiles as dirty */
294 screentiles[y1 / TILEY][x1 / TILEX] = -1;
295 screentiles[y2 / TILEY][x2 / TILEX] = -1;
299 void game_initscreen(void)
307 for (y = 0; y < MAX_BUF_YSIZE; y++)
308 for (x = 0; x < MAX_BUF_XSIZE; x++)
309 screentiles[y][x] = -1;
311 DrawGameDoorValues_EM(lev.required, ply1.dynamite, lev.score,
312 DISPLAY_TIME(lev.time + 4));
315 void game_animscreen(void)
319 x = (frame * ply1.oldx + (8 - frame) * ply1.x) * TILEX / 8
320 + ((SCR_FIELDX - 1) * TILEX) / 2;
321 y = (frame * ply1.oldy + (8 - frame) * ply1.y) * TILEY / 8
322 + ((SCR_FIELDY - 1) * TILEY) / 2;
324 if (x > lev.width * TILEX)
325 x = lev.width * TILEX;
326 if (y > lev.height * TILEY)
327 y = lev.height * TILEY;
329 if (x < SCR_FIELDX * TILEX)
330 x = SCR_FIELDX * TILEY;
331 if (y < SCR_FIELDY * TILEY)
332 y = SCR_FIELDY * TILEY;
334 screen_x = x - (SCR_FIELDX - 1) * TILEX;
335 screen_y = y - (SCR_FIELDY - 1) * TILEY;