1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
8 #define MIN_SCREEN_XPOS_RAW 0
9 #define MIN_SCREEN_YPOS_RAW 0
10 #define MAX_SCREEN_XPOS_RAW MAX(0, lev.width - SCR_FIELDX)
11 #define MAX_SCREEN_YPOS_RAW MAX(0, lev.height - SCR_FIELDY)
13 #define MIN_SCREEN_XPOS (MIN_SCREEN_XPOS_RAW + CAVE_BUFFER_XOFFSET)
14 #define MIN_SCREEN_YPOS (MIN_SCREEN_YPOS_RAW + CAVE_BUFFER_YOFFSET)
15 #define MAX_SCREEN_XPOS (MAX_SCREEN_XPOS_RAW + CAVE_BUFFER_XOFFSET)
16 #define MAX_SCREEN_YPOS (MAX_SCREEN_YPOS_RAW + CAVE_BUFFER_YOFFSET)
18 #define MIN_SCREEN_X (MIN_SCREEN_XPOS * TILEX)
19 #define MIN_SCREEN_Y (MIN_SCREEN_YPOS * TILEY)
20 #define MAX_SCREEN_X (MAX_SCREEN_XPOS * TILEX)
21 #define MAX_SCREEN_Y (MAX_SCREEN_YPOS * TILEY)
23 #define VALID_SCREEN_X(x) ((x) < MIN_SCREEN_X ? MIN_SCREEN_X : \
24 (x) > MAX_SCREEN_X ? MAX_SCREEN_X : (x))
25 #define VALID_SCREEN_Y(y) ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y : \
26 (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
28 #define PLAYER_POS_X(nr) (((7 - frame) * ply[nr].prev_x + \
29 (1 + frame) * ply[nr].x) * TILEX / 8)
30 #define PLAYER_POS_Y(nr) (((7 - frame) * ply[nr].prev_y + \
31 (1 + frame) * ply[nr].y) * TILEY / 8)
33 #define PLAYER_SCREEN_X(nr) (PLAYER_POS_X(nr) - \
34 (SCR_FIELDX - 1) * TILEX / 2)
35 #define PLAYER_SCREEN_Y(nr) (PLAYER_POS_Y(nr) - \
36 (SCR_FIELDY - 1) * TILEY / 2)
38 #define USE_EXTENDED_GRAPHICS_ENGINE 1
41 int frame; /* current screen frame */
42 int screen_x, screen_y; /* current scroll position */
44 /* tiles currently on screen */
45 static int screen_tiles[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
46 static int crumbled_state[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2];
48 /* graphic info for game objects/frames and players/actions/frames */
49 struct GraphicInfo_EM graphic_info_em_object[GAME_TILE_MAX][8];
50 struct GraphicInfo_EM graphic_info_em_player[MAX_PLAYERS][PLY_MAX][8];
52 static void setScreenCenteredToAllPlayers(int *, int *);
54 int getFieldbufferOffsetX_EM(void)
56 return screen_x % TILEX;
59 int getFieldbufferOffsetY_EM(void)
61 return screen_y % TILEY;
64 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
66 /* blit all (up to four) parts of the scroll buffer to the target bitmap */
68 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
69 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
72 int full_xsize = lev.width * TILEX;
73 int full_ysize = lev.height * TILEY;
74 int sx = SX + (full_xsize < xsize ? (xsize - full_xsize) / 2 : 0);
75 int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0);
76 int sxsize = (full_xsize < xsize ? full_xsize : xsize);
77 int sysize = (full_ysize < ysize ? full_ysize : ysize);
78 int xxsize = MAX_BUF_XSIZE * TILEX - x;
79 int yysize = MAX_BUF_YSIZE * TILEY - y;
80 int xoffset = 2 * CAVE_BUFFER_XOFFSET * TILEX;
81 int yoffset = 2 * CAVE_BUFFER_YOFFSET * TILEY;
83 if (x < xoffset && y < yoffset)
85 BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, sysize,
88 else if (x < xoffset && y >= yoffset)
90 BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, yysize,
92 BlitBitmap(screenBitmap, target_bitmap, x, 0, sxsize, y - yoffset,
95 else if (x >= xoffset && y < yoffset)
97 BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, sysize,
99 BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, sysize,
104 BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, yysize,
106 BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, yysize,
108 BlitBitmap(screenBitmap, target_bitmap, x, 0, xxsize, y - yoffset,
110 BlitBitmap(screenBitmap, target_bitmap, 0, 0, x - xoffset, y - yoffset,
111 sx + xxsize, sy + yysize);
115 static void BackToFront_EM(void)
117 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
120 static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
122 int tile = lev.draw[x][y];
123 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
125 if (!game.use_native_emc_graphics_engine)
126 getGraphicSourceObjectExt_EM(g, tile, frame, x - lev.left, y - lev.top);
131 static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
133 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
135 if (!game.use_native_emc_graphics_engine)
136 getGraphicSourcePlayerExt_EM(g, player_nr, anim, frame);
141 static void DrawLevelField_EM(int x, int y, int sx, int sy,
144 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
145 int src_x = g->src_x + g->src_offset_x * TILESIZE_VAR / TILESIZE;
146 int src_y = g->src_y + g->src_offset_y * TILESIZE_VAR / TILESIZE;
147 int dst_x = sx * TILEX + g->dst_offset_x * TILESIZE_VAR / TILESIZE;
148 int dst_y = sy * TILEY + g->dst_offset_y * TILESIZE_VAR / TILESIZE;
149 int width = g->width * TILESIZE_VAR / TILESIZE;
150 int height = g->height * TILESIZE_VAR / TILESIZE;
151 int left = screen_x / TILEX;
152 int top = screen_y / TILEY;
154 /* do not draw fields that are outside the visible screen area */
155 if (x < left || x >= left + MAX_BUF_XSIZE ||
156 y < top || y >= top + MAX_BUF_YSIZE)
161 if (width > 0 && height > 0)
162 BlitBitmapMasked(g->bitmap, screenBitmap,
163 src_x, src_y, width, height, dst_x, dst_y);
167 if ((width != TILEX || height != TILEY) && !g->preserve_background)
168 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
170 if (width > 0 && height > 0)
171 BlitBitmap(g->bitmap, screenBitmap,
172 src_x, src_y, width, height, dst_x, dst_y);
176 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
177 int crm, boolean draw_masked)
179 struct GraphicInfo_EM *g;
180 int crumbled_border_size;
181 int left = screen_x / TILEX;
182 int top = screen_y / TILEY;
185 /* do not draw fields that are outside the visible screen area */
186 if (x < left || x >= left + MAX_BUF_XSIZE ||
187 y < top || y >= top + MAX_BUF_YSIZE)
190 if (crm == 0) /* no crumbled edges for this tile */
193 g = getObjectGraphic(x, y);
195 crumbled_border_size =
196 g->crumbled_border_size * TILESIZE_VAR / g->crumbled_tile_size;
198 for (i = 0; i < 4; i++)
202 int width, height, cx, cy;
204 if (i == 1 || i == 2)
206 width = crumbled_border_size;
208 cx = (i == 2 ? TILEX - crumbled_border_size : 0);
214 height = crumbled_border_size;
216 cy = (i == 3 ? TILEY - crumbled_border_size : 0);
219 if (width > 0 && height > 0)
221 int src_x = g->crumbled_src_x + cx;
222 int src_y = g->crumbled_src_y + cy;
223 int dst_x = sx * TILEX + cx;
224 int dst_y = sy * TILEY + cy;
227 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
228 src_x, src_y, width, height, dst_x, dst_y);
230 BlitBitmap(g->crumbled_bitmap, screenBitmap,
231 src_x, src_y, width, height, dst_x, dst_y);
237 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
240 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
241 int src_x = g->src_x, src_y = g->src_y;
244 /* do not draw fields that are outside the visible screen area */
245 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
246 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
249 x1 %= MAX_BUF_XSIZE * TILEX;
250 y1 %= MAX_BUF_YSIZE * TILEY;
254 /* draw the player to current location */
257 BlitBitmapMasked(g->bitmap, screenBitmap,
258 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
260 /* draw the player to opposite wrap-around column */
261 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
263 BlitBitmapMasked(g->bitmap, screenBitmap,
264 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
266 /* draw the player to opposite wrap-around row */
268 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
269 BlitBitmapMasked(g->bitmap, screenBitmap,
270 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
274 /* draw the player to current location */
277 BlitBitmap(g->bitmap, screenBitmap,
278 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
280 /* draw the player to opposite wrap-around column */
281 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
283 BlitBitmap(g->bitmap, screenBitmap,
284 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
286 /* draw the player to opposite wrap-around row */
288 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
289 BlitBitmap(g->bitmap, screenBitmap,
290 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
294 /* draw differences between game tiles and screen tiles
296 * implicitly handles scrolling and restoring background under the sprites
299 static void animscreen(void)
302 int left = screen_x / TILEX;
303 int top = screen_y / TILEY;
304 static int xy[4][2] =
312 if (!game.use_native_emc_graphics_engine)
313 for (y = lev.top; y < lev.bottom; y++)
314 for (x = lev.left; x < lev.right; x++)
315 SetGfxAnimation_EM(&graphic_info_em_object[lev.draw[x][y]][frame],
316 lev.draw[x][y], frame,
317 x - lev.left, y - lev.top);
319 for (y = top; y < top + MAX_BUF_YSIZE; y++)
321 for (x = left; x < left + MAX_BUF_XSIZE; x++)
323 int sx = x % MAX_BUF_XSIZE;
324 int sy = y % MAX_BUF_YSIZE;
325 int tile = lev.draw[x][y];
326 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
327 int obj = g->unique_identifier;
329 boolean redraw_screen_tile = FALSE;
331 /* re-calculate crumbled state of this tile */
332 if (g->has_crumbled_graphics)
334 for (i = 0; i < 4; i++)
336 int xx = x + xy[i][0];
337 int yy = y + xy[i][1];
340 if (xx < 0 || xx >= CAVE_BUFFER_WIDTH ||
341 yy < 0 || yy >= CAVE_BUFFER_HEIGHT)
344 tile_next = lev.draw[xx][yy];
346 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
351 redraw_screen_tile = (screen_tiles[sx][sy] != obj ||
352 crumbled_state[sx][sy] != crm);
354 /* only redraw screen tiles if they (or their crumbled state) changed */
355 if (redraw_screen_tile)
357 DrawLevelField_EM(x, y, sx, sy, FALSE);
358 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
360 screen_tiles[sx][sy] = obj;
361 crumbled_state[sx][sy] = crm;
368 /* blit players to the screen
370 * handles transparency and movement
373 static void blitplayer_ext(int nr)
380 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
381 x1 = PLAYER_POS_X(nr);
382 y1 = PLAYER_POS_Y(nr);
386 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
387 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
389 /* some casts to "int" are needed because of negative calculation values */
390 int dx = (int)ply[nr].x - (int)ply[nr].prev_x;
391 int dy = (int)ply[nr].y - (int)ply[nr].prev_y;
392 int old_x = (int)ply[nr].prev_x + (int)frame * dx / 8;
393 int old_y = (int)ply[nr].prev_y + (int)frame * dy / 8;
394 int new_x = old_x + SIGN(dx);
395 int new_y = old_y + SIGN(dy);
396 int old_sx = old_x % MAX_BUF_XSIZE;
397 int old_sy = old_y % MAX_BUF_YSIZE;
398 int new_sx = new_x % MAX_BUF_XSIZE;
399 int new_sy = new_y % MAX_BUF_YSIZE;
400 int new_crm = crumbled_state[new_sx][new_sy];
402 /* only diggable elements can be crumbled in the classic EM engine */
403 boolean player_is_digging = (new_crm != 0);
405 if (player_is_digging)
407 /* draw the field the player is moving to (under the player) */
408 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
409 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
411 /* draw the player (masked) over the element he is just digging away */
412 DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, TRUE);
414 /* draw the field the player is moving from (masked over the player) */
415 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
419 /* draw the player under the element which is on the same field */
420 DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, FALSE);
422 /* draw the field the player is moving from (masked over the player) */
423 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
425 /* draw the field the player is moving to (masked over the player) */
426 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
429 /* redraw screen tiles in the next frame (player may have left the tiles) */
430 screen_tiles[old_sx][old_sy] = -1;
431 screen_tiles[new_sx][new_sy] = -1;
435 static void blitplayer(int nr)
439 /* check for wrap-around movement ... */
440 if (ply[nr].x < lev.left ||
441 ply[nr].x > lev.right - 1)
443 struct PLAYER ply_last = ply[nr];
444 int direction = (ply[nr].x < lev.left ? -1 : 1);
445 int dx = ply[nr].x - ply[nr].prev_x;
447 ply[nr].x += -direction * lev.width;
448 ply[nr].prev_x = ply[nr].x - dx;
450 if (!lev.infinite_true)
452 int dy = ply[nr].y - ply[nr].prev_y;
454 ply[nr].y += direction;
455 ply[nr].prev_y = ply[nr].y - dy;
458 /* draw player entering playfield from the opposite side */
461 /* ... but keep the old player position until game logic */
466 void game_initscreen(void)
472 if (game.centered_player_nr == -1)
474 setScreenCenteredToAllPlayers(&sx, &sy);
478 sx = PLAYER_SCREEN_X(game.centered_player_nr);
479 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
482 screen_x = VALID_SCREEN_X(sx);
483 screen_y = VALID_SCREEN_Y(sy);
485 for (y = 0; y < MAX_BUF_YSIZE; y++)
487 for (x = 0; x < MAX_BUF_XSIZE; x++)
489 screen_tiles[x][y] = -1;
490 crumbled_state[x][y] = 0;
495 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
497 int max_dx = 0, max_dy = 0;
498 int player_nr = game_em.last_moving_player;
501 for (i = 0; i < MAX_PLAYERS; i++)
505 int sx = PLAYER_SCREEN_X(i);
506 int sy = PLAYER_SCREEN_Y(i);
508 if (game_em.last_player_direction[i] != MV_NONE &&
509 (ABS(sx - center_x) > max_dx ||
510 ABS(sy - center_y) > max_dy))
512 max_dx = MAX(max_dx, ABS(sx - center_x));
513 max_dy = MAX(max_dy, ABS(sy - center_y));
523 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
525 boolean num_checked_players = 0;
528 for (i = 0; i < MAX_PLAYERS; i++)
532 int sx = PLAYER_SCREEN_X(i);
533 int sy = PLAYER_SCREEN_Y(i);
535 if (num_checked_players == 0)
542 *sx1 = MIN(*sx1, sx);
543 *sy1 = MIN(*sy1, sy);
544 *sx2 = MAX(*sx2, sx);
545 *sy2 = MAX(*sy2, sy);
548 num_checked_players++;
553 boolean checkIfAllPlayersFitToScreen(void)
555 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
556 int scr_fieldx = getScreenFieldSizeX();
557 int scr_fieldy = getScreenFieldSizeY();
559 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
561 return (sx2 - sx1 <= scr_fieldx * TILEX &&
562 sy2 - sy1 <= scr_fieldy * TILEY);
565 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
567 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
569 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
571 *sx = (sx1 + sx2) / 2;
572 *sy = (sy1 + sy2) / 2;
575 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
576 int center_x, int center_y)
578 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
580 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
582 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
583 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
586 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
590 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
592 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
593 max_dy <= SCR_FIELDY * TILEY / 2);
596 void RedrawPlayfield_EM(boolean force_redraw)
598 boolean draw_new_player_location = FALSE;
599 boolean draw_new_player_location_wrap = FALSE;
600 boolean quick_relocation = setup.quick_switch;
601 int max_center_distance_player_nr =
602 getMaxCenterDistancePlayerNr(screen_x, screen_y);
603 int stepsize = TILEX / 8;
604 int offset_raw = game.scroll_delay_value;
605 int offset_x = MIN(offset_raw, (SCR_FIELDX - 2) / 2) * TILEX;
606 int offset_y = MIN(offset_raw, (SCR_FIELDY - 2) / 2) * TILEY;
607 int screen_x_old = screen_x;
608 int screen_y_old = screen_y;
612 if (game.set_centered_player)
614 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
616 /* switching to "all players" only possible if all players fit to screen */
617 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
619 game.centered_player_nr_next = game.centered_player_nr;
620 game.set_centered_player = FALSE;
623 /* do not switch focus to non-existing (or non-active) player */
624 if (game.centered_player_nr_next >= 0 &&
625 !ply[game.centered_player_nr_next].alive)
627 game.centered_player_nr_next = game.centered_player_nr;
628 game.set_centered_player = FALSE;
632 /* also allow focus switching when screen is scrolled to half tile */
633 if (game.set_centered_player)
635 game.centered_player_nr = game.centered_player_nr_next;
637 draw_new_player_location = TRUE;
638 draw_new_player_location_wrap = game.set_centered_player_wrap;
641 game.set_centered_player = FALSE;
642 game.set_centered_player_wrap = FALSE;
645 if (game.centered_player_nr == -1)
647 if (draw_new_player_location || offset_raw == 0)
649 setScreenCenteredToAllPlayers(&sx, &sy);
653 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
654 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
659 sx = PLAYER_SCREEN_X(game.centered_player_nr);
660 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
663 if (draw_new_player_location && quick_relocation)
665 screen_x = VALID_SCREEN_X(sx);
666 screen_y = VALID_SCREEN_Y(sy);
667 screen_x_old = screen_x;
668 screen_y_old = screen_y;
671 if (draw_new_player_location && !quick_relocation)
673 unsigned int frame_delay_value_old = GetVideoFrameDelay();
674 int wait_delay_value = frame_delay_value_old;
675 int screen_xx = VALID_SCREEN_X(sx);
676 int screen_yy = VALID_SCREEN_Y(sy);
678 if (draw_new_player_location_wrap)
680 if (lev.infinite_true)
682 // when wrapping around (horizontally), keep vertical player position
683 screen_yy = screen_y;
686 // scrolling for wrapping should be faster than for switching players
687 wait_delay_value /= 4;
690 SetVideoFrameDelay(wait_delay_value);
692 while (screen_x != screen_xx || screen_y != screen_yy)
694 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
695 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
696 int dxx = 0, dyy = 0;
698 if (dx == 0 && dy == 0) /* no scrolling needed at all */
701 if (ABS(screen_xx - screen_x) >= TILEX)
703 screen_x -= dx * TILEX;
704 dxx = dx * TILEX / 2;
708 screen_x = screen_xx;
712 if (ABS(screen_yy - screen_y) >= TILEY)
714 screen_y -= dy * TILEY;
715 dyy = dy * TILEY / 2;
719 screen_y = screen_yy;
723 /* scroll in two steps of half tile size to make things smoother */
729 for (i = 0; i < MAX_PLAYERS; i++)
732 BlitScreenToBitmap_EM(backbuffer);
735 /* scroll second step to align at full tile size */
741 for (i = 0; i < MAX_PLAYERS; i++)
744 BlitScreenToBitmap_EM(backbuffer);
748 SetVideoFrameDelay(frame_delay_value_old);
750 screen_x_old = screen_x;
751 screen_y_old = screen_y;
756 for (y = 0; y < MAX_BUF_YSIZE; y++)
758 for (x = 0; x < MAX_BUF_XSIZE; x++)
760 screen_tiles[x][y] = -1;
761 crumbled_state[x][y] = 0;
766 /* calculate new screen scrolling position, with regard to scroll delay */
767 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
768 sx - offset_x > screen_x ? sx - offset_x :
770 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
771 sy - offset_y > screen_y ? sy - offset_y :
774 /* prevent scrolling further than double player step size when scrolling */
775 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
777 int dx = SIGN(screen_x - screen_x_old);
779 screen_x = screen_x_old + dx * 2 * stepsize;
781 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
783 int dy = SIGN(screen_y - screen_y_old);
785 screen_y = screen_y_old + dy * 2 * stepsize;
788 /* prevent scrolling away from the other players when focus on all players */
789 if (game.centered_player_nr == -1)
791 /* check if all players are still visible with new scrolling position */
792 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
793 !checkIfAllPlayersAreVisible(screen_x, screen_y))
795 /* reset horizontal scroll position to last value, if needed */
796 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
797 screen_x = screen_x_old;
799 /* reset vertical scroll position to last value, if needed */
800 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
801 screen_y = screen_y_old;
805 /* prevent scrolling (for screen correcting) if no player is moving */
806 if (!game_em.any_player_moving)
808 screen_x = screen_x_old;
809 screen_y = screen_y_old;
813 /* prevent scrolling against the players move direction */
814 int player_nr = (game.centered_player_nr == -1 ?
815 max_center_distance_player_nr : game.centered_player_nr);
816 int player_move_dir = game_em.last_player_direction[player_nr];
817 int dx = SIGN(screen_x - screen_x_old);
818 int dy = SIGN(screen_y - screen_y_old);
820 if ((dx < 0 && player_move_dir != MV_LEFT) ||
821 (dx > 0 && player_move_dir != MV_RIGHT))
822 screen_x = screen_x_old;
824 if ((dy < 0 && player_move_dir != MV_UP) ||
825 (dy > 0 && player_move_dir != MV_DOWN))
826 screen_y = screen_y_old;
829 // skip redrawing playfield in warp mode or when testing tapes with "autotest"
830 if (DrawingDeactivatedField())
835 for (i = 0; i < MAX_PLAYERS; i++)