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 int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
17 static unsigned int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
19 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
22 /* copy the entire screen to the window at the scroll position
24 * perhaps use mit-shm to speed this up
27 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
29 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
30 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
32 if (x < 2 * TILEX && y < 2 * TILEY)
34 BlitBitmap(screenBitmap, target_bitmap, x, y,
35 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
37 else if (x < 2 * TILEX && y >= 2 * TILEY)
39 BlitBitmap(screenBitmap, target_bitmap, x, y,
40 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
42 BlitBitmap(screenBitmap, target_bitmap, x, 0,
43 SCR_FIELDX * TILEX, y - 2 * TILEY,
44 SX, SY + MAX_BUF_YSIZE * TILEY - y);
46 else if (x >= 2 * TILEX && y < 2 * TILEY)
48 BlitBitmap(screenBitmap, target_bitmap, x, y,
49 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
51 BlitBitmap(screenBitmap, target_bitmap, 0, y,
52 x - 2 * TILEX, SCR_FIELDY * TILEY,
53 SX + MAX_BUF_XSIZE * TILEX - x, SY);
57 BlitBitmap(screenBitmap, target_bitmap, x, y,
58 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
60 BlitBitmap(screenBitmap, target_bitmap, 0, y,
61 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
62 SX + MAX_BUF_XSIZE * TILEX - x, SY);
63 BlitBitmap(screenBitmap, target_bitmap, x, 0,
64 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
65 SX, SY + MAX_BUF_YSIZE * TILEY - y);
66 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
67 x - 2 * TILEX, y - 2 * TILEY,
68 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
76 static boolean scrolling_last = FALSE;
77 unsigned int left = screen_x / TILEX;
78 unsigned int top = screen_y / TILEY;
79 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
84 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
86 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
87 BlitScreenToBitmap_EM(backbuffer);
89 /* blit the completely updated backbuffer to the window (in one blit) */
90 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
94 for (x = 0; x < SCR_FIELDX; x++)
96 for (y = 0; y < SCR_FIELDY; y++)
98 int xx = (left + x) % MAX_BUF_XSIZE;
99 int yy = (top + y) % MAX_BUF_YSIZE;
102 BlitBitmap(screenBitmap, window,
103 xx * TILEX, yy * TILEY, TILEX, TILEY,
104 SX + x * TILEX, SY + y * TILEY);
109 for (x = 0; x < MAX_BUF_XSIZE; x++)
110 for (y = 0; y < MAX_BUF_YSIZE; y++)
111 redraw[x][y] = FALSE;
114 scrolling_last = scrolling;
118 /* blit all (up to four) parts of the scroll buffer to the window */
119 BlitScreenToBitmap_EM(window);
124 static void DrawLevelField_EM(int x, int y, int sx, int sy,
127 int tile = Draw[y][x];
128 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
129 int src_x = g->src_x + g->src_offset_x;
130 int src_y = g->src_y + g->src_offset_y;
131 int dst_x = sx * TILEX + g->dst_offset_x;
132 int dst_y = sy * TILEY + g->dst_offset_y;
133 int width = g->width;
134 int height = g->height;
138 if (width > 0 && height > 0)
140 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
141 dst_x - src_x, dst_y - src_y);
142 BlitBitmapMasked(g->bitmap, screenBitmap,
143 src_x, src_y, width, height, dst_x, dst_y);
148 if ((width != TILEX || height != TILEY) && !g->preserve_background)
149 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
151 if (width > 0 && height > 0)
152 BlitBitmap(g->bitmap, screenBitmap,
153 src_x, src_y, width, height, dst_x, dst_y);
157 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
158 int crm, boolean draw_masked)
160 int tile = Draw[y][x];
161 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
164 if (crm == 0) /* no crumbled edges for this tile */
167 for (i = 0; i < 4; i++)
171 int width, height, cx, cy;
173 if (i == 1 || i == 2)
175 width = g->crumbled_border_size;
177 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
183 height = g->crumbled_border_size;
185 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
188 if (width > 0 && height > 0)
190 int src_x = g->crumbled_src_x + cx;
191 int src_y = g->crumbled_src_y + cy;
192 int dst_x = sx * TILEX + cx;
193 int dst_y = sy * TILEY + cy;
197 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
198 dst_x - src_x, dst_y - src_y);
199 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
200 src_x, src_y, width, height, dst_x, dst_y);
203 BlitBitmap(g->crumbled_bitmap, screenBitmap,
204 src_x, src_y, width, height, dst_x, dst_y);
210 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
213 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
215 int src_x = g->src_x, src_y = g->src_y;
220 /* draw the player to current location */
223 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
224 dst_x - src_x, dst_y - src_y);
225 BlitBitmapMasked(g->bitmap, screenBitmap,
226 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
228 /* draw the player to opposite wrap-around column */
229 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
231 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
232 dst_x - src_x, dst_y - src_y);
233 BlitBitmapMasked(g->bitmap, screenBitmap,
234 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
236 /* draw the player to opposite wrap-around row */
238 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
239 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
240 dst_x - src_x, dst_y - src_y);
241 BlitBitmapMasked(g->bitmap, screenBitmap,
242 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
246 /* draw the player to current location */
249 BlitBitmap(g->bitmap, screenBitmap,
250 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
252 /* draw the player to opposite wrap-around column */
253 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
255 BlitBitmap(g->bitmap, screenBitmap,
256 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
258 /* draw the player to opposite wrap-around row */
260 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
261 BlitBitmap(g->bitmap, screenBitmap,
262 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
266 /* draw differences between game tiles and screen tiles
268 * implicitly handles scrolling and restoring background under the sprites
270 * perhaps use mit-shm to speed this up
273 static void animscreen(void)
275 unsigned int x, y, i;
276 unsigned int left = screen_x / TILEX;
277 unsigned int top = screen_y / TILEY;
278 static int xy[4][2] =
286 for (y = top; y < top + MAX_BUF_YSIZE; y++)
288 for (x = left; x < left + MAX_BUF_XSIZE; x++)
290 int sx = x % MAX_BUF_XSIZE;
291 int sy = y % MAX_BUF_YSIZE;
292 int tile = Draw[y][x];
293 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
294 unsigned int obj = g->unique_identifier;
295 unsigned int crm = 0;
297 /* re-calculate crumbled state of this tile */
298 if (g->has_crumbled_graphics)
300 for (i = 0; i < 4; i++)
302 int xx = x + xy[i][0];
303 int yy = y + xy[i][1];
306 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
307 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
310 tile_next = Draw[yy][xx];
312 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
317 /* only redraw screen tiles if they (or their crumbled state) changed */
318 if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
320 DrawLevelField_EM(x, y, sx, sy, FALSE);
321 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
323 screentiles[sy][sx] = obj;
324 crumbled_state[sy][sx] = crm;
326 redraw[sx][sy] = TRUE;
334 /* blit players to the screen
336 * handles transparency and movement
339 static void blitplayer(struct PLAYER *ply)
341 unsigned int x1, y1, x2, y2;
346 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
347 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
348 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
352 if ((unsigned int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
353 (unsigned int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
355 /* some casts to "int" are needed because of negative calculation values */
356 int dx = (int)ply->x - (int)ply->oldx;
357 int dy = (int)ply->y - (int)ply->oldy;
358 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
359 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
360 int new_x = old_x + SIGN(dx);
361 int new_y = old_y + SIGN(dy);
362 int old_sx = old_x % MAX_BUF_XSIZE;
363 int old_sy = old_y % MAX_BUF_XSIZE;
364 int new_sx = new_x % MAX_BUF_XSIZE;
365 int new_sy = new_y % MAX_BUF_XSIZE;
367 int old_crm = crumbled_state[old_sy][old_sx];
369 int new_crm = crumbled_state[new_sy][new_sx];
371 /* only diggable elements can be crumbled in the classic EM engine */
372 boolean player_is_digging = (new_crm != 0);
374 x1 %= MAX_BUF_XSIZE * TILEX;
375 y1 %= MAX_BUF_YSIZE * TILEY;
376 x2 %= MAX_BUF_XSIZE * TILEX;
377 y2 %= MAX_BUF_YSIZE * TILEY;
379 if (player_is_digging)
382 /* draw the field the player is moving from (under the player) */
383 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
384 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
387 /* draw the field the player is moving to (under the player) */
388 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
389 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
391 /* draw the player (masked) over the element he is just digging away */
392 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
395 /* draw the field the player is moving from (masked over the player) */
396 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
401 /* draw the player under the element which is on the same field */
402 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
404 /* draw the field the player is moving from (masked over the player) */
405 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
407 /* draw the field the player is moving to (masked over the player) */
408 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
411 /* mark screen tiles as dirty */
412 screentiles[old_sy][old_sx] = -1;
413 screentiles[new_sy][new_sx] = -1;
417 void game_initscreen(void)
420 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
421 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
427 for (y = 0; y < MAX_BUF_YSIZE; y++)
429 for (x = 0; x < MAX_BUF_XSIZE; x++)
431 screentiles[y][x] = -1;
432 crumbled_state[y][x] = 0;
437 DrawAllGameValues(lev.required, dynamite_state, lev.score,
438 lev.time, all_keys_state);
440 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
441 DISPLAY_TIME(lev.time + 4), ply1.keys | ply2.keys);
445 void RedrawPlayfield_EM()
447 unsigned int i, x, y;
449 /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
450 x = (frame * ply[0].oldx + (8 - frame) * ply[0].x) * TILEX / 8
451 + ((SCR_FIELDX - 1) * TILEX) / 2;
452 y = (frame * ply[0].oldy + (8 - frame) * ply[0].y) * TILEY / 8
453 + ((SCR_FIELDY - 1) * TILEY) / 2;
455 if (x > lev.width * TILEX)
456 x = lev.width * TILEX;
457 if (y > lev.height * TILEY)
458 y = lev.height * TILEY;
460 if (x < SCR_FIELDX * TILEX)
461 x = SCR_FIELDX * TILEY;
462 if (y < SCR_FIELDY * TILEY)
463 y = SCR_FIELDY * TILEY;
465 screen_x = x - (SCR_FIELDX - 1) * TILEX;
466 screen_y = y - (SCR_FIELDY - 1) * TILEY;
470 for (i = 0; i < MAX_PLAYERS; i++)
478 void game_animscreen(void)
480 RedrawPlayfield_EM();
483 void DrawGameDoorValues_EM()
485 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
486 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
489 DrawAllGameValues(lev.required, dynamite_state, lev.score,
490 lev.time, all_keys_state);
492 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
493 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);