1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
8 #define MIN_SCREEN_XPOS 1
9 #define MIN_SCREEN_YPOS 1
10 #define MAX_SCREEN_XPOS MAX(1, lev.width - (SCR_FIELDX - 1))
11 #define MAX_SCREEN_YPOS MAX(1, lev.height - (SCR_FIELDY - 1))
13 #define MIN_SCREEN_X (MIN_SCREEN_XPOS * TILEX)
14 #define MIN_SCREEN_Y (MIN_SCREEN_YPOS * TILEY)
15 #define MAX_SCREEN_X (MAX_SCREEN_XPOS * TILEX)
16 #define MAX_SCREEN_Y (MAX_SCREEN_YPOS * TILEY)
18 #define VALID_SCREEN_X(x) ((x) < MIN_SCREEN_X ? MIN_SCREEN_X : \
19 (x) > MAX_SCREEN_X ? MAX_SCREEN_X : (x))
20 #define VALID_SCREEN_Y(y) ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y : \
21 (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
23 #define PLAYER_SCREEN_X(p) ((( frame) * ply[p].oldx + \
24 (8 - frame) * ply[p].x) * TILEX / 8 \
25 - ((SCR_FIELDX - 1) * TILEX) / 2)
26 #define PLAYER_SCREEN_Y(p) ((( frame) * ply[p].oldy + \
27 (8 - frame) * ply[p].y) * TILEY / 8 \
28 - ((SCR_FIELDY - 1) * TILEY) / 2)
30 #define USE_EXTENDED_GRAPHICS_ENGINE 1
34 int TILEX = ORIG_TILEX * ZOOM_FACTOR;
35 int TILEY = ORIG_TILEY * ZOOM_FACTOR;
38 int frame; /* current screen frame */
39 int screen_x, screen_y; /* current scroll position */
41 /* tiles currently on screen */
43 static int screentiles[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2];
44 static int crumbled_state[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2];
46 static boolean redraw[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
48 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
49 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
51 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
56 int centered_player_nr;
58 static int centered_player_nr;
62 /* copy the entire screen to the window at the scroll position */
64 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
66 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
67 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
68 int sx, sy, sxsize, sysize;
71 int full_xsize = lev.width * TILEX;
72 int full_ysize = lev.height * TILEY;
74 sxsize = (full_xsize < xsize ? full_xsize : xsize);
75 sysize = (full_ysize < ysize ? full_ysize : ysize);
76 sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
77 sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
80 printf("::: %d, %d\n", screenBitmap->width, screenBitmap->height);
81 BlitBitmap(screenBitmap, target_bitmap, 0, 0, 544, 544, SX, SY);
86 if (x < 2 * TILEX && y < 2 * TILEY)
88 BlitBitmap(screenBitmap, target_bitmap, x, y,
89 sxsize, sysize, sx, sy);
91 else if (x < 2 * TILEX && y >= 2 * TILEY)
93 BlitBitmap(screenBitmap, target_bitmap, x, y,
94 sxsize, MAX_BUF_YSIZE * TILEY - y,
96 BlitBitmap(screenBitmap, target_bitmap, x, 0,
97 sxsize, y - 2 * TILEY,
98 sx, sy + MAX_BUF_YSIZE * TILEY - y);
100 else if (x >= 2 * TILEX && y < 2 * TILEY)
102 BlitBitmap(screenBitmap, target_bitmap, x, y,
103 MAX_BUF_XSIZE * TILEX - x, sysize,
105 BlitBitmap(screenBitmap, target_bitmap, 0, y,
106 x - 2 * TILEX, sysize,
107 sx + MAX_BUF_XSIZE * TILEX - x, sy);
111 BlitBitmap(screenBitmap, target_bitmap, x, y,
112 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
114 BlitBitmap(screenBitmap, target_bitmap, 0, y,
115 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
116 sx + MAX_BUF_XSIZE * TILEX - x, sy);
117 BlitBitmap(screenBitmap, target_bitmap, x, 0,
118 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
119 sx, sy + MAX_BUF_YSIZE * TILEY - y);
120 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
121 x - 2 * TILEX, y - 2 * TILEY,
122 sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y);
125 if (x < 2 * TILEX && y < 2 * TILEY)
127 BlitBitmap(screenBitmap, target_bitmap, x, y,
128 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
130 else if (x < 2 * TILEX && y >= 2 * TILEY)
132 BlitBitmap(screenBitmap, target_bitmap, x, y,
133 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
135 BlitBitmap(screenBitmap, target_bitmap, x, 0,
136 SCR_FIELDX * TILEX, y - 2 * TILEY,
137 SX, SY + MAX_BUF_YSIZE * TILEY - y);
139 else if (x >= 2 * TILEX && y < 2 * TILEY)
141 BlitBitmap(screenBitmap, target_bitmap, x, y,
142 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
144 BlitBitmap(screenBitmap, target_bitmap, 0, y,
145 x - 2 * TILEX, SCR_FIELDY * TILEY,
146 SX + MAX_BUF_XSIZE * TILEX - x, SY);
150 BlitBitmap(screenBitmap, target_bitmap, x, y,
151 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
153 BlitBitmap(screenBitmap, target_bitmap, 0, y,
154 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
155 SX + MAX_BUF_XSIZE * TILEX - x, SY);
156 BlitBitmap(screenBitmap, target_bitmap, x, 0,
157 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
158 SX, SY + MAX_BUF_YSIZE * TILEY - y);
159 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
160 x - 2 * TILEX, y - 2 * TILEY,
161 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
166 void BackToFront_EM(void)
168 static int screen_x_last = -1, screen_y_last = -1;
169 static boolean scrolling_last = FALSE;
170 int left = screen_x / TILEX;
171 int top = screen_y / TILEY;
173 boolean scrolling = (screen_x != screen_x_last || screen_y != screen_y_last);
175 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
180 printf("::: %d, %d\n", screen_x, screen_y);
185 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
187 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
188 BlitScreenToBitmap_EM(backbuffer);
190 /* blit the completely updated backbuffer to the window (in one blit) */
191 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
197 boolean half_shifted_x = (screen_x % TILEX != 0);
198 boolean half_shifted_y = (screen_y % TILEY != 0);
200 boolean half_shifted_x = (EVEN(SCR_FIELDX) && screen_x % TILEX != 0);
201 boolean half_shifted_y = (EVEN(SCR_FIELDY) && screen_y % TILEY != 0);
210 int full_xsize = lev.width * TILEX;
211 int full_ysize = lev.height * TILEY;
214 sxsize = (full_xsize < xsize ? full_xsize : xsize);
215 sysize = (full_ysize < ysize ? full_ysize : ysize);
217 sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
218 sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
222 printf("::: %d, %d\n", EVEN(SCR_FIELDX), screen_x);
224 half_shifted_x = TRUE;
225 half_shifted_y = FALSE;
229 int x1 = 0, x2 = SCR_FIELDX - (half_shifted_x ? 0 : 1);
230 int y1 = 0, y2 = SCR_FIELDY - (half_shifted_y ? 0 : 1);
231 int scroll_xoffset = (half_shifted_x ? TILEX / 2 : 0);
232 int scroll_yoffset = (half_shifted_y ? TILEY / 2 : 0);
234 InitGfxClipRegion(TRUE, SX, SY, SXSIZE, SYSIZE);
236 for (x = x1; x <= x2; x++)
238 for (y = y1; y <= y2; y++)
240 int xx = (left + x) % MAX_BUF_XSIZE;
241 int yy = (top + y) % MAX_BUF_YSIZE;
244 BlitBitmap(screenBitmap, window,
245 xx * TILEX, yy * TILEY, TILEX, TILEY,
246 sx + x * TILEX - scroll_xoffset,
247 sy + y * TILEY - scroll_yoffset);
251 InitGfxClipRegion(FALSE, -1, -1, -1, -1);
255 for (x = 0; x < SCR_FIELDX; x++)
257 for (y = 0; y < SCR_FIELDY; y++)
259 int xx = (left + x) % MAX_BUF_XSIZE;
260 int yy = (top + y) % MAX_BUF_YSIZE;
263 BlitBitmap(screenBitmap, window,
264 xx * TILEX, yy * TILEY, TILEX, TILEY,
265 SX + x * TILEX, SY + y * TILEY);
273 for (x = 0; x < MAX_BUF_XSIZE; x++)
274 for (y = 0; y < MAX_BUF_YSIZE; y++)
275 redraw[x][y] = FALSE;
278 screen_x_last = screen_x;
279 screen_y_last = screen_y;
280 scrolling_last = scrolling;
283 void blitscreen(void)
288 static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
290 int tile = Draw[y][x];
291 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
293 if (!game.use_native_emc_graphics_engine)
294 getGraphicSourceObjectExt_EM(g, tile, 7 - frame, x - 2, y - 2);
299 static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
301 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
303 if (!game.use_native_emc_graphics_engine)
304 getGraphicSourcePlayerExt_EM(g, player_nr, anim, 7 - frame);
309 static void DrawLevelField_EM(int x, int y, int sx, int sy,
312 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
314 int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE;
315 int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE;
316 int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE;
317 int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE;
318 int width = g->width * TILESIZE_VAR / TILESIZE;
319 int height = g->height * TILESIZE_VAR / TILESIZE;
321 int src_x = g->src_x + g->src_offset_x;
322 int src_y = g->src_y + g->src_offset_y;
323 int dst_x = sx * TILEX + g->dst_offset_x;
324 int dst_y = sy * TILEY + g->dst_offset_y;
325 int width = g->width;
326 int height = g->height;
328 int left = screen_x / TILEX;
329 int top = screen_y / TILEY;
331 /* do not draw fields that are outside the visible screen area */
332 if (x < left || x >= left + MAX_BUF_XSIZE ||
333 y < top || y >= top + MAX_BUF_YSIZE)
338 if (width > 0 && height > 0)
340 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
341 dst_x - src_x, dst_y - src_y);
342 BlitBitmapMasked(g->bitmap, screenBitmap,
343 src_x, src_y, width, height, dst_x, dst_y);
348 if ((width != TILEX || height != TILEY) && !g->preserve_background)
349 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
351 if (width > 0 && height > 0)
352 BlitBitmap(g->bitmap, screenBitmap,
353 src_x, src_y, width, height, dst_x, dst_y);
357 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
358 int crm, boolean draw_masked)
361 struct GraphicInfo_EM *g;
363 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
365 int crumbled_border_size;
366 int left = screen_x / TILEX;
367 int top = screen_y / TILEY;
370 /* do not draw fields that are outside the visible screen area */
371 if (x < left || x >= left + MAX_BUF_XSIZE ||
372 y < top || y >= top + MAX_BUF_YSIZE)
375 if (crm == 0) /* no crumbled edges for this tile */
379 g = getObjectGraphic(x, y);
382 crumbled_border_size = g->crumbled_border_size;
385 crumbled_border_size = crumbled_border_size * TILESIZE_VAR / TILESIZE;
389 if (x == 3 && y == 3 && frame == 0)
390 printf("::: %d, %d\n",
391 graphic_info_em_object[207][0].crumbled_src_x,
392 graphic_info_em_object[207][0].crumbled_src_y);
395 for (i = 0; i < 4; i++)
399 int width, height, cx, cy;
401 if (i == 1 || i == 2)
403 width = crumbled_border_size;
405 cx = (i == 2 ? TILEX - crumbled_border_size : 0);
411 height = crumbled_border_size;
413 cy = (i == 3 ? TILEY - crumbled_border_size : 0);
416 if (width > 0 && height > 0)
418 int src_x = g->crumbled_src_x + cx;
419 int src_y = g->crumbled_src_y + cy;
420 int dst_x = sx * TILEX + cx;
421 int dst_y = sy * TILEY + cy;
425 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
426 dst_x - src_x, dst_y - src_y);
427 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
428 src_x, src_y, width, height, dst_x, dst_y);
431 BlitBitmap(g->crumbled_bitmap, screenBitmap,
432 src_x, src_y, width, height, dst_x, dst_y);
438 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
441 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
442 int src_x = g->src_x, src_y = g->src_y;
445 /* do not draw fields that are outside the visible screen area */
446 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
447 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
450 x1 %= MAX_BUF_XSIZE * TILEX;
451 y1 %= MAX_BUF_YSIZE * TILEY;
455 /* draw the player to current location */
458 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
459 dst_x - src_x, dst_y - src_y);
460 BlitBitmapMasked(g->bitmap, screenBitmap,
461 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
463 /* draw the player to opposite wrap-around column */
464 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
466 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
467 dst_x - src_x, dst_y - src_y);
468 BlitBitmapMasked(g->bitmap, screenBitmap,
469 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
471 /* draw the player to opposite wrap-around row */
473 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
474 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
475 dst_x - src_x, dst_y - src_y);
476 BlitBitmapMasked(g->bitmap, screenBitmap,
477 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
481 /* draw the player to current location */
484 BlitBitmap(g->bitmap, screenBitmap,
485 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
487 /* draw the player to opposite wrap-around column */
488 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
490 BlitBitmap(g->bitmap, screenBitmap,
491 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
493 /* draw the player to opposite wrap-around row */
495 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
496 BlitBitmap(g->bitmap, screenBitmap,
497 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
501 /* draw differences between game tiles and screen tiles
503 * implicitly handles scrolling and restoring background under the sprites
506 static void animscreen(void)
509 int left = screen_x / TILEX;
510 int top = screen_y / TILEY;
511 static int xy[4][2] =
519 if (!game.use_native_emc_graphics_engine)
520 for (y = 2; y < EM_MAX_CAVE_HEIGHT - 2; y++)
521 for (x = 2; x < EM_MAX_CAVE_WIDTH - 2; x++)
522 SetGfxAnimation_EM(&graphic_info_em_object[Draw[y][x]][frame],
523 Draw[y][x], 7 - frame, x - 2, y - 2);
525 for (y = top; y < top + MAX_BUF_YSIZE; y++)
527 for (x = left; x < left + MAX_BUF_XSIZE; x++)
529 int sx = x % MAX_BUF_XSIZE;
530 int sy = y % MAX_BUF_YSIZE;
531 int tile = Draw[y][x];
532 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
533 int obj = g->unique_identifier;
535 boolean redraw_screen_tile = FALSE;
537 /* re-calculate crumbled state of this tile */
538 if (g->has_crumbled_graphics)
540 for (i = 0; i < 4; i++)
542 int xx = x + xy[i][0];
543 int yy = y + xy[i][1];
546 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
547 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
550 tile_next = Draw[yy][xx];
552 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
557 redraw_screen_tile = (screentiles[sy][sx] != obj ||
558 crumbled_state[sy][sx] != crm);
561 /* !!! TEST ONLY -- CHANGE THIS !!! */
562 if (!game.use_native_emc_graphics_engine)
563 redraw_screen_tile = TRUE;
566 /* only redraw screen tiles if they (or their crumbled state) changed */
567 if (redraw_screen_tile)
569 DrawLevelField_EM(x, y, sx, sy, FALSE);
570 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
572 screentiles[sy][sx] = obj;
573 crumbled_state[sy][sx] = crm;
575 redraw[sx][sy] = TRUE;
583 /* blit players to the screen
585 * handles transparency and movement
588 static void blitplayer(struct PLAYER *ply)
595 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
596 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
597 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
602 printf("::: %d, %d\n", x1, y1);
605 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
606 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
608 /* some casts to "int" are needed because of negative calculation values */
609 int dx = (int)ply->x - (int)ply->oldx;
610 int dy = (int)ply->y - (int)ply->oldy;
611 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
612 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
613 int new_x = old_x + SIGN(dx);
614 int new_y = old_y + SIGN(dy);
615 int old_sx = old_x % MAX_BUF_XSIZE;
616 int old_sy = old_y % MAX_BUF_XSIZE;
617 int new_sx = new_x % MAX_BUF_XSIZE;
618 int new_sy = new_y % MAX_BUF_XSIZE;
620 int old_crm = crumbled_state[old_sy][old_sx];
622 int new_crm = crumbled_state[new_sy][new_sx];
624 /* only diggable elements can be crumbled in the classic EM engine */
625 boolean player_is_digging = (new_crm != 0);
628 x1 %= MAX_BUF_XSIZE * TILEX;
629 y1 %= MAX_BUF_YSIZE * TILEY;
630 x2 %= MAX_BUF_XSIZE * TILEX;
631 y2 %= MAX_BUF_YSIZE * TILEY;
634 if (player_is_digging)
637 /* draw the field the player is moving from (under the player) */
638 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
639 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
642 /* draw the field the player is moving to (under the player) */
643 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
644 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
646 /* draw the player (masked) over the element he is just digging away */
647 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
650 /* draw the field the player is moving from (masked over the player) */
651 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
656 /* draw the player under the element which is on the same field */
657 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
659 /* draw the field the player is moving from (masked over the player) */
660 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
662 /* draw the field the player is moving to (masked over the player) */
663 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
666 /* redraw screen tiles in the next frame (player may have left the tiles) */
667 screentiles[old_sy][old_sx] = -1;
668 screentiles[new_sy][new_sx] = -1;
670 /* mark screen tiles as dirty (force screen refresh with changed content) */
671 redraw[old_sx][old_sy] = TRUE;
672 redraw[new_sx][new_sy] = TRUE;
677 void game_initscreen(void)
680 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
681 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
687 game.centered_player_nr = getCenteredPlayerNr_EM();
690 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
692 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
693 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
695 for (y = 0; y < MAX_BUF_YSIZE; y++)
697 for (x = 0; x < MAX_BUF_XSIZE; x++)
699 screentiles[y][x] = -1;
700 crumbled_state[y][x] = 0;
704 DrawAllGameValues(lev.required, dynamite_state, lev.score,
705 lev.time, all_keys_state);
709 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
711 boolean ffwd_delay = (tape.playing && tape.fast_forward);
712 boolean no_delay = (tape.warp_forward);
713 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
714 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
718 if (quick_relocation)
720 int offset = game.scroll_delay_value;
722 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
724 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
725 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
726 player->jx - MIDPOSX);
728 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
729 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
730 player->jy - MIDPOSY);
734 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
735 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
736 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
738 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
739 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
740 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
742 /* don't scroll over playfield boundaries */
743 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
744 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
746 /* don't scroll over playfield boundaries */
747 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
748 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
751 RedrawPlayfield(TRUE, 0,0,0,0);
755 int scroll_xx = -999, scroll_yy = -999;
757 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
759 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
762 int fx = FX, fy = FY;
764 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
765 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
766 player->jx - MIDPOSX);
768 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
769 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
770 player->jy - MIDPOSY);
772 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
773 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
775 if (dx == 0 && dy == 0) /* no scrolling needed at all */
781 fx += dx * TILEX / 2;
782 fy += dy * TILEY / 2;
787 /* scroll in two steps of half tile size to make things smoother */
788 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
790 Delay(wait_delay_value);
792 /* scroll second step to align at full tile size */
794 Delay(wait_delay_value);
799 Delay(wait_delay_value);
804 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
806 int max_dx = 0, max_dy = 0;
807 int player_nr = game_em.last_moving_player;
810 for (i = 0; i < MAX_PLAYERS; i++)
814 int sx = PLAYER_SCREEN_X(i);
815 int sy = PLAYER_SCREEN_Y(i);
817 if (game_em.last_player_direction[i] != MV_NONE &&
818 (ABS(sx - center_x) > max_dx ||
819 ABS(sy - center_y) > max_dy))
821 max_dx = MAX(max_dx, ABS(sx - center_x));
822 max_dy = MAX(max_dy, ABS(sy - center_y));
832 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
834 boolean num_checked_players = 0;
837 for (i = 0; i < MAX_PLAYERS; i++)
841 int sx = PLAYER_SCREEN_X(i);
842 int sy = PLAYER_SCREEN_Y(i);
844 if (num_checked_players == 0)
851 *sx1 = MIN(*sx1, sx);
852 *sy1 = MIN(*sy1, sy);
853 *sx2 = MAX(*sx2, sx);
854 *sy2 = MAX(*sy2, sy);
857 num_checked_players++;
862 boolean checkIfAllPlayersFitToScreen()
864 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
866 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
868 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
869 sy2 - sy1 <= SCR_FIELDY * TILEY);
872 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
874 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
876 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
878 *sx = (sx1 + sx2) / 2;
879 *sy = (sy1 + sy2) / 2;
882 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
883 int center_x, int center_y)
885 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
887 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
889 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
890 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
893 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
897 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
899 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
900 max_dy <= SCR_FIELDY * TILEY / 2);
903 void RedrawPlayfield_EM(boolean force_redraw)
906 boolean all_players_visible = checkIfAllPlayersAreVisible();
908 boolean draw_new_player_location = FALSE;
909 boolean quick_relocation = setup.quick_switch;
911 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
914 boolean game.set_centered_player = getSetCenteredPlayer_EM();
915 int game.centered_player_nr_next = getCenteredPlayerNr_EM();
918 int max_center_distance_player_nr =
919 getMaxCenterDistancePlayerNr(screen_x, screen_y);
921 int player_nr = game_em.last_moving_player;
923 int stepsize = TILEX / 8;
924 int offset = game.scroll_delay_value * TILEX;
925 int offset_x = offset;
926 int offset_y = offset;
927 int screen_x_old = screen_x;
928 int screen_y_old = screen_y;
932 if (game.set_centered_player)
934 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
936 /* switching to "all players" only possible if all players fit to screen */
937 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
939 game.centered_player_nr_next = game.centered_player_nr;
940 game.set_centered_player = FALSE;
943 /* do not switch focus to non-existing (or non-active) player */
944 if (game.centered_player_nr_next >= 0 &&
945 !ply[game.centered_player_nr_next].alive)
947 game.centered_player_nr_next = game.centered_player_nr;
948 game.set_centered_player = FALSE;
953 /* also allow focus switching when screen is scrolled to half tile */
955 if (!scrolling) /* screen currently aligned at tile position */
959 if (game.set_centered_player)
961 if (game.centered_player_nr != game.centered_player_nr_next)
964 game.centered_player_nr = game.centered_player_nr_next;
966 draw_new_player_location = TRUE;
969 game.set_centered_player = FALSE;
973 if (game.centered_player_nr == -1)
976 if (draw_new_player_location || offset == 0)
978 if (draw_new_player_location)
981 setScreenCenteredToAllPlayers(&sx, &sy);
986 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
987 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
989 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
990 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
996 sx = PLAYER_SCREEN_X(game.centered_player_nr);
997 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
1000 if (draw_new_player_location && quick_relocation)
1002 screen_x = VALID_SCREEN_X(sx);
1003 screen_y = VALID_SCREEN_Y(sy);
1004 screen_x_old = screen_x;
1005 screen_y_old = screen_y;
1013 if (draw_new_player_location && !quick_relocation)
1016 unsigned int game_frame_delay_value = getGameFrameDelay_EM(20);
1018 unsigned int game_frame_delay_value = getGameFrameDelay_EM(25);
1020 int wait_delay_value = game_frame_delay_value;
1021 int screen_xx = VALID_SCREEN_X(sx);
1022 int screen_yy = VALID_SCREEN_Y(sy);
1024 while (screen_x != screen_xx || screen_y != screen_yy)
1026 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
1027 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
1028 int dxx = 0, dyy = 0;
1030 if (dx == 0 && dy == 0) /* no scrolling needed at all */
1035 if (ABS(screen_xx - screen_x) >= TILEX)
1037 screen_x -= dx * TILEX;
1038 dxx = dx * TILEX / 2;
1042 screen_x = screen_xx;
1046 if (ABS(screen_yy - screen_y) >= TILEY)
1048 screen_y -= dy * TILEY;
1049 dyy = dy * TILEY / 2;
1053 screen_y = screen_yy;
1060 if (ABS(screen_xx - screen_x) >= TILEX ||
1061 ABS(screen_yy - screen_y) >= TILEY)
1063 screen_x -= dx * TILEX;
1064 screen_y -= dy * TILEY;
1066 dxx = dx * TILEX / 2;
1067 dyy = dy * TILEY / 2;
1071 screen_x = screen_xx;
1072 screen_y = screen_yy;
1078 screen_x -= dx * TILEX;
1079 screen_y -= dy * TILEY;
1081 dxx += dx * TILEX / 2;
1082 dyy += dy * TILEY / 2;
1087 /* scroll in two steps of half tile size to make things smoother */
1093 for (i = 0; i < MAX_PLAYERS; i++)
1094 blitplayer(&ply[i]);
1098 Delay(wait_delay_value);
1100 /* scroll second step to align at full tile size */
1110 for (i = 0; i < MAX_PLAYERS; i++)
1111 blitplayer(&ply[i]);
1115 Delay(wait_delay_value);
1118 screen_x_old = screen_x;
1119 screen_y_old = screen_y;
1124 for (y = 0; y < MAX_BUF_YSIZE; y++)
1126 for (x = 0; x < MAX_BUF_XSIZE; x++)
1128 screentiles[y][x] = -1;
1129 crumbled_state[y][x] = 0;
1134 /* calculate new screen scrolling position, with regard to scroll delay */
1135 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
1136 sx - offset_x > screen_x ? sx - offset_x :
1138 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
1139 sy - offset_y > screen_y ? sy - offset_y :
1143 printf("::: (%d, %d) => (%d, %d) [(%d, %d), (%d, %d)] [%d, %d] [%d / %d]\n",
1144 screen_x_old, screen_y_old,
1146 ply[max_center_distance_player_nr].oldx,
1147 ply[max_center_distance_player_nr].x,
1148 ply[max_center_distance_player_nr].oldy,
1149 ply[max_center_distance_player_nr].y,
1151 ABS(screen_x - screen_x_old),
1152 ABS(screen_y - screen_y_old));
1158 /* prevent scrolling further than double player step size when scrolling */
1159 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
1161 int dx = SIGN(screen_x - screen_x_old);
1163 screen_x = screen_x_old + dx * 2 * stepsize;
1165 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
1167 int dy = SIGN(screen_y - screen_y_old);
1169 screen_y = screen_y_old + dy * 2 * stepsize;
1172 /* prevent scrolling further than double player step size when scrolling */
1173 if (ABS(screen_x - screen_x_old) > 2 * stepsize ||
1174 ABS(screen_y - screen_y_old) > 2 * stepsize)
1176 int dx = SIGN(screen_x - screen_x_old);
1177 int dy = SIGN(screen_y - screen_y_old);
1179 screen_x = screen_x_old + dx * 2 * stepsize;
1180 screen_y = screen_y_old + dy * 2 * stepsize;
1185 /* prevent scrolling further than player step size when scrolling */
1186 if (ABS(screen_x - screen_x_old) > stepsize ||
1187 ABS(screen_y - screen_y_old) > stepsize)
1189 int dx = SIGN(screen_x - screen_x_old);
1190 int dy = SIGN(screen_y - screen_y_old);
1192 screen_x = screen_x_old + dx * stepsize;
1193 screen_y = screen_y_old + dy * stepsize;
1197 /* prevent scrolling away from the other players when focus on all players */
1198 if (game.centered_player_nr == -1)
1201 /* check if all players are still visible with new scrolling position */
1202 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
1203 !checkIfAllPlayersAreVisible(screen_x, screen_y))
1205 /* reset horizontal scroll position to last value, if needed */
1206 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
1207 screen_x = screen_x_old;
1209 /* reset vertical scroll position to last value, if needed */
1210 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
1211 screen_y = screen_y_old;
1214 boolean all_players_visible = checkIfAllPlayersAreVisible();
1216 if (!all_players_visible)
1218 printf("::: not all players visible\n");
1220 screen_x = screen_x_old;
1221 screen_y = screen_y_old;
1226 /* prevent scrolling (for screen correcting) if no player is moving */
1227 if (!game_em.any_player_moving)
1229 screen_x = screen_x_old;
1230 screen_y = screen_y_old;
1234 /* prevent scrolling against the players move direction */
1236 int player_nr = game_em.last_moving_player;
1238 int player_nr = (game.centered_player_nr == -1 ?
1239 max_center_distance_player_nr : game.centered_player_nr);
1240 int player_move_dir = game_em.last_player_direction[player_nr];
1241 int dx = SIGN(screen_x - screen_x_old);
1242 int dy = SIGN(screen_y - screen_y_old);
1244 if ((dx < 0 && player_move_dir != MV_LEFT) ||
1245 (dx > 0 && player_move_dir != MV_RIGHT))
1246 screen_x = screen_x_old;
1248 if ((dy < 0 && player_move_dir != MV_UP) ||
1249 (dy > 0 && player_move_dir != MV_DOWN))
1250 screen_y = screen_y_old;
1255 for (i = 0; i < MAX_PLAYERS; i++)
1256 blitplayer(&ply[i]);
1267 void game_animscreen(void)
1269 RedrawPlayfield_EM(FALSE);
1272 void DrawGameDoorValues_EM()
1278 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1279 int key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1283 if (game.centered_player_nr == -1)
1291 for (i = 0; i < MAX_PLAYERS; i++)
1293 dynamite_state += ply[i].dynamite;
1294 key_state |= ply[i].keys;
1299 dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1300 key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1305 int player_nr = game.centered_player_nr;
1307 dynamite_state = ply[player_nr].dynamite;
1308 key_state = ply[player_nr].keys;
1313 DrawAllGameValues(lev.required, dynamite_state, lev.score,
1314 lev.time, key_state);
1316 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
1317 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);