1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
11 unsigned int frame; /* current screen frame */
13 unsigned int screen_x; /* current scroll position */
14 unsigned int screen_y;
16 int screen_x; /* current scroll position */
20 /* tiles currently on screen */
21 static unsigned int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
22 static unsigned int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
24 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
27 /* copy the entire screen to the window at the scroll position
29 * perhaps use mit-shm to speed this up
32 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
34 unsigned int x = screen_x % (MAX_BUF_XSIZE * TILEX);
35 unsigned int y = screen_y % (MAX_BUF_YSIZE * TILEY);
37 if (x < 2 * TILEX && y < 2 * TILEY)
39 BlitBitmap(screenBitmap, target_bitmap, x, y,
40 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
42 else if (x < 2 * TILEX && y >= 2 * TILEY)
44 BlitBitmap(screenBitmap, target_bitmap, x, y,
45 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
47 BlitBitmap(screenBitmap, target_bitmap, x, 0,
48 SCR_FIELDX * TILEX, y - 2 * TILEY,
49 SX, SY + MAX_BUF_YSIZE * TILEY - y);
51 else if (x >= 2 * TILEX && y < 2 * TILEY)
53 BlitBitmap(screenBitmap, target_bitmap, x, y,
54 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
56 BlitBitmap(screenBitmap, target_bitmap, 0, y,
57 x - 2 * TILEX, SCR_FIELDY * TILEY,
58 SX + MAX_BUF_XSIZE * TILEX - x, SY);
62 BlitBitmap(screenBitmap, target_bitmap, x, y,
63 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
65 BlitBitmap(screenBitmap, target_bitmap, 0, y,
66 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
67 SX + MAX_BUF_XSIZE * TILEX - x, SY);
68 BlitBitmap(screenBitmap, target_bitmap, x, 0,
69 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
70 SX, SY + MAX_BUF_YSIZE * TILEY - y);
71 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
72 x - 2 * TILEX, y - 2 * TILEY,
73 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
81 static boolean scrolling_last = FALSE;
82 unsigned int left = screen_x / TILEX;
83 unsigned int top = screen_y / TILEY;
84 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
89 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
91 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
92 BlitScreenToBitmap_EM(backbuffer);
94 /* blit the completely updated backbuffer to the window (in one blit) */
95 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
99 for (x = 0; x < SCR_FIELDX; x++)
101 for (y = 0; y < SCR_FIELDY; y++)
103 int xx = (left + x) % MAX_BUF_XSIZE;
104 int yy = (top + y) % MAX_BUF_YSIZE;
107 BlitBitmap(screenBitmap, window,
108 xx * TILEX, yy * TILEY, TILEX, TILEY,
109 SX + x * TILEX, SY + y * TILEY);
114 for (x = 0; x < MAX_BUF_XSIZE; x++)
115 for (y = 0; y < MAX_BUF_YSIZE; y++)
116 redraw[x][y] = FALSE;
119 scrolling_last = scrolling;
123 /* blit all (up to four) parts of the scroll buffer to the window */
124 BlitScreenToBitmap_EM(window);
129 static void DrawLevelField_EM(int x, int y, int sx, int sy,
132 int tile = Draw[y][x];
133 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
134 int src_x = g->src_x + g->src_offset_x;
135 int src_y = g->src_y + g->src_offset_y;
136 int dst_x = sx * TILEX + g->dst_offset_x;
137 int dst_y = sy * TILEY + g->dst_offset_y;
138 int width = g->width;
139 int height = g->height;
143 if (width > 0 && height > 0)
145 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
146 dst_x - src_x, dst_y - src_y);
147 BlitBitmapMasked(g->bitmap, screenBitmap,
148 src_x, src_y, width, height, dst_x, dst_y);
153 if ((width != TILEX || height != TILEY) && !g->preserve_background)
154 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
156 if (width > 0 && height > 0)
157 BlitBitmap(g->bitmap, screenBitmap,
158 src_x, src_y, width, height, dst_x, dst_y);
162 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
163 int crm, boolean draw_masked)
165 int tile = Draw[y][x];
166 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
169 if (crm == 0) /* no crumbled edges for this tile */
172 for (i = 0; i < 4; i++)
176 int width, height, cx, cy;
178 if (i == 1 || i == 2)
180 width = g->crumbled_border_size;
182 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
188 height = g->crumbled_border_size;
190 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
193 if (width > 0 && height > 0)
195 int src_x = g->crumbled_src_x + cx;
196 int src_y = g->crumbled_src_y + cy;
197 int dst_x = sx * TILEX + cx;
198 int dst_y = sy * TILEY + cy;
202 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
203 dst_x - src_x, dst_y - src_y);
204 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
205 src_x, src_y, width, height, dst_x, dst_y);
208 BlitBitmap(g->crumbled_bitmap, screenBitmap,
209 src_x, src_y, width, height, dst_x, dst_y);
215 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
218 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
220 int src_x = g->src_x, src_y = g->src_y;
225 /* draw the player to current location */
228 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
229 dst_x - src_x, dst_y - src_y);
230 BlitBitmapMasked(g->bitmap, screenBitmap,
231 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
233 /* draw the player to opposite wrap-around column */
234 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
236 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
237 dst_x - src_x, dst_y - src_y);
238 BlitBitmapMasked(g->bitmap, screenBitmap,
239 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
241 /* draw the player to opposite wrap-around row */
243 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
244 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
245 dst_x - src_x, dst_y - src_y);
246 BlitBitmapMasked(g->bitmap, screenBitmap,
247 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
251 /* draw the player to current location */
254 BlitBitmap(g->bitmap, screenBitmap,
255 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
257 /* draw the player to opposite wrap-around column */
258 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
260 BlitBitmap(g->bitmap, screenBitmap,
261 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
263 /* draw the player to opposite wrap-around row */
265 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
266 BlitBitmap(g->bitmap, screenBitmap,
267 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
271 /* draw differences between game tiles and screen tiles
273 * implicitly handles scrolling and restoring background under the sprites
275 * perhaps use mit-shm to speed this up
278 static void animscreen(void)
280 unsigned int x, y, i;
281 unsigned int left = screen_x / TILEX;
282 unsigned int top = screen_y / TILEY;
283 static int xy[4][2] =
291 for (y = top; y < top + MAX_BUF_YSIZE; y++)
293 for (x = left; x < left + MAX_BUF_XSIZE; x++)
295 int sx = x % MAX_BUF_XSIZE;
296 int sy = y % MAX_BUF_YSIZE;
297 int tile = Draw[y][x];
298 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
299 unsigned int obj = g->unique_identifier;
300 unsigned int crm = 0;
302 /* re-calculate crumbled state of this tile */
303 if (g->has_crumbled_graphics)
305 for (i = 0; i < 4; i++)
307 int xx = x + xy[i][0];
308 int yy = y + xy[i][1];
311 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
312 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
315 tile_next = Draw[yy][xx];
317 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
322 /* only redraw screen tiles if they (or their crumbled state) changed */
323 if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
325 DrawLevelField_EM(x, y, sx, sy, FALSE);
326 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
328 screentiles[sy][sx] = obj;
329 crumbled_state[sy][sx] = crm;
331 redraw[sx][sy] = TRUE;
339 /* blit players to the screen
341 * handles transparency and movement
344 static void blitplayer(struct PLAYER *ply)
346 unsigned int x1, y1, x2, y2;
351 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
352 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
353 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
357 if ((unsigned int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
358 (unsigned int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
360 /* some casts to "int" are needed because of negative calculation values */
361 int dx = (int)ply->x - (int)ply->oldx;
362 int dy = (int)ply->y - (int)ply->oldy;
363 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
364 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
365 int new_x = old_x + SIGN(dx);
366 int new_y = old_y + SIGN(dy);
367 int old_sx = old_x % MAX_BUF_XSIZE;
368 int old_sy = old_y % MAX_BUF_XSIZE;
369 int new_sx = new_x % MAX_BUF_XSIZE;
370 int new_sy = new_y % MAX_BUF_XSIZE;
372 int old_crm = crumbled_state[old_sy][old_sx];
374 int new_crm = crumbled_state[new_sy][new_sx];
376 /* only diggable elements can be crumbled in the classic EM engine */
377 boolean player_is_digging = (new_crm != 0);
379 x1 %= MAX_BUF_XSIZE * TILEX;
380 y1 %= MAX_BUF_YSIZE * TILEY;
381 x2 %= MAX_BUF_XSIZE * TILEX;
382 y2 %= MAX_BUF_YSIZE * TILEY;
384 if (player_is_digging)
387 /* draw the field the player is moving from (under the player) */
388 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
389 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
392 /* draw the field the player is moving to (under the player) */
393 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
394 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
396 /* draw the player (masked) over the element he is just digging away */
397 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
400 /* draw the field the player is moving from (masked over the player) */
401 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
406 /* draw the player under the element which is on the same field */
407 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
409 /* draw the field the player is moving from (masked over the player) */
410 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
412 /* draw the field the player is moving to (masked over the player) */
413 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
416 /* mark screen tiles as dirty */
417 screentiles[old_sy][old_sx] = -1;
418 screentiles[new_sy][new_sx] = -1;
422 void game_initscreen(void)
425 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
426 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
432 for (y = 0; y < MAX_BUF_YSIZE; y++)
434 for (x = 0; x < MAX_BUF_XSIZE; x++)
436 screentiles[y][x] = -1;
437 crumbled_state[y][x] = 0;
442 DrawAllGameValues(lev.required, dynamite_state, lev.score,
443 lev.time, all_keys_state);
445 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
446 DISPLAY_TIME(lev.time + 4), ply1.keys | ply2.keys);
450 void RedrawPlayfield_EM()
456 int screen_x_min = TILEX;
457 int screen_y_min = TILEY;
458 int screen_x_max = (lev.width - (SCR_FIELDX - 1)) * TILEX;
459 int screen_y_max = (lev.height - (SCR_FIELDY - 1)) * TILEY;
460 int offset = (setup.scroll_delay ? 3 : 0) * TILEX;
461 int stepsize = TILEX / 8;
462 int nr = 0; /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
464 sx = (frame * ply[nr].oldx + (8 - frame) * ply[nr].x) * stepsize
465 - ((SCR_FIELDX - 1) * TILEX) / 2;
466 sy = (frame * ply[nr].oldy + (8 - frame) * ply[nr].y) * stepsize
467 - ((SCR_FIELDY - 1) * TILEY) / 2;
469 /* calculate new screen scrolling position, with regard to scroll delay */
470 screen_x = (sx < screen_x - offset ? sx + offset :
471 sx > screen_x + offset ? sx - offset : screen_x);
472 screen_y = (sy < screen_y - offset ? sy + offset :
473 sy > screen_y + offset ? sy - offset : screen_y);
475 /* check minimal and maximal boundaries for screen scrolling position */
476 screen_x = (screen_x < screen_x_min ? screen_x_min :
477 screen_x > screen_x_max ? screen_x_max : screen_x);
478 screen_y = (screen_y < screen_y_min ? screen_y_min :
479 screen_y > screen_y_max ? screen_y_max : screen_y);
483 /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
484 sx = (frame * ply[0].oldx + (8 - frame) * ply[0].x) * TILEX / 8
485 + ((SCR_FIELDX - 1) * TILEX) / 2;
486 sy = (frame * ply[0].oldy + (8 - frame) * ply[0].y) * TILEY / 8
487 + ((SCR_FIELDY - 1) * TILEY) / 2;
489 if (sx > lev.width * TILEX)
490 sx = lev.width * TILEX;
491 if (sy > lev.height * TILEY)
492 sy = lev.height * TILEY;
494 if (sx < SCR_FIELDX * TILEX)
495 sx = SCR_FIELDX * TILEY;
496 if (sy < SCR_FIELDY * TILEY)
497 sy = SCR_FIELDY * TILEY;
499 screen_x = sx - (SCR_FIELDX - 1) * TILEX;
500 screen_y = sy - (SCR_FIELDY - 1) * TILEY;
506 for (i = 0; i < MAX_PLAYERS; i++)
514 void game_animscreen(void)
516 RedrawPlayfield_EM();
519 void DrawGameDoorValues_EM()
521 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
522 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
525 DrawAllGameValues(lev.required, dynamite_state, lev.score,
526 lev.time, all_keys_state);
528 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
529 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);