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_F(p,f) ((( f) * ply[p].oldx + \
26 (8 - f) * ply[p].x) * TILEX / 8 \
27 - ((SCR_FIELDX - 1) * TILEX) / 2)
28 #define PLAYER_SCREEN_Y_F(p,f) ((( f) * ply[p].oldy + \
29 (8 - f) * ply[p].y) * TILEY / 8 \
30 - ((SCR_FIELDY - 1) * TILEY) / 2)
32 #define PLAYER_SCREEN_X(p) PLAYER_SCREEN_X_F(p, frame)
33 #define PLAYER_SCREEN_Y(p) PLAYER_SCREEN_Y_F(p, frame)
36 int frame; /* current screen frame */
37 int screen_x; /* current scroll position */
40 /* tiles currently on screen */
41 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
42 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
44 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
46 static int centered_player_nr;
48 /* copy the entire screen to the window at the scroll position
50 * perhaps use mit-shm to speed this up
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);
102 static boolean scrolling_last = FALSE;
103 int left = screen_x / TILEX;
104 int top = screen_y / TILEY;
105 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
112 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
114 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
115 BlitScreenToBitmap_EM(backbuffer);
117 /* blit the completely updated backbuffer to the window (in one blit) */
118 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
122 for (x = 0; x < SCR_FIELDX; x++)
124 for (y = 0; y < SCR_FIELDY; y++)
126 int xx = (left + x) % MAX_BUF_XSIZE;
127 int yy = (top + y) % MAX_BUF_YSIZE;
130 BlitBitmap(screenBitmap, window,
131 xx * TILEX, yy * TILEY, TILEX, TILEY,
132 SX + x * TILEX, SY + y * TILEY);
137 for (x = 0; x < MAX_BUF_XSIZE; x++)
138 for (y = 0; y < MAX_BUF_YSIZE; y++)
139 redraw[x][y] = FALSE;
142 scrolling_last = scrolling;
146 /* blit all (up to four) parts of the scroll buffer to the window */
147 BlitScreenToBitmap_EM(window);
152 static void DrawLevelField_EM(int x, int y, int sx, int sy,
155 int tile = Draw[y][x];
156 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
157 int src_x = g->src_x + g->src_offset_x;
158 int src_y = g->src_y + g->src_offset_y;
159 int dst_x = sx * TILEX + g->dst_offset_x;
160 int dst_y = sy * TILEY + g->dst_offset_y;
161 int width = g->width;
162 int height = g->height;
165 int left = screen_x / TILEX;
166 int top = screen_y / TILEY;
168 if (x < left || x >= left + MAX_BUF_XSIZE ||
169 y < top || y >= top + MAX_BUF_YSIZE)
175 if (width > 0 && height > 0)
177 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
178 dst_x - src_x, dst_y - src_y);
179 BlitBitmapMasked(g->bitmap, screenBitmap,
180 src_x, src_y, width, height, dst_x, dst_y);
185 if ((width != TILEX || height != TILEY) && !g->preserve_background)
186 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
188 if (width > 0 && height > 0)
189 BlitBitmap(g->bitmap, screenBitmap,
190 src_x, src_y, width, height, dst_x, dst_y);
194 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
195 int crm, boolean draw_masked)
197 int tile = Draw[y][x];
198 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
202 int left = screen_x / TILEX;
203 int top = screen_y / TILEY;
205 if (x < left || x >= left + MAX_BUF_XSIZE ||
206 y < top || y >= top + MAX_BUF_YSIZE)
210 if (crm == 0) /* no crumbled edges for this tile */
213 for (i = 0; i < 4; i++)
217 int width, height, cx, cy;
219 if (i == 1 || i == 2)
221 width = g->crumbled_border_size;
223 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
229 height = g->crumbled_border_size;
231 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
234 if (width > 0 && height > 0)
236 int src_x = g->crumbled_src_x + cx;
237 int src_y = g->crumbled_src_y + cy;
238 int dst_x = sx * TILEX + cx;
239 int dst_y = sy * TILEY + cy;
243 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
244 dst_x - src_x, dst_y - src_y);
245 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
246 src_x, src_y, width, height, dst_x, dst_y);
249 BlitBitmap(g->crumbled_bitmap, screenBitmap,
250 src_x, src_y, width, height, dst_x, dst_y);
256 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
259 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
261 int src_x = g->src_x, src_y = g->src_y;
265 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
266 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
269 x1 %= MAX_BUF_XSIZE * TILEX;
270 y1 %= MAX_BUF_YSIZE * TILEY;
275 /* draw the player to current location */
278 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
279 dst_x - src_x, dst_y - src_y);
280 BlitBitmapMasked(g->bitmap, screenBitmap,
281 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
283 /* draw the player to opposite wrap-around column */
284 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
286 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
287 dst_x - src_x, dst_y - src_y);
288 BlitBitmapMasked(g->bitmap, screenBitmap,
289 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
291 /* draw the player to opposite wrap-around row */
293 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
294 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
295 dst_x - src_x, dst_y - src_y);
296 BlitBitmapMasked(g->bitmap, screenBitmap,
297 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
301 /* draw the player to current location */
304 BlitBitmap(g->bitmap, screenBitmap,
305 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
307 /* draw the player to opposite wrap-around column */
308 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
310 BlitBitmap(g->bitmap, screenBitmap,
311 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
313 /* draw the player to opposite wrap-around row */
315 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
316 BlitBitmap(g->bitmap, screenBitmap,
317 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
321 /* draw differences between game tiles and screen tiles
323 * implicitly handles scrolling and restoring background under the sprites
325 * perhaps use mit-shm to speed this up
328 static void animscreen(void)
331 int left = screen_x / TILEX;
332 int top = screen_y / TILEY;
333 static int xy[4][2] =
341 for (y = top; y < top + MAX_BUF_YSIZE; y++)
343 for (x = left; x < left + MAX_BUF_XSIZE; x++)
345 int sx = x % MAX_BUF_XSIZE;
346 int sy = y % MAX_BUF_YSIZE;
347 int tile = Draw[y][x];
348 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
349 int obj = g->unique_identifier;
352 /* re-calculate crumbled state of this tile */
353 if (g->has_crumbled_graphics)
355 for (i = 0; i < 4; i++)
357 int xx = x + xy[i][0];
358 int yy = y + xy[i][1];
361 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
362 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
365 tile_next = Draw[yy][xx];
367 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
372 /* only redraw screen tiles if they (or their crumbled state) changed */
373 if (screentiles[sy][sx] != obj || crumbled_state[sy][sx] != crm)
375 DrawLevelField_EM(x, y, sx, sy, FALSE);
376 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
378 screentiles[sy][sx] = obj;
379 crumbled_state[sy][sx] = crm;
381 redraw[sx][sy] = TRUE;
389 /* blit players to the screen
391 * handles transparency and movement
394 static void blitplayer(struct PLAYER *ply)
401 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
402 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
403 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
407 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
408 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
410 /* some casts to "int" are needed because of negative calculation values */
411 int dx = (int)ply->x - (int)ply->oldx;
412 int dy = (int)ply->y - (int)ply->oldy;
413 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
414 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
415 int new_x = old_x + SIGN(dx);
416 int new_y = old_y + SIGN(dy);
417 int old_sx = old_x % MAX_BUF_XSIZE;
418 int old_sy = old_y % MAX_BUF_XSIZE;
419 int new_sx = new_x % MAX_BUF_XSIZE;
420 int new_sy = new_y % MAX_BUF_XSIZE;
422 int old_crm = crumbled_state[old_sy][old_sx];
424 int new_crm = crumbled_state[new_sy][new_sx];
426 /* only diggable elements can be crumbled in the classic EM engine */
427 boolean player_is_digging = (new_crm != 0);
430 x1 %= MAX_BUF_XSIZE * TILEX;
431 y1 %= MAX_BUF_YSIZE * TILEY;
432 x2 %= MAX_BUF_XSIZE * TILEX;
433 y2 %= MAX_BUF_YSIZE * TILEY;
436 if (player_is_digging)
439 /* draw the field the player is moving from (under the player) */
440 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
441 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
444 /* draw the field the player is moving to (under the player) */
445 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
446 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
448 /* draw the player (masked) over the element he is just digging away */
449 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
452 /* draw the field the player is moving from (masked over the player) */
453 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
458 /* draw the player under the element which is on the same field */
459 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
461 /* draw the field the player is moving from (masked over the player) */
462 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
464 /* draw the field the player is moving to (masked over the player) */
465 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
468 /* mark screen tiles as dirty */
469 screentiles[old_sy][old_sx] = -1;
470 screentiles[new_sy][new_sx] = -1;
474 void game_initscreen(void)
477 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
478 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
483 int player_nr = getCenteredPlayerNr_EM();
485 int player_nr = 0; /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
489 centered_player_nr = getCenteredPlayerNr_EM();
491 player_nr = (centered_player_nr != -1 ? centered_player_nr : 0);
495 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
496 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
502 for (y = 0; y < MAX_BUF_YSIZE; y++)
504 for (x = 0; x < MAX_BUF_XSIZE; x++)
506 screentiles[y][x] = -1;
507 crumbled_state[y][x] = 0;
512 DrawAllGameValues(lev.required, dynamite_state, lev.score,
513 lev.time, all_keys_state);
515 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
516 DISPLAY_TIME(lev.time + 4), ply1.keys | ply2.keys);
521 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
523 boolean ffwd_delay = (tape.playing && tape.fast_forward);
524 boolean no_delay = (tape.warp_forward);
525 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
526 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
530 if (quick_relocation)
532 int offset = (setup.scroll_delay ? 3 : 0);
534 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
536 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
537 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
538 player->jx - MIDPOSX);
540 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
541 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
542 player->jy - MIDPOSY);
546 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
547 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
548 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
550 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
551 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
552 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
554 /* don't scroll over playfield boundaries */
555 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
556 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
558 /* don't scroll over playfield boundaries */
559 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
560 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
563 RedrawPlayfield(TRUE, 0,0,0,0);
567 int scroll_xx = -999, scroll_yy = -999;
569 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
571 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
574 int fx = FX, fy = FY;
576 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
577 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
578 player->jx - MIDPOSX);
580 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
581 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
582 player->jy - MIDPOSY);
584 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
585 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
587 if (dx == 0 && dy == 0) /* no scrolling needed at all */
593 fx += dx * TILEX / 2;
594 fy += dy * TILEY / 2;
599 /* scroll in two steps of half tile size to make things smoother */
600 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
602 Delay(wait_delay_value);
604 /* scroll second step to align at full tile size */
606 Delay(wait_delay_value);
611 Delay(wait_delay_value);
616 void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
618 boolean num_checked_players = 0;
621 for (i = 0; i < MAX_PLAYERS; i++)
626 int sx = PLAYER_SCREEN_X_F(i, 0);
627 int sy = PLAYER_SCREEN_Y_F(i, 0);
629 int sx = PLAYER_SCREEN_X(i);
630 int sy = PLAYER_SCREEN_Y(i);
634 /* round player position to full tile */
635 sx = (sx / TILEX) * TILEX;
636 sy = (sy / TILEY) * TILEY;
639 if (num_checked_players == 0)
646 *sx1 = MIN(*sx1, sx);
647 *sy1 = MIN(*sy1, sy);
648 *sx2 = MAX(*sx2, sx);
649 *sy2 = MAX(*sy2, sy);
652 num_checked_players++;
657 boolean checkIfAllPlayersFitToScreen()
659 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
661 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
663 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
664 sy2 - sy1 <= SCR_FIELDY * TILEY);
667 void setScreenCenteredToAllPlayers(int *sx, int *sy)
669 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
671 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
673 *sx = (sx1 + sx2) / 2;
674 *sy = (sy1 + sy2) / 2;
677 void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy)
679 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
681 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
683 *max_dx = MAX(ABS(sx1 - screen_x), ABS(sx2 - screen_x));
684 *max_dy = MAX(ABS(sy1 - screen_y), ABS(sy2 - screen_y));
687 boolean checkIfAllPlayersAreVisible()
691 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy);
693 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
694 max_dy <= SCR_FIELDY * TILEY / 2);
697 void RedrawPlayfield_EM(boolean force_redraw)
700 int centered_player_nr_next = getCenteredPlayerNr_EM();
704 boolean all_players_visible = checkIfAllPlayersAreVisible();
705 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
706 boolean draw_new_player_location = FALSE;
707 boolean quick_relocation = setup.quick_switch;
709 int player_nr = 0; /* !!! FIX THIS (CENTERED TO PLAYER 1) !!! */
711 int offset = (setup.scroll_delay ? 3 : 0) * TILEX;
712 int offset_x = offset;
713 int offset_y = offset;
714 int screen_x_old = screen_x;
715 int screen_y_old = screen_y;
720 player_nr = (centered_player_nr_next != -1 ? centered_player_nr_next :0);
722 sx = PLAYER_SCREEN_X(player_nr);
723 sy = PLAYER_SCREEN_Y(player_nr);
726 if (centered_player_nr_next == -1 && !all_players_fit_to_screen)
728 setCenteredPlayerNr_EM(centered_player_nr);
730 centered_player_nr_next = centered_player_nr;
734 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
737 if (!scrolling) /* screen currently aligned at tile position */
740 if (centered_player_nr != centered_player_nr_next)
742 centered_player_nr = centered_player_nr_next;
744 draw_new_player_location = TRUE;
751 if (centered_player_nr == -1)
756 if (draw_new_player_location)
757 setScreenCenteredToAllPlayers(&sx, &sy);
760 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
761 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
767 setScreenCenteredToAllPlayers(&sx, &sy);
771 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
772 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
777 printf("::: %d\n", all_players_visible);
779 if (!all_players_visible)
794 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy);
796 if (max_dx > offset_x)
797 offset_x = MAX(0, offset_x - (max_dx - offset_x));
798 if (max_dy > offset_y)
799 offset_y = MAX(0, offset_y - (max_dy - offset_y));
805 sx = PLAYER_SCREEN_X(centered_player_nr);
806 sy = PLAYER_SCREEN_Y(centered_player_nr);
810 if (draw_new_player_location && !quick_relocation)
813 unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
815 unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
817 int wait_delay_value = game_frame_delay_value;
819 int screen_xx = VALID_SCREEN_X(sx);
820 int screen_yy = VALID_SCREEN_Y(sy);
822 int screen_xx = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
823 int screen_yy = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
826 while (screen_x != screen_xx || screen_y != screen_yy)
828 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
829 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
830 int dxx = 0, dyy = 0;
832 if (dx == 0 && dy == 0) /* no scrolling needed at all */
836 if (ABS(screen_xx - screen_x) >= TILEX ||
837 ABS(screen_yy - screen_y) >= TILEY)
839 screen_x -= dx * TILEX;
840 screen_y -= dy * TILEY;
842 dxx = dx * TILEX / 2;
843 dyy = dy * TILEY / 2;
847 screen_x = screen_xx;
848 screen_y = screen_yy;
854 screen_x -= dx * TILEX;
855 screen_y -= dy * TILEY;
857 dxx += dx * TILEX / 2;
858 dyy += dy * TILEY / 2;
861 /* scroll in two steps of half tile size to make things smoother */
867 for (i = 0; i < MAX_PLAYERS; i++)
872 Delay(wait_delay_value);
874 /* scroll second step to align at full tile size */
882 for (i = 0; i < MAX_PLAYERS; i++)
887 Delay(wait_delay_value);
890 screen_x_old = screen_x;
891 screen_y_old = screen_y;
896 for (y = 0; y < MAX_BUF_YSIZE; y++)
898 for (x = 0; x < MAX_BUF_XSIZE; x++)
900 screentiles[y][x] = -1;
901 crumbled_state[y][x] = 0;
906 /* calculate new screen scrolling position, with regard to scroll delay */
907 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
908 sx - offset_x > screen_x ? sx - offset_x :
910 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
911 sy - offset_y > screen_y ? sy - offset_y :
915 /* prevent scrolling further than player step size screen when scrolling */
916 if (ABS(screen_x - screen_x_old) > TILEX / 8 ||
917 ABS(screen_y - screen_y_old) > TILEY / 8)
919 int dx = SIGN(screen_x - screen_x_old);
920 int dy = SIGN(screen_y - screen_y_old);
922 screen_x = screen_x_old + dx * TILEX / 8;
923 screen_y = screen_y_old + dy * TILEY / 8;
928 if (centered_player_nr == -1)
930 boolean all_players_visible_old = all_players_visible;
932 all_players_visible = checkIfAllPlayersAreVisible();
935 printf("::: OLD(%d) -> NEW(%d) / OLD(%d, %d) -> NEW(%d, %d)\n",
936 all_players_visible_old,
938 screen_x_old, screen_y_old,
942 if (!all_players_visible)
944 screen_x = screen_x_old;
945 screen_y = screen_y_old;
951 /* prevent scrolling if no player is moving */
952 if (!game_em.any_player_moving)
954 screen_x = screen_x_old;
955 screen_y = screen_y_old;
959 /* prevent scrolling against the players move direction */
960 int player_nr = game_em.last_moving_player;
961 int player_move_dir = game_em.last_player_direction[player_nr];
962 int dx = SIGN(screen_x - screen_x_old);
963 int dy = SIGN(screen_y - screen_y_old);
965 if (dx < 0 && player_move_dir == MV_RIGHT ||
966 dx > 0 && player_move_dir == MV_LEFT)
967 screen_x = screen_x_old;
969 if (dy < 0 && player_move_dir == MV_DOWN ||
970 dy > 0 && player_move_dir == MV_UP)
971 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);