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
33 int frame; /* current screen frame */
34 int screen_x, screen_y; /* current scroll position */
36 /* tiles currently on screen */
37 static int screentiles[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2];
38 static int crumbled_state[MAX_PLAYFIELD_HEIGHT + 2][MAX_PLAYFIELD_WIDTH + 2];
39 static boolean redraw[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
41 /* copy the entire screen to the window at the scroll position */
43 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
45 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
46 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
47 int sx, sy, sxsize, sysize;
50 int full_xsize = lev.width * TILEX;
51 int full_ysize = lev.height * TILEY;
53 sxsize = (full_xsize < xsize ? full_xsize : xsize);
54 sysize = (full_ysize < ysize ? full_ysize : ysize);
55 sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
56 sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
58 if (x < 2 * TILEX && y < 2 * TILEY)
60 BlitBitmap(screenBitmap, target_bitmap, x, y,
61 sxsize, sysize, sx, sy);
63 else if (x < 2 * TILEX && y >= 2 * TILEY)
65 BlitBitmap(screenBitmap, target_bitmap, x, y,
66 sxsize, MAX_BUF_YSIZE * TILEY - y,
68 BlitBitmap(screenBitmap, target_bitmap, x, 0,
69 sxsize, y - 2 * TILEY,
70 sx, sy + MAX_BUF_YSIZE * TILEY - y);
72 else if (x >= 2 * TILEX && y < 2 * TILEY)
74 BlitBitmap(screenBitmap, target_bitmap, x, y,
75 MAX_BUF_XSIZE * TILEX - x, sysize,
77 BlitBitmap(screenBitmap, target_bitmap, 0, y,
78 x - 2 * TILEX, sysize,
79 sx + MAX_BUF_XSIZE * TILEX - x, sy);
83 BlitBitmap(screenBitmap, target_bitmap, x, y,
84 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
86 BlitBitmap(screenBitmap, target_bitmap, 0, y,
87 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
88 sx + MAX_BUF_XSIZE * TILEX - x, sy);
89 BlitBitmap(screenBitmap, target_bitmap, x, 0,
90 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
91 sx, sy + MAX_BUF_YSIZE * TILEY - y);
92 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
93 x - 2 * TILEX, y - 2 * TILEY,
94 sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y);
98 void BackToFront_EM(void)
100 static int screen_x_last = -1, screen_y_last = -1;
101 static boolean scrolling_last = FALSE;
102 int left = screen_x / TILEX;
103 int top = screen_y / TILEY;
104 boolean scrolling = (screen_x != screen_x_last || screen_y != screen_y_last);
109 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
111 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
112 BlitScreenToBitmap_EM(backbuffer);
114 /* blit the completely updated backbuffer to the window (in one blit) */
115 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
119 boolean half_shifted_x = (screen_x % TILEX != 0);
120 boolean half_shifted_y = (screen_y % TILEY != 0);
125 int full_xsize = lev.width * TILEX;
126 int full_ysize = lev.height * TILEY;
128 sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
129 sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
131 int x1 = 0, x2 = SCR_FIELDX - (half_shifted_x ? 0 : 1);
132 int y1 = 0, y2 = SCR_FIELDY - (half_shifted_y ? 0 : 1);
133 int scroll_xoffset = (half_shifted_x ? TILEX / 2 : 0);
134 int scroll_yoffset = (half_shifted_y ? TILEY / 2 : 0);
136 InitGfxClipRegion(TRUE, SX, SY, SXSIZE, SYSIZE);
138 for (x = x1; x <= x2; x++)
140 for (y = y1; y <= y2; y++)
142 int xx = (left + x) % MAX_BUF_XSIZE;
143 int yy = (top + y) % MAX_BUF_YSIZE;
146 BlitBitmap(screenBitmap, window,
147 xx * TILEX, yy * TILEY, TILEX, TILEY,
148 sx + x * TILEX - scroll_xoffset,
149 sy + y * TILEY - scroll_yoffset);
153 InitGfxClipRegion(FALSE, -1, -1, -1, -1);
158 for (x = 0; x < MAX_BUF_XSIZE; x++)
159 for (y = 0; y < MAX_BUF_YSIZE; y++)
160 redraw[x][y] = FALSE;
163 screen_x_last = screen_x;
164 screen_y_last = screen_y;
165 scrolling_last = scrolling;
168 void blitscreen(void)
173 static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
175 int tile = Draw[y][x];
176 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
178 if (!game.use_native_emc_graphics_engine)
179 getGraphicSourceObjectExt_EM(g, tile, 7 - frame, x - 2, y - 2);
184 static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
186 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
188 if (!game.use_native_emc_graphics_engine)
189 getGraphicSourcePlayerExt_EM(g, player_nr, anim, 7 - frame);
194 static void DrawLevelField_EM(int x, int y, int sx, int sy,
197 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
198 int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE;
199 int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE;
200 int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE;
201 int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE;
202 int width = g->width * TILESIZE_VAR / TILESIZE;
203 int height = g->height * TILESIZE_VAR / TILESIZE;
204 int left = screen_x / TILEX;
205 int top = screen_y / TILEY;
207 /* do not draw fields that are outside the visible screen area */
208 if (x < left || x >= left + MAX_BUF_XSIZE ||
209 y < top || y >= top + MAX_BUF_YSIZE)
214 if (width > 0 && height > 0)
216 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
217 dst_x - src_x, dst_y - src_y);
218 BlitBitmapMasked(g->bitmap, screenBitmap,
219 src_x, src_y, width, height, dst_x, dst_y);
224 if ((width != TILEX || height != TILEY) && !g->preserve_background)
225 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
227 if (width > 0 && height > 0)
228 BlitBitmap(g->bitmap, screenBitmap,
229 src_x, src_y, width, height, dst_x, dst_y);
233 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
234 int crm, boolean draw_masked)
236 struct GraphicInfo_EM *g;
237 int crumbled_border_size;
238 int left = screen_x / TILEX;
239 int top = screen_y / TILEY;
242 /* do not draw fields that are outside the visible screen area */
243 if (x < left || x >= left + MAX_BUF_XSIZE ||
244 y < top || y >= top + MAX_BUF_YSIZE)
247 if (crm == 0) /* no crumbled edges for this tile */
250 g = getObjectGraphic(x, y);
252 crumbled_border_size = g->crumbled_border_size * TILESIZE_VAR / TILESIZE;
254 for (i = 0; i < 4; i++)
258 int width, height, cx, cy;
260 if (i == 1 || i == 2)
262 width = crumbled_border_size;
264 cx = (i == 2 ? TILEX - crumbled_border_size : 0);
270 height = crumbled_border_size;
272 cy = (i == 3 ? TILEY - crumbled_border_size : 0);
275 if (width > 0 && height > 0)
277 int src_x = g->crumbled_src_x + cx;
278 int src_y = g->crumbled_src_y + cy;
279 int dst_x = sx * TILEX + cx;
280 int dst_y = sy * TILEY + cy;
284 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
285 dst_x - src_x, dst_y - src_y);
286 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
287 src_x, src_y, width, height, dst_x, dst_y);
290 BlitBitmap(g->crumbled_bitmap, screenBitmap,
291 src_x, src_y, width, height, dst_x, dst_y);
297 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
300 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
301 int src_x = g->src_x, src_y = g->src_y;
304 /* do not draw fields that are outside the visible screen area */
305 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
306 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
309 x1 %= MAX_BUF_XSIZE * TILEX;
310 y1 %= MAX_BUF_YSIZE * TILEY;
314 /* draw the player to current location */
317 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
318 dst_x - src_x, dst_y - src_y);
319 BlitBitmapMasked(g->bitmap, screenBitmap,
320 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
322 /* draw the player to opposite wrap-around column */
323 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
325 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
326 dst_x - src_x, dst_y - src_y);
327 BlitBitmapMasked(g->bitmap, screenBitmap,
328 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
330 /* draw the player to opposite wrap-around row */
332 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
333 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
334 dst_x - src_x, dst_y - src_y);
335 BlitBitmapMasked(g->bitmap, screenBitmap,
336 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
340 /* draw the player to current location */
343 BlitBitmap(g->bitmap, screenBitmap,
344 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
346 /* draw the player to opposite wrap-around column */
347 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
349 BlitBitmap(g->bitmap, screenBitmap,
350 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
352 /* draw the player to opposite wrap-around row */
354 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
355 BlitBitmap(g->bitmap, screenBitmap,
356 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
360 /* draw differences between game tiles and screen tiles
362 * implicitly handles scrolling and restoring background under the sprites
365 static void animscreen(void)
368 int left = screen_x / TILEX;
369 int top = screen_y / TILEY;
370 static int xy[4][2] =
378 if (!game.use_native_emc_graphics_engine)
379 for (y = 2; y < EM_MAX_CAVE_HEIGHT - 2; y++)
380 for (x = 2; x < EM_MAX_CAVE_WIDTH - 2; x++)
381 SetGfxAnimation_EM(&graphic_info_em_object[Draw[y][x]][frame],
382 Draw[y][x], 7 - frame, x - 2, y - 2);
384 for (y = top; y < top + MAX_BUF_YSIZE; y++)
386 for (x = left; x < left + MAX_BUF_XSIZE; x++)
388 int sx = x % MAX_BUF_XSIZE;
389 int sy = y % MAX_BUF_YSIZE;
390 int tile = Draw[y][x];
391 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
392 int obj = g->unique_identifier;
394 boolean redraw_screen_tile = FALSE;
396 /* re-calculate crumbled state of this tile */
397 if (g->has_crumbled_graphics)
399 for (i = 0; i < 4; i++)
401 int xx = x + xy[i][0];
402 int yy = y + xy[i][1];
405 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
406 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
409 tile_next = Draw[yy][xx];
411 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
416 redraw_screen_tile = (screentiles[sy][sx] != obj ||
417 crumbled_state[sy][sx] != crm);
419 /* only redraw screen tiles if they (or their crumbled state) changed */
420 if (redraw_screen_tile)
422 DrawLevelField_EM(x, y, sx, sy, FALSE);
423 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
425 screentiles[sy][sx] = obj;
426 crumbled_state[sy][sx] = crm;
428 redraw[sx][sy] = TRUE;
436 /* blit players to the screen
438 * handles transparency and movement
441 static void blitplayer(struct PLAYER *ply)
448 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
449 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
450 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
454 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
455 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
457 /* some casts to "int" are needed because of negative calculation values */
458 int dx = (int)ply->x - (int)ply->oldx;
459 int dy = (int)ply->y - (int)ply->oldy;
460 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
461 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
462 int new_x = old_x + SIGN(dx);
463 int new_y = old_y + SIGN(dy);
464 int old_sx = old_x % MAX_BUF_XSIZE;
465 int old_sy = old_y % MAX_BUF_YSIZE;
466 int new_sx = new_x % MAX_BUF_XSIZE;
467 int new_sy = new_y % MAX_BUF_YSIZE;
468 int new_crm = crumbled_state[new_sy][new_sx];
470 /* only diggable elements can be crumbled in the classic EM engine */
471 boolean player_is_digging = (new_crm != 0);
473 if (player_is_digging)
475 /* draw the field the player is moving to (under the player) */
476 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
477 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
479 /* draw the player (masked) over the element he is just digging away */
480 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
482 /* draw the field the player is moving from (masked over the player) */
483 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
487 /* draw the player under the element which is on the same field */
488 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
490 /* draw the field the player is moving from (masked over the player) */
491 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
493 /* draw the field the player is moving to (masked over the player) */
494 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
497 /* redraw screen tiles in the next frame (player may have left the tiles) */
498 screentiles[old_sy][old_sx] = -1;
499 screentiles[new_sy][new_sx] = -1;
501 /* mark screen tiles as dirty (force screen refresh with changed content) */
502 redraw[old_sx][old_sy] = TRUE;
503 redraw[new_sx][new_sy] = TRUE;
508 void game_initscreen(void)
515 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
517 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
518 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
520 for (y = 0; y < MAX_BUF_YSIZE; y++)
522 for (x = 0; x < MAX_BUF_XSIZE; x++)
524 screentiles[y][x] = -1;
525 crumbled_state[y][x] = 0;
530 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
532 int max_dx = 0, max_dy = 0;
533 int player_nr = game_em.last_moving_player;
536 for (i = 0; i < MAX_PLAYERS; i++)
540 int sx = PLAYER_SCREEN_X(i);
541 int sy = PLAYER_SCREEN_Y(i);
543 if (game_em.last_player_direction[i] != MV_NONE &&
544 (ABS(sx - center_x) > max_dx ||
545 ABS(sy - center_y) > max_dy))
547 max_dx = MAX(max_dx, ABS(sx - center_x));
548 max_dy = MAX(max_dy, ABS(sy - center_y));
558 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
560 boolean num_checked_players = 0;
563 for (i = 0; i < MAX_PLAYERS; i++)
567 int sx = PLAYER_SCREEN_X(i);
568 int sy = PLAYER_SCREEN_Y(i);
570 if (num_checked_players == 0)
577 *sx1 = MIN(*sx1, sx);
578 *sy1 = MIN(*sy1, sy);
579 *sx2 = MAX(*sx2, sx);
580 *sy2 = MAX(*sy2, sy);
583 num_checked_players++;
588 boolean checkIfAllPlayersFitToScreen()
590 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
592 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
594 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
595 sy2 - sy1 <= SCR_FIELDY * TILEY);
598 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
600 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
602 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
604 *sx = (sx1 + sx2) / 2;
605 *sy = (sy1 + sy2) / 2;
608 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
609 int center_x, int center_y)
611 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
613 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
615 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
616 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
619 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
623 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
625 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
626 max_dy <= SCR_FIELDY * TILEY / 2);
629 void RedrawPlayfield_EM(boolean force_redraw)
631 boolean draw_new_player_location = FALSE;
632 boolean quick_relocation = setup.quick_switch;
633 int max_center_distance_player_nr =
634 getMaxCenterDistancePlayerNr(screen_x, screen_y);
635 int stepsize = TILEX / 8;
636 int offset = game.scroll_delay_value * TILEX;
637 int offset_x = offset;
638 int offset_y = offset;
639 int screen_x_old = screen_x;
640 int screen_y_old = screen_y;
644 if (game.set_centered_player)
646 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
648 /* switching to "all players" only possible if all players fit to screen */
649 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
651 game.centered_player_nr_next = game.centered_player_nr;
652 game.set_centered_player = FALSE;
655 /* do not switch focus to non-existing (or non-active) player */
656 if (game.centered_player_nr_next >= 0 &&
657 !ply[game.centered_player_nr_next].alive)
659 game.centered_player_nr_next = game.centered_player_nr;
660 game.set_centered_player = FALSE;
664 /* also allow focus switching when screen is scrolled to half tile */
665 if (game.set_centered_player)
667 game.centered_player_nr = game.centered_player_nr_next;
669 draw_new_player_location = TRUE;
672 game.set_centered_player = FALSE;
675 if (game.centered_player_nr == -1)
677 if (draw_new_player_location || offset == 0)
679 setScreenCenteredToAllPlayers(&sx, &sy);
683 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
684 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
689 sx = PLAYER_SCREEN_X(game.centered_player_nr);
690 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
693 if (draw_new_player_location && quick_relocation)
695 screen_x = VALID_SCREEN_X(sx);
696 screen_y = VALID_SCREEN_Y(sy);
697 screen_x_old = screen_x;
698 screen_y_old = screen_y;
701 if (draw_new_player_location && !quick_relocation)
703 unsigned int game_frame_delay_value = getGameFrameDelay_EM(20);
704 int wait_delay_value = game_frame_delay_value;
705 int screen_xx = VALID_SCREEN_X(sx);
706 int screen_yy = VALID_SCREEN_Y(sy);
708 while (screen_x != screen_xx || screen_y != screen_yy)
710 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
711 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
712 int dxx = 0, dyy = 0;
714 if (dx == 0 && dy == 0) /* no scrolling needed at all */
717 if (ABS(screen_xx - screen_x) >= TILEX)
719 screen_x -= dx * TILEX;
720 dxx = dx * TILEX / 2;
724 screen_x = screen_xx;
728 if (ABS(screen_yy - screen_y) >= TILEY)
730 screen_y -= dy * TILEY;
731 dyy = dy * TILEY / 2;
735 screen_y = screen_yy;
739 /* scroll in two steps of half tile size to make things smoother */
745 for (i = 0; i < MAX_PLAYERS; i++)
750 Delay(wait_delay_value);
752 /* scroll second step to align at full tile size */
758 for (i = 0; i < MAX_PLAYERS; i++)
763 Delay(wait_delay_value);
766 screen_x_old = screen_x;
767 screen_y_old = screen_y;
772 for (y = 0; y < MAX_BUF_YSIZE; y++)
774 for (x = 0; x < MAX_BUF_XSIZE; x++)
776 screentiles[y][x] = -1;
777 crumbled_state[y][x] = 0;
782 /* calculate new screen scrolling position, with regard to scroll delay */
783 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
784 sx - offset_x > screen_x ? sx - offset_x :
786 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
787 sy - offset_y > screen_y ? sy - offset_y :
790 /* prevent scrolling further than double player step size when scrolling */
791 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
793 int dx = SIGN(screen_x - screen_x_old);
795 screen_x = screen_x_old + dx * 2 * stepsize;
797 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
799 int dy = SIGN(screen_y - screen_y_old);
801 screen_y = screen_y_old + dy * 2 * stepsize;
804 /* prevent scrolling away from the other players when focus on all players */
805 if (game.centered_player_nr == -1)
807 /* check if all players are still visible with new scrolling position */
808 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
809 !checkIfAllPlayersAreVisible(screen_x, screen_y))
811 /* reset horizontal scroll position to last value, if needed */
812 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
813 screen_x = screen_x_old;
815 /* reset vertical scroll position to last value, if needed */
816 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
817 screen_y = screen_y_old;
821 /* prevent scrolling (for screen correcting) if no player is moving */
822 if (!game_em.any_player_moving)
824 screen_x = screen_x_old;
825 screen_y = screen_y_old;
829 /* prevent scrolling against the players move direction */
830 int player_nr = (game.centered_player_nr == -1 ?
831 max_center_distance_player_nr : game.centered_player_nr);
832 int player_move_dir = game_em.last_player_direction[player_nr];
833 int dx = SIGN(screen_x - screen_x_old);
834 int dy = SIGN(screen_y - screen_y_old);
836 if ((dx < 0 && player_move_dir != MV_LEFT) ||
837 (dx > 0 && player_move_dir != MV_RIGHT))
838 screen_x = screen_x_old;
840 if ((dy < 0 && player_move_dir != MV_UP) ||
841 (dy > 0 && player_move_dir != MV_DOWN))
842 screen_y = screen_y_old;
847 for (i = 0; i < MAX_PLAYERS; i++)
851 void game_animscreen(void)
853 RedrawPlayfield_EM(FALSE);
856 void DrawGameDoorValues_EM()