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)
31 int frame; /* current screen frame */
32 int screen_x; /* current scroll position */
35 /* tiles currently on screen */
36 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
37 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
39 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
43 int centered_player_nr;
45 static int centered_player_nr;
49 /* copy the entire screen to the window at the scroll position */
51 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
53 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
54 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
56 if (x < 2 * TILEX && y < 2 * TILEY)
58 BlitBitmap(screenBitmap, target_bitmap, x, y,
59 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
61 else if (x < 2 * TILEX && y >= 2 * TILEY)
63 BlitBitmap(screenBitmap, target_bitmap, x, y,
64 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
66 BlitBitmap(screenBitmap, target_bitmap, x, 0,
67 SCR_FIELDX * TILEX, y - 2 * TILEY,
68 SX, SY + MAX_BUF_YSIZE * TILEY - y);
70 else if (x >= 2 * TILEX && y < 2 * TILEY)
72 BlitBitmap(screenBitmap, target_bitmap, x, y,
73 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
75 BlitBitmap(screenBitmap, target_bitmap, 0, y,
76 x - 2 * TILEX, SCR_FIELDY * TILEY,
77 SX + MAX_BUF_XSIZE * TILEX - x, SY);
81 BlitBitmap(screenBitmap, target_bitmap, x, y,
82 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
84 BlitBitmap(screenBitmap, target_bitmap, 0, y,
85 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
86 SX + MAX_BUF_XSIZE * TILEX - x, SY);
87 BlitBitmap(screenBitmap, target_bitmap, x, 0,
88 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
89 SX, SY + MAX_BUF_YSIZE * TILEY - y);
90 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
91 x - 2 * TILEX, y - 2 * TILEY,
92 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
96 void BackToFront_EM(void)
98 static boolean scrolling_last = FALSE;
99 int left = screen_x / TILEX;
100 int top = screen_y / TILEY;
101 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);
133 for (x = 0; x < MAX_BUF_XSIZE; x++)
134 for (y = 0; y < MAX_BUF_YSIZE; y++)
135 redraw[x][y] = FALSE;
138 scrolling_last = scrolling;
141 void blitscreen(void)
146 static void DrawLevelField_EM(int x, int y, int sx, int sy,
149 int tile = Draw[y][x];
150 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
151 int src_x = g->src_x + g->src_offset_x;
152 int src_y = g->src_y + g->src_offset_y;
153 int dst_x = sx * TILEX + g->dst_offset_x;
154 int dst_y = sy * TILEY + g->dst_offset_y;
155 int width = g->width;
156 int height = g->height;
157 int left = screen_x / TILEX;
158 int top = screen_y / TILEY;
160 /* do not draw fields that are outside the visible screen area */
161 if (x < left || x >= left + MAX_BUF_XSIZE ||
162 y < top || y >= top + MAX_BUF_YSIZE)
167 if (width > 0 && height > 0)
169 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
170 dst_x - src_x, dst_y - src_y);
171 BlitBitmapMasked(g->bitmap, screenBitmap,
172 src_x, src_y, width, height, dst_x, dst_y);
177 if ((width != TILEX || height != TILEY) && !g->preserve_background)
178 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
180 if (width > 0 && height > 0)
181 BlitBitmap(g->bitmap, screenBitmap,
182 src_x, src_y, width, height, dst_x, dst_y);
186 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
187 int crm, boolean draw_masked)
189 int tile = Draw[y][x];
190 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
191 int left = screen_x / TILEX;
192 int top = screen_y / TILEY;
195 /* do not draw fields that are outside the visible screen area */
196 if (x < left || x >= left + MAX_BUF_XSIZE ||
197 y < top || y >= top + MAX_BUF_YSIZE)
200 if (crm == 0) /* no crumbled edges for this tile */
203 for (i = 0; i < 4; i++)
207 int width, height, cx, cy;
209 if (i == 1 || i == 2)
211 width = g->crumbled_border_size;
213 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
219 height = g->crumbled_border_size;
221 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
224 if (width > 0 && height > 0)
226 int src_x = g->crumbled_src_x + cx;
227 int src_y = g->crumbled_src_y + cy;
228 int dst_x = sx * TILEX + cx;
229 int dst_y = sy * TILEY + cy;
233 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
234 dst_x - src_x, dst_y - src_y);
235 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
236 src_x, src_y, width, height, dst_x, dst_y);
239 BlitBitmap(g->crumbled_bitmap, screenBitmap,
240 src_x, src_y, width, height, dst_x, dst_y);
246 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
249 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
251 int src_x = g->src_x, src_y = g->src_y;
254 /* do not draw fields that are outside the visible screen area */
255 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
256 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
259 x1 %= MAX_BUF_XSIZE * TILEX;
260 y1 %= MAX_BUF_YSIZE * TILEY;
264 /* draw the player to current location */
267 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
268 dst_x - src_x, dst_y - src_y);
269 BlitBitmapMasked(g->bitmap, screenBitmap,
270 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
272 /* draw the player to opposite wrap-around column */
273 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
275 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
276 dst_x - src_x, dst_y - src_y);
277 BlitBitmapMasked(g->bitmap, screenBitmap,
278 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
280 /* draw the player to opposite wrap-around row */
282 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
283 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
284 dst_x - src_x, dst_y - src_y);
285 BlitBitmapMasked(g->bitmap, screenBitmap,
286 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
290 /* draw the player to current location */
293 BlitBitmap(g->bitmap, screenBitmap,
294 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
296 /* draw the player to opposite wrap-around column */
297 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
299 BlitBitmap(g->bitmap, screenBitmap,
300 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
302 /* draw the player to opposite wrap-around row */
304 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
305 BlitBitmap(g->bitmap, screenBitmap,
306 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
310 /* draw differences between game tiles and screen tiles
312 * implicitly handles scrolling and restoring background under the sprites
315 static void animscreen(void)
318 int left = screen_x / TILEX;
319 int top = screen_y / TILEY;
320 static int xy[4][2] =
328 for (y = top; y < top + MAX_BUF_YSIZE; y++)
330 for (x = left; x < left + MAX_BUF_XSIZE; x++)
332 int sx = x % MAX_BUF_XSIZE;
333 int sy = y % MAX_BUF_YSIZE;
334 int tile = Draw[y][x];
335 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
336 int obj = g->unique_identifier;
339 /* re-calculate crumbled state of this tile */
340 if (g->has_crumbled_graphics)
342 for (i = 0; i < 4; i++)
344 int xx = x + xy[i][0];
345 int yy = y + xy[i][1];
348 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
349 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
352 tile_next = Draw[yy][xx];
354 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
359 /* only redraw screen tiles if they (or their crumbled state) changed */
360 if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
362 DrawLevelField_EM(x, y, sx, sy, FALSE);
363 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
365 screentiles[sy][sx] = obj;
366 crumbled_state[sy][sx] = crm;
368 redraw[sx][sy] = TRUE;
376 /* blit players to the screen
378 * handles transparency and movement
381 static void blitplayer(struct PLAYER *ply)
388 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
389 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
390 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
394 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
395 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
397 /* some casts to "int" are needed because of negative calculation values */
398 int dx = (int)ply->x - (int)ply->oldx;
399 int dy = (int)ply->y - (int)ply->oldy;
400 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
401 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
402 int new_x = old_x + SIGN(dx);
403 int new_y = old_y + SIGN(dy);
404 int old_sx = old_x % MAX_BUF_XSIZE;
405 int old_sy = old_y % MAX_BUF_XSIZE;
406 int new_sx = new_x % MAX_BUF_XSIZE;
407 int new_sy = new_y % MAX_BUF_XSIZE;
409 int old_crm = crumbled_state[old_sy][old_sx];
411 int new_crm = crumbled_state[new_sy][new_sx];
413 /* only diggable elements can be crumbled in the classic EM engine */
414 boolean player_is_digging = (new_crm != 0);
417 x1 %= MAX_BUF_XSIZE * TILEX;
418 y1 %= MAX_BUF_YSIZE * TILEY;
419 x2 %= MAX_BUF_XSIZE * TILEX;
420 y2 %= MAX_BUF_YSIZE * TILEY;
423 if (player_is_digging)
426 /* draw the field the player is moving from (under the player) */
427 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
428 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
431 /* draw the field the player is moving to (under the player) */
432 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
433 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
435 /* draw the player (masked) over the element he is just digging away */
436 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
439 /* draw the field the player is moving from (masked over the player) */
440 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
445 /* draw the player under the element which is on the same field */
446 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
448 /* draw the field the player is moving from (masked over the player) */
449 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
451 /* draw the field the player is moving to (masked over the player) */
452 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
455 /* mark screen tiles as dirty */
456 screentiles[old_sy][old_sx] = -1;
457 screentiles[new_sy][new_sx] = -1;
461 void game_initscreen(void)
464 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
465 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
471 game.centered_player_nr = getCenteredPlayerNr_EM();
474 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
476 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
477 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
479 for (y = 0; y < MAX_BUF_YSIZE; y++)
481 for (x = 0; x < MAX_BUF_XSIZE; x++)
483 screentiles[y][x] = -1;
484 crumbled_state[y][x] = 0;
488 DrawAllGameValues(lev.required, dynamite_state, lev.score,
489 lev.time, all_keys_state);
493 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
495 boolean ffwd_delay = (tape.playing && tape.fast_forward);
496 boolean no_delay = (tape.warp_forward);
497 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
498 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
502 if (quick_relocation)
504 int offset = (setup.scroll_delay ? 3 : 0);
506 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
508 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
509 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
510 player->jx - MIDPOSX);
512 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
513 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
514 player->jy - MIDPOSY);
518 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
519 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
520 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
522 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
523 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
524 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
526 /* don't scroll over playfield boundaries */
527 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
528 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
530 /* don't scroll over playfield boundaries */
531 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
532 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
535 RedrawPlayfield(TRUE, 0,0,0,0);
539 int scroll_xx = -999, scroll_yy = -999;
541 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
543 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
546 int fx = FX, fy = FY;
548 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
549 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
550 player->jx - MIDPOSX);
552 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
553 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
554 player->jy - MIDPOSY);
556 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
557 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
559 if (dx == 0 && dy == 0) /* no scrolling needed at all */
565 fx += dx * TILEX / 2;
566 fy += dy * TILEY / 2;
571 /* scroll in two steps of half tile size to make things smoother */
572 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
574 Delay(wait_delay_value);
576 /* scroll second step to align at full tile size */
578 Delay(wait_delay_value);
583 Delay(wait_delay_value);
588 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
590 int max_dx = 0, max_dy = 0;
591 int player_nr = game_em.last_moving_player;
594 for (i = 0; i < MAX_PLAYERS; i++)
598 int sx = PLAYER_SCREEN_X(i);
599 int sy = PLAYER_SCREEN_Y(i);
601 if (game_em.last_player_direction[i] != MV_NONE &&
602 (ABS(sx - center_x) > max_dx ||
603 ABS(sy - center_y) > max_dy))
605 max_dx = MAX(max_dx, ABS(sx - center_x));
606 max_dy = MAX(max_dy, ABS(sy - center_y));
616 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
618 boolean num_checked_players = 0;
621 for (i = 0; i < MAX_PLAYERS; i++)
625 int sx = PLAYER_SCREEN_X(i);
626 int sy = PLAYER_SCREEN_Y(i);
628 if (num_checked_players == 0)
635 *sx1 = MIN(*sx1, sx);
636 *sy1 = MIN(*sy1, sy);
637 *sx2 = MAX(*sx2, sx);
638 *sy2 = MAX(*sy2, sy);
641 num_checked_players++;
646 boolean checkIfAllPlayersFitToScreen()
648 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
650 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
652 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
653 sy2 - sy1 <= SCR_FIELDY * TILEY);
656 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
658 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
660 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
662 *sx = (sx1 + sx2) / 2;
663 *sy = (sy1 + sy2) / 2;
666 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
667 int center_x, int center_y)
669 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
671 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
673 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
674 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
677 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
681 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
683 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
684 max_dy <= SCR_FIELDY * TILEY / 2);
687 void RedrawPlayfield_EM(boolean force_redraw)
690 boolean all_players_visible = checkIfAllPlayersAreVisible();
692 boolean draw_new_player_location = FALSE;
693 boolean quick_relocation = setup.quick_switch;
695 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
698 boolean game.set_centered_player = getSetCenteredPlayer_EM();
699 int game.centered_player_nr_next = getCenteredPlayerNr_EM();
702 int max_center_distance_player_nr =
703 getMaxCenterDistancePlayerNr(screen_x, screen_y);
705 int player_nr = game_em.last_moving_player;
707 int stepsize = TILEX / 8;
708 int offset = (setup.scroll_delay ? 3 : 0) * TILEX;
709 int offset_x = offset;
710 int offset_y = offset;
711 int screen_x_old = screen_x;
712 int screen_y_old = screen_y;
716 if (game.set_centered_player)
718 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
720 /* switching to "all players" only possible if all players fit to screen */
721 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
723 game.centered_player_nr_next = game.centered_player_nr;
724 game.set_centered_player = FALSE;
727 /* do not switch focus to non-existing (or non-active) player */
728 if (game.centered_player_nr_next >= 0 &&
729 !ply[game.centered_player_nr_next].alive)
731 game.centered_player_nr_next = game.centered_player_nr;
732 game.set_centered_player = FALSE;
737 /* also allow focus switching when screen is scrolled to half tile */
739 if (!scrolling) /* screen currently aligned at tile position */
743 if (game.set_centered_player)
745 if (game.centered_player_nr != game.centered_player_nr_next)
748 game.centered_player_nr = game.centered_player_nr_next;
750 draw_new_player_location = TRUE;
753 game.set_centered_player = FALSE;
757 if (game.centered_player_nr == -1)
760 if (draw_new_player_location || offset == 0)
762 if (draw_new_player_location)
765 setScreenCenteredToAllPlayers(&sx, &sy);
770 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
771 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
773 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
774 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
780 sx = PLAYER_SCREEN_X(game.centered_player_nr);
781 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
784 if (draw_new_player_location && quick_relocation)
786 screen_x = VALID_SCREEN_X(sx);
787 screen_y = VALID_SCREEN_Y(sy);
788 screen_x_old = screen_x;
789 screen_y_old = screen_y;
797 if (draw_new_player_location && !quick_relocation)
800 unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
802 unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
804 int wait_delay_value = game_frame_delay_value;
805 int screen_xx = VALID_SCREEN_X(sx);
806 int screen_yy = VALID_SCREEN_Y(sy);
808 while (screen_x != screen_xx || screen_y != screen_yy)
810 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
811 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
812 int dxx = 0, dyy = 0;
814 if (dx == 0 && dy == 0) /* no scrolling needed at all */
819 if (ABS(screen_xx - screen_x) >= TILEX)
821 screen_x -= dx * TILEX;
822 dxx = dx * TILEX / 2;
826 screen_x = screen_xx;
830 if (ABS(screen_yy - screen_y) >= TILEY)
832 screen_y -= dy * TILEY;
833 dyy = dy * TILEY / 2;
837 screen_y = screen_yy;
844 if (ABS(screen_xx - screen_x) >= TILEX ||
845 ABS(screen_yy - screen_y) >= TILEY)
847 screen_x -= dx * TILEX;
848 screen_y -= dy * TILEY;
850 dxx = dx * TILEX / 2;
851 dyy = dy * TILEY / 2;
855 screen_x = screen_xx;
856 screen_y = screen_yy;
862 screen_x -= dx * TILEX;
863 screen_y -= dy * TILEY;
865 dxx += dx * TILEX / 2;
866 dyy += dy * TILEY / 2;
871 /* scroll in two steps of half tile size to make things smoother */
877 for (i = 0; i < MAX_PLAYERS; i++)
882 Delay(wait_delay_value);
884 /* scroll second step to align at full tile size */
894 for (i = 0; i < MAX_PLAYERS; i++)
899 Delay(wait_delay_value);
902 screen_x_old = screen_x;
903 screen_y_old = screen_y;
908 for (y = 0; y < MAX_BUF_YSIZE; y++)
910 for (x = 0; x < MAX_BUF_XSIZE; x++)
912 screentiles[y][x] = -1;
913 crumbled_state[y][x] = 0;
918 /* calculate new screen scrolling position, with regard to scroll delay */
919 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
920 sx - offset_x > screen_x ? sx - offset_x :
922 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
923 sy - offset_y > screen_y ? sy - offset_y :
927 printf("::: (%d, %d) => (%d, %d) [(%d, %d), (%d, %d)] [%d, %d] [%d / %d]\n",
928 screen_x_old, screen_y_old,
930 ply[max_center_distance_player_nr].oldx,
931 ply[max_center_distance_player_nr].x,
932 ply[max_center_distance_player_nr].oldy,
933 ply[max_center_distance_player_nr].y,
935 ABS(screen_x - screen_x_old),
936 ABS(screen_y - screen_y_old));
942 /* prevent scrolling further than double player step size when scrolling */
943 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
945 int dx = SIGN(screen_x - screen_x_old);
947 screen_x = screen_x_old + dx * 2 * stepsize;
949 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
951 int dy = SIGN(screen_y - screen_y_old);
953 screen_y = screen_y_old + dy * 2 * stepsize;
956 /* prevent scrolling further than double player step size when scrolling */
957 if (ABS(screen_x - screen_x_old) > 2 * stepsize ||
958 ABS(screen_y - screen_y_old) > 2 * stepsize)
960 int dx = SIGN(screen_x - screen_x_old);
961 int dy = SIGN(screen_y - screen_y_old);
963 screen_x = screen_x_old + dx * 2 * stepsize;
964 screen_y = screen_y_old + dy * 2 * stepsize;
969 /* prevent scrolling further than player step size when scrolling */
970 if (ABS(screen_x - screen_x_old) > stepsize ||
971 ABS(screen_y - screen_y_old) > stepsize)
973 int dx = SIGN(screen_x - screen_x_old);
974 int dy = SIGN(screen_y - screen_y_old);
976 screen_x = screen_x_old + dx * stepsize;
977 screen_y = screen_y_old + dy * stepsize;
981 /* prevent scrolling away from the other players when focus on all players */
982 if (game.centered_player_nr == -1)
985 /* check if all players are still visible with new scrolling position */
986 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
987 !checkIfAllPlayersAreVisible(screen_x, screen_y))
989 /* reset horizontal scroll position to last value, if needed */
990 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
991 screen_x = screen_x_old;
993 /* reset vertical scroll position to last value, if needed */
994 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
995 screen_y = screen_y_old;
998 boolean all_players_visible = checkIfAllPlayersAreVisible();
1000 if (!all_players_visible)
1002 printf("::: not all players visible\n");
1004 screen_x = screen_x_old;
1005 screen_y = screen_y_old;
1010 /* prevent scrolling (for screen correcting) if no player is moving */
1011 if (!game_em.any_player_moving)
1013 screen_x = screen_x_old;
1014 screen_y = screen_y_old;
1018 /* prevent scrolling against the players move direction */
1020 int player_nr = game_em.last_moving_player;
1022 int player_nr = (game.centered_player_nr == -1 ?
1023 max_center_distance_player_nr : game.centered_player_nr);
1024 int player_move_dir = game_em.last_player_direction[player_nr];
1025 int dx = SIGN(screen_x - screen_x_old);
1026 int dy = SIGN(screen_y - screen_y_old);
1028 if ((dx < 0 && player_move_dir != MV_LEFT) ||
1029 (dx > 0 && player_move_dir != MV_RIGHT))
1030 screen_x = screen_x_old;
1032 if ((dy < 0 && player_move_dir != MV_UP) ||
1033 (dy > 0 && player_move_dir != MV_DOWN))
1034 screen_y = screen_y_old;
1039 for (i = 0; i < MAX_PLAYERS; i++)
1040 blitplayer(&ply[i]);
1051 void game_animscreen(void)
1053 RedrawPlayfield_EM(FALSE);
1056 void DrawGameDoorValues_EM()
1062 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1063 int key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1067 if (game.centered_player_nr == -1)
1075 for (i = 0; i < MAX_PLAYERS; i++)
1077 dynamite_state += ply[i].dynamite;
1078 key_state |= ply[i].keys;
1083 dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1084 key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1089 int player_nr = game.centered_player_nr;
1091 dynamite_state = ply[player_nr].dynamite;
1092 key_state = ply[player_nr].keys;
1097 DrawAllGameValues(lev.required, dynamite_state, lev.score,
1098 lev.time, key_state);
1100 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
1101 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);