1 /* 2000-08-13T14:36:17Z
3 * graphics manipulation crap
10 #define MIN_SCREEN_XPOS 1
11 #define MIN_SCREEN_YPOS 1
12 #define MAX_SCREEN_XPOS MAX(1, lev.width - (SCR_FIELDX - 1))
13 #define MAX_SCREEN_YPOS MAX(1, lev.height - (SCR_FIELDY - 1))
15 #define MIN_SCREEN_X (MIN_SCREEN_XPOS * TILEX)
16 #define MIN_SCREEN_Y (MIN_SCREEN_YPOS * TILEY)
17 #define MAX_SCREEN_X (MAX_SCREEN_XPOS * TILEX)
18 #define MAX_SCREEN_Y (MAX_SCREEN_YPOS * TILEY)
20 #define VALID_SCREEN_X(x) ((x) < MIN_SCREEN_X ? MIN_SCREEN_X : \
21 (x) > MAX_SCREEN_X ? MAX_SCREEN_X : (x))
22 #define VALID_SCREEN_Y(y) ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y : \
23 (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y))
25 #define PLAYER_SCREEN_X(p) ((( frame) * ply[p].oldx + \
26 (8 - frame) * ply[p].x) * TILEX / 8 \
27 - ((SCR_FIELDX - 1) * TILEX) / 2)
28 #define PLAYER_SCREEN_Y(p) ((( frame) * ply[p].oldy + \
29 (8 - frame) * ply[p].y) * TILEY / 8 \
30 - ((SCR_FIELDY - 1) * TILEY) / 2)
33 int frame; /* current screen frame */
34 int screen_x; /* current scroll position */
37 /* tiles currently on screen */
38 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
39 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
41 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
45 int centered_player_nr;
47 static int centered_player_nr;
51 /* copy the entire screen to the window at the scroll position */
53 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
55 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
56 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
58 if (x < 2 * TILEX && y < 2 * TILEY)
60 BlitBitmap(screenBitmap, target_bitmap, x, y,
61 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
63 else if (x < 2 * TILEX && y >= 2 * TILEY)
65 BlitBitmap(screenBitmap, target_bitmap, x, y,
66 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
68 BlitBitmap(screenBitmap, target_bitmap, x, 0,
69 SCR_FIELDX * TILEX, 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, SCR_FIELDY * TILEY,
77 BlitBitmap(screenBitmap, target_bitmap, 0, y,
78 x - 2 * TILEX, SCR_FIELDY * TILEY,
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);
100 static boolean scrolling_last = FALSE;
101 int left = screen_x / TILEX;
102 int top = screen_y / TILEY;
103 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
106 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
108 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
109 BlitScreenToBitmap_EM(backbuffer);
111 /* blit the completely updated backbuffer to the window (in one blit) */
112 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
116 for (x = 0; x < SCR_FIELDX; x++)
118 for (y = 0; y < SCR_FIELDY; y++)
120 int xx = (left + x) % MAX_BUF_XSIZE;
121 int yy = (top + y) % MAX_BUF_YSIZE;
124 BlitBitmap(screenBitmap, window,
125 xx * TILEX, yy * TILEY, TILEX, TILEY,
126 SX + x * TILEX, SY + y * TILEY);
131 for (x = 0; x < MAX_BUF_XSIZE; x++)
132 for (y = 0; y < MAX_BUF_YSIZE; y++)
133 redraw[x][y] = FALSE;
136 scrolling_last = scrolling;
139 static void DrawLevelField_EM(int x, int y, int sx, int sy,
142 int tile = Draw[y][x];
143 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
144 int src_x = g->src_x + g->src_offset_x;
145 int src_y = g->src_y + g->src_offset_y;
146 int dst_x = sx * TILEX + g->dst_offset_x;
147 int dst_y = sy * TILEY + g->dst_offset_y;
148 int width = g->width;
149 int height = g->height;
150 int left = screen_x / TILEX;
151 int top = screen_y / TILEY;
153 /* do not draw fields that are outside the visible screen area */
154 if (x < left || x >= left + MAX_BUF_XSIZE ||
155 y < top || y >= top + MAX_BUF_YSIZE)
160 if (width > 0 && height > 0)
162 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
163 dst_x - src_x, dst_y - src_y);
164 BlitBitmapMasked(g->bitmap, screenBitmap,
165 src_x, src_y, width, height, dst_x, dst_y);
170 if ((width != TILEX || height != TILEY) && !g->preserve_background)
171 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
173 if (width > 0 && height > 0)
174 BlitBitmap(g->bitmap, screenBitmap,
175 src_x, src_y, width, height, dst_x, dst_y);
179 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
180 int crm, boolean draw_masked)
182 int tile = Draw[y][x];
183 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
184 int left = screen_x / TILEX;
185 int top = screen_y / TILEY;
188 /* do not draw fields that are outside the visible screen area */
189 if (x < left || x >= left + MAX_BUF_XSIZE ||
190 y < top || y >= top + MAX_BUF_YSIZE)
193 if (crm == 0) /* no crumbled edges for this tile */
196 for (i = 0; i < 4; i++)
200 int width, height, cx, cy;
202 if (i == 1 || i == 2)
204 width = g->crumbled_border_size;
206 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
212 height = g->crumbled_border_size;
214 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
217 if (width > 0 && height > 0)
219 int src_x = g->crumbled_src_x + cx;
220 int src_y = g->crumbled_src_y + cy;
221 int dst_x = sx * TILEX + cx;
222 int dst_y = sy * TILEY + cy;
226 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
227 dst_x - src_x, dst_y - src_y);
228 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
229 src_x, src_y, width, height, dst_x, dst_y);
232 BlitBitmap(g->crumbled_bitmap, screenBitmap,
233 src_x, src_y, width, height, dst_x, dst_y);
239 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
242 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
244 int src_x = g->src_x, src_y = g->src_y;
247 /* do not draw fields that are outside the visible screen area */
248 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
249 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
252 x1 %= MAX_BUF_XSIZE * TILEX;
253 y1 %= MAX_BUF_YSIZE * TILEY;
257 /* draw the player to current location */
260 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
261 dst_x - src_x, dst_y - src_y);
262 BlitBitmapMasked(g->bitmap, screenBitmap,
263 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
265 /* draw the player to opposite wrap-around column */
266 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
268 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
269 dst_x - src_x, dst_y - src_y);
270 BlitBitmapMasked(g->bitmap, screenBitmap,
271 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
273 /* draw the player to opposite wrap-around row */
275 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
276 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
277 dst_x - src_x, dst_y - src_y);
278 BlitBitmapMasked(g->bitmap, screenBitmap,
279 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
283 /* draw the player to current location */
286 BlitBitmap(g->bitmap, screenBitmap,
287 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
289 /* draw the player to opposite wrap-around column */
290 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
292 BlitBitmap(g->bitmap, screenBitmap,
293 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
295 /* draw the player to opposite wrap-around row */
297 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
298 BlitBitmap(g->bitmap, screenBitmap,
299 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
303 /* draw differences between game tiles and screen tiles
305 * implicitly handles scrolling and restoring background under the sprites
308 static void animscreen(void)
311 int left = screen_x / TILEX;
312 int top = screen_y / TILEY;
313 static int xy[4][2] =
321 for (y = top; y < top + MAX_BUF_YSIZE; y++)
323 for (x = left; x < left + MAX_BUF_XSIZE; x++)
325 int sx = x % MAX_BUF_XSIZE;
326 int sy = y % MAX_BUF_YSIZE;
327 int tile = Draw[y][x];
328 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
329 int obj = g->unique_identifier;
332 /* re-calculate crumbled state of this tile */
333 if (g->has_crumbled_graphics)
335 for (i = 0; i < 4; i++)
337 int xx = x + xy[i][0];
338 int yy = y + xy[i][1];
341 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
342 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
345 tile_next = Draw[yy][xx];
347 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
352 /* only redraw screen tiles if they (or their crumbled state) changed */
353 if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
355 DrawLevelField_EM(x, y, sx, sy, FALSE);
356 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
358 screentiles[sy][sx] = obj;
359 crumbled_state[sy][sx] = crm;
361 redraw[sx][sy] = TRUE;
369 /* blit players to the screen
371 * handles transparency and movement
374 static void blitplayer(struct PLAYER *ply)
381 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
382 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
383 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
387 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
388 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
390 /* some casts to "int" are needed because of negative calculation values */
391 int dx = (int)ply->x - (int)ply->oldx;
392 int dy = (int)ply->y - (int)ply->oldy;
393 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
394 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
395 int new_x = old_x + SIGN(dx);
396 int new_y = old_y + SIGN(dy);
397 int old_sx = old_x % MAX_BUF_XSIZE;
398 int old_sy = old_y % MAX_BUF_XSIZE;
399 int new_sx = new_x % MAX_BUF_XSIZE;
400 int new_sy = new_y % MAX_BUF_XSIZE;
402 int old_crm = crumbled_state[old_sy][old_sx];
404 int new_crm = crumbled_state[new_sy][new_sx];
406 /* only diggable elements can be crumbled in the classic EM engine */
407 boolean player_is_digging = (new_crm != 0);
410 x1 %= MAX_BUF_XSIZE * TILEX;
411 y1 %= MAX_BUF_YSIZE * TILEY;
412 x2 %= MAX_BUF_XSIZE * TILEX;
413 y2 %= MAX_BUF_YSIZE * TILEY;
416 if (player_is_digging)
419 /* draw the field the player is moving from (under the player) */
420 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
421 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
424 /* draw the field the player is moving to (under the player) */
425 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
426 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
428 /* draw the player (masked) over the element he is just digging away */
429 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
432 /* draw the field the player is moving from (masked over the player) */
433 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
438 /* draw the player under the element which is on the same field */
439 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
441 /* draw the field the player is moving from (masked over the player) */
442 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
444 /* draw the field the player is moving to (masked over the player) */
445 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
448 /* mark screen tiles as dirty */
449 screentiles[old_sy][old_sx] = -1;
450 screentiles[new_sy][new_sx] = -1;
454 void game_initscreen(void)
457 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
458 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
464 game.centered_player_nr = getCenteredPlayerNr_EM();
467 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
469 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
470 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
472 for (y = 0; y < MAX_BUF_YSIZE; y++)
474 for (x = 0; x < MAX_BUF_XSIZE; x++)
476 screentiles[y][x] = -1;
477 crumbled_state[y][x] = 0;
481 DrawAllGameValues(lev.required, dynamite_state, lev.score,
482 lev.time, all_keys_state);
486 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
488 boolean ffwd_delay = (tape.playing && tape.fast_forward);
489 boolean no_delay = (tape.warp_forward);
490 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
491 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
495 if (quick_relocation)
497 int offset = (setup.scroll_delay ? 3 : 0);
499 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
501 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
502 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
503 player->jx - MIDPOSX);
505 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
506 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
507 player->jy - MIDPOSY);
511 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
512 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
513 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
515 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
516 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
517 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
519 /* don't scroll over playfield boundaries */
520 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
521 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
523 /* don't scroll over playfield boundaries */
524 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
525 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
528 RedrawPlayfield(TRUE, 0,0,0,0);
532 int scroll_xx = -999, scroll_yy = -999;
534 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
536 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
539 int fx = FX, fy = FY;
541 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
542 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
543 player->jx - MIDPOSX);
545 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
546 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
547 player->jy - MIDPOSY);
549 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
550 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
552 if (dx == 0 && dy == 0) /* no scrolling needed at all */
558 fx += dx * TILEX / 2;
559 fy += dy * TILEY / 2;
564 /* scroll in two steps of half tile size to make things smoother */
565 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
567 Delay(wait_delay_value);
569 /* scroll second step to align at full tile size */
571 Delay(wait_delay_value);
576 Delay(wait_delay_value);
581 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
583 int max_dx = 0, max_dy = 0;
584 int player_nr = game_em.last_moving_player;
587 for (i = 0; i < MAX_PLAYERS; i++)
591 int sx = PLAYER_SCREEN_X(i);
592 int sy = PLAYER_SCREEN_Y(i);
594 if (game_em.last_player_direction[i] != MV_NONE &&
595 (ABS(sx - center_x) > max_dx ||
596 ABS(sy - center_y) > max_dy))
598 max_dx = MAX(max_dx, ABS(sx - center_x));
599 max_dy = MAX(max_dy, ABS(sy - center_y));
609 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
611 boolean num_checked_players = 0;
614 for (i = 0; i < MAX_PLAYERS; i++)
618 int sx = PLAYER_SCREEN_X(i);
619 int sy = PLAYER_SCREEN_Y(i);
621 if (num_checked_players == 0)
628 *sx1 = MIN(*sx1, sx);
629 *sy1 = MIN(*sy1, sy);
630 *sx2 = MAX(*sx2, sx);
631 *sy2 = MAX(*sy2, sy);
634 num_checked_players++;
639 boolean checkIfAllPlayersFitToScreen()
641 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
643 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
645 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
646 sy2 - sy1 <= SCR_FIELDY * TILEY);
649 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
651 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
653 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
655 *sx = (sx1 + sx2) / 2;
656 *sy = (sy1 + sy2) / 2;
659 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
660 int center_x, int center_y)
662 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
664 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
666 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
667 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
670 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
674 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
676 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
677 max_dy <= SCR_FIELDY * TILEY / 2);
680 void RedrawPlayfield_EM(boolean force_redraw)
683 boolean all_players_visible = checkIfAllPlayersAreVisible();
685 boolean draw_new_player_location = FALSE;
686 boolean quick_relocation = setup.quick_switch;
688 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
691 boolean game.set_centered_player = getSetCenteredPlayer_EM();
692 int game.centered_player_nr_next = getCenteredPlayerNr_EM();
695 int player_nr = getMaxCenterDistancePlayerNr(screen_x, screen_y);
697 int player_nr = game_em.last_moving_player;
699 int offset = (setup.scroll_delay ? 3 : 0) * TILEX;
700 int offset_x = offset;
701 int offset_y = offset;
702 int screen_x_old = screen_x;
703 int screen_y_old = screen_y;
707 if (game.set_centered_player)
709 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
711 /* switching to "all players" only possible if all players fit to screen */
712 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
714 game.centered_player_nr_next = game.centered_player_nr;
715 game.set_centered_player = FALSE;
718 /* do not switch focus to non-existing (or non-active) player */
719 if (game.centered_player_nr_next >= 0 &&
720 !ply[game.centered_player_nr_next].alive)
722 game.centered_player_nr_next = game.centered_player_nr;
723 game.set_centered_player = FALSE;
728 /* also allow focus switching when screen is scrolled to half tile */
730 if (!scrolling) /* screen currently aligned at tile position */
734 if (game.set_centered_player)
736 if (game.centered_player_nr != game.centered_player_nr_next)
739 game.centered_player_nr = game.centered_player_nr_next;
741 draw_new_player_location = TRUE;
744 game.set_centered_player = FALSE;
748 if (game.centered_player_nr == -1)
750 if (draw_new_player_location)
752 setScreenCenteredToAllPlayers(&sx, &sy);
757 sx = PLAYER_SCREEN_X(player_nr);
758 sy = PLAYER_SCREEN_Y(player_nr);
760 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
761 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
767 sx = PLAYER_SCREEN_X(game.centered_player_nr);
768 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
771 if (draw_new_player_location && quick_relocation)
773 screen_x = VALID_SCREEN_X(sx);
774 screen_y = VALID_SCREEN_Y(sy);
775 screen_x_old = screen_x;
776 screen_y_old = screen_y;
784 if (draw_new_player_location && !quick_relocation)
787 unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
789 unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
791 int wait_delay_value = game_frame_delay_value;
792 int screen_xx = VALID_SCREEN_X(sx);
793 int screen_yy = VALID_SCREEN_Y(sy);
795 while (screen_x != screen_xx || screen_y != screen_yy)
797 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
798 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
799 int dxx = 0, dyy = 0;
801 if (dx == 0 && dy == 0) /* no scrolling needed at all */
806 if (ABS(screen_xx - screen_x) >= TILEX)
808 screen_x -= dx * TILEX;
809 dxx = dx * TILEX / 2;
813 screen_x = screen_xx;
817 if (ABS(screen_yy - screen_y) >= TILEY)
819 screen_y -= dy * TILEY;
820 dyy = dy * TILEY / 2;
824 screen_y = screen_yy;
831 if (ABS(screen_xx - screen_x) >= TILEX ||
832 ABS(screen_yy - screen_y) >= TILEY)
834 screen_x -= dx * TILEX;
835 screen_y -= dy * TILEY;
837 dxx = dx * TILEX / 2;
838 dyy = dy * TILEY / 2;
842 screen_x = screen_xx;
843 screen_y = screen_yy;
849 screen_x -= dx * TILEX;
850 screen_y -= dy * TILEY;
852 dxx += dx * TILEX / 2;
853 dyy += dy * TILEY / 2;
858 /* scroll in two steps of half tile size to make things smoother */
864 for (i = 0; i < MAX_PLAYERS; i++)
869 Delay(wait_delay_value);
871 /* scroll second step to align at full tile size */
879 for (i = 0; i < MAX_PLAYERS; i++)
884 Delay(wait_delay_value);
887 screen_x_old = screen_x;
888 screen_y_old = screen_y;
893 for (y = 0; y < MAX_BUF_YSIZE; y++)
895 for (x = 0; x < MAX_BUF_XSIZE; x++)
897 screentiles[y][x] = -1;
898 crumbled_state[y][x] = 0;
903 /* calculate new screen scrolling position, with regard to scroll delay */
904 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
905 sx - offset_x > screen_x ? sx - offset_x :
907 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
908 sy - offset_y > screen_y ? sy - offset_y :
911 /* prevent scrolling further than player step size screen when scrolling */
912 if (ABS(screen_x - screen_x_old) > TILEX / 8 ||
913 ABS(screen_y - screen_y_old) > TILEY / 8)
915 int dx = SIGN(screen_x - screen_x_old);
916 int dy = SIGN(screen_y - screen_y_old);
918 screen_x = screen_x_old + dx * TILEX / 8;
919 screen_y = screen_y_old + dy * TILEY / 8;
922 /* prevent scrolling away from the other players when focus on all players */
923 if (game.centered_player_nr == -1)
926 /* check if all players are still visible with new scrolling position */
927 if (!checkIfAllPlayersAreVisible(screen_x, screen_y))
929 /* reset horizontal scroll position to last value, if needed */
930 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
931 screen_x = screen_x_old;
933 /* reset vertical scroll position to last value, if needed */
934 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
935 screen_y = screen_y_old;
938 boolean all_players_visible = checkIfAllPlayersAreVisible();
940 if (!all_players_visible)
942 printf("::: not all players visible\n");
944 screen_x = screen_x_old;
945 screen_y = screen_y_old;
950 /* prevent scrolling (for screen correcting) if no player is moving */
951 if (!game_em.any_player_moving)
953 screen_x = screen_x_old;
954 screen_y = screen_y_old;
958 /* prevent scrolling against the players move direction */
960 int player_nr = game_em.last_moving_player;
962 int player_move_dir = game_em.last_player_direction[player_nr];
963 int dx = SIGN(screen_x - screen_x_old);
964 int dy = SIGN(screen_y - screen_y_old);
966 if ((dx < 0 && player_move_dir != MV_LEFT) ||
967 (dx > 0 && player_move_dir != MV_RIGHT))
968 screen_x = screen_x_old;
970 if ((dy < 0 && player_move_dir != MV_UP) ||
971 (dy > 0 && player_move_dir != MV_DOWN))
972 screen_y = screen_y_old;
977 for (i = 0; i < MAX_PLAYERS; i++)
987 void game_animscreen(void)
989 RedrawPlayfield_EM(FALSE);
992 void DrawGameDoorValues_EM()
994 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
995 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
998 DrawAllGameValues(lev.required, dynamite_state, lev.score,
999 lev.time, all_keys_state);
1001 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
1002 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);