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
32 int frame; /* current screen frame */
33 int screen_x; /* current scroll position */
36 /* tiles currently on screen */
37 static int screentiles[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
38 static int crumbled_state[MAX_BUF_YSIZE][MAX_BUF_XSIZE];
40 static boolean redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
44 int centered_player_nr;
46 static int centered_player_nr;
50 /* copy the entire screen to the window at the scroll position */
52 void BlitScreenToBitmap_EM(Bitmap *target_bitmap)
54 int x = screen_x % (MAX_BUF_XSIZE * TILEX);
55 int y = screen_y % (MAX_BUF_YSIZE * TILEY);
57 if (x < 2 * TILEX && y < 2 * TILEY)
59 BlitBitmap(screenBitmap, target_bitmap, x, y,
60 SCR_FIELDX * TILEX, SCR_FIELDY * TILEY, SX, SY);
62 else if (x < 2 * TILEX && y >= 2 * TILEY)
64 BlitBitmap(screenBitmap, target_bitmap, x, y,
65 SCR_FIELDX * TILEX, MAX_BUF_YSIZE * TILEY - y,
67 BlitBitmap(screenBitmap, target_bitmap, x, 0,
68 SCR_FIELDX * TILEX, y - 2 * TILEY,
69 SX, SY + MAX_BUF_YSIZE * TILEY - y);
71 else if (x >= 2 * TILEX && y < 2 * TILEY)
73 BlitBitmap(screenBitmap, target_bitmap, x, y,
74 MAX_BUF_XSIZE * TILEX - x, SCR_FIELDY * TILEY,
76 BlitBitmap(screenBitmap, target_bitmap, 0, y,
77 x - 2 * TILEX, SCR_FIELDY * TILEY,
78 SX + MAX_BUF_XSIZE * TILEX - x, SY);
82 BlitBitmap(screenBitmap, target_bitmap, x, y,
83 MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y,
85 BlitBitmap(screenBitmap, target_bitmap, 0, y,
86 x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y,
87 SX + MAX_BUF_XSIZE * TILEX - x, SY);
88 BlitBitmap(screenBitmap, target_bitmap, x, 0,
89 MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY,
90 SX, SY + MAX_BUF_YSIZE * TILEY - y);
91 BlitBitmap(screenBitmap, target_bitmap, 0, 0,
92 x - 2 * TILEX, y - 2 * TILEY,
93 SX + MAX_BUF_XSIZE * TILEX - x, SY + MAX_BUF_YSIZE * TILEY - y);
97 void BackToFront_EM(void)
99 static boolean scrolling_last = FALSE;
100 int left = screen_x / TILEX;
101 int top = screen_y / TILEY;
102 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
107 if (redraw_tiles > REDRAWTILES_THRESHOLD || scrolling || scrolling_last)
109 /* blit all (up to four) parts of the scroll buffer to the backbuffer */
110 BlitScreenToBitmap_EM(backbuffer);
112 /* blit the completely updated backbuffer to the window (in one blit) */
113 BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY);
117 for (x = 0; x < SCR_FIELDX; x++)
119 for (y = 0; y < SCR_FIELDY; y++)
121 int xx = (left + x) % MAX_BUF_XSIZE;
122 int yy = (top + y) % MAX_BUF_YSIZE;
125 BlitBitmap(screenBitmap, window,
126 xx * TILEX, yy * TILEY, TILEX, TILEY,
127 SX + x * TILEX, SY + y * TILEY);
134 for (x = 0; x < MAX_BUF_XSIZE; x++)
135 for (y = 0; y < MAX_BUF_YSIZE; y++)
136 redraw[x][y] = FALSE;
139 scrolling_last = scrolling;
142 void blitscreen(void)
147 static struct GraphicInfo_EM *getObjectGraphic(int x, int y)
149 int tile = Draw[y][x];
150 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
152 if (!game.use_native_emc_graphics_engine)
153 getGraphicSourceObjectExt_EM(g, tile, 7 - frame, x - 2, y - 2);
158 static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim)
160 struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame];
162 if (!game.use_native_emc_graphics_engine)
163 getGraphicSourcePlayerExt_EM(g, player_nr, anim, 7 - frame);
168 static void DrawLevelField_EM(int x, int y, int sx, int sy,
171 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
172 int src_x = g->src_x + g->src_offset_x;
173 int src_y = g->src_y + g->src_offset_y;
174 int dst_x = sx * TILEX + g->dst_offset_x;
175 int dst_y = sy * TILEY + g->dst_offset_y;
176 int width = g->width;
177 int height = g->height;
178 int left = screen_x / TILEX;
179 int top = screen_y / TILEY;
181 /* do not draw fields that are outside the visible screen area */
182 if (x < left || x >= left + MAX_BUF_XSIZE ||
183 y < top || y >= top + MAX_BUF_YSIZE)
188 if (width > 0 && height > 0)
190 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
191 dst_x - src_x, dst_y - src_y);
192 BlitBitmapMasked(g->bitmap, screenBitmap,
193 src_x, src_y, width, height, dst_x, dst_y);
198 if ((width != TILEX || height != TILEY) && !g->preserve_background)
199 ClearRectangle(screenBitmap, sx * TILEX, sy * TILEY, TILEX, TILEY);
201 if (width > 0 && height > 0)
202 BlitBitmap(g->bitmap, screenBitmap,
203 src_x, src_y, width, height, dst_x, dst_y);
207 static void DrawLevelFieldCrumbled_EM(int x, int y, int sx, int sy,
208 int crm, boolean draw_masked)
210 struct GraphicInfo_EM *g = getObjectGraphic(x, y);
211 int left = screen_x / TILEX;
212 int top = screen_y / TILEY;
215 /* do not draw fields that are outside the visible screen area */
216 if (x < left || x >= left + MAX_BUF_XSIZE ||
217 y < top || y >= top + MAX_BUF_YSIZE)
220 if (crm == 0) /* no crumbled edges for this tile */
224 if (x == 3 && y == 3 && frame == 0)
225 printf("::: %d, %d\n",
226 graphic_info_em_object[207][0].crumbled_src_x,
227 graphic_info_em_object[207][0].crumbled_src_y);
230 for (i = 0; i < 4; i++)
234 int width, height, cx, cy;
236 if (i == 1 || i == 2)
238 width = g->crumbled_border_size;
240 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
246 height = g->crumbled_border_size;
248 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
251 if (width > 0 && height > 0)
253 int src_x = g->crumbled_src_x + cx;
254 int src_y = g->crumbled_src_y + cy;
255 int dst_x = sx * TILEX + cx;
256 int dst_y = sy * TILEY + cy;
260 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
261 dst_x - src_x, dst_y - src_y);
262 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
263 src_x, src_y, width, height, dst_x, dst_y);
266 BlitBitmap(g->crumbled_bitmap, screenBitmap,
267 src_x, src_y, width, height, dst_x, dst_y);
273 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
276 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
277 int src_x = g->src_x, src_y = g->src_y;
280 /* do not draw fields that are outside the visible screen area */
281 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
282 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
285 x1 %= MAX_BUF_XSIZE * TILEX;
286 y1 %= MAX_BUF_YSIZE * TILEY;
290 /* draw the player to current location */
293 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
294 dst_x - src_x, dst_y - src_y);
295 BlitBitmapMasked(g->bitmap, screenBitmap,
296 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
298 /* draw the player to opposite wrap-around column */
299 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
301 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
302 dst_x - src_x, dst_y - src_y);
303 BlitBitmapMasked(g->bitmap, screenBitmap,
304 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
306 /* draw the player to opposite wrap-around row */
308 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
309 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
310 dst_x - src_x, dst_y - src_y);
311 BlitBitmapMasked(g->bitmap, screenBitmap,
312 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
316 /* draw the player to current location */
319 BlitBitmap(g->bitmap, screenBitmap,
320 g->src_x, g->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 BlitBitmap(g->bitmap, screenBitmap,
326 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
328 /* draw the player to opposite wrap-around row */
330 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
331 BlitBitmap(g->bitmap, screenBitmap,
332 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
336 /* draw differences between game tiles and screen tiles
338 * implicitly handles scrolling and restoring background under the sprites
341 static void animscreen(void)
344 int left = screen_x / TILEX;
345 int top = screen_y / TILEY;
346 static int xy[4][2] =
354 if (!game.use_native_emc_graphics_engine)
355 for (y = 2; y < EM_MAX_CAVE_HEIGHT - 2; y++)
356 for (x = 2; x < EM_MAX_CAVE_WIDTH - 2; x++)
357 SetGfxAnimation_EM(&graphic_info_em_object[Draw[y][x]][frame],
358 Draw[y][x], 7 - frame, x - 2, y - 2);
360 for (y = top; y < top + MAX_BUF_YSIZE; y++)
362 for (x = left; x < left + MAX_BUF_XSIZE; x++)
364 int sx = x % MAX_BUF_XSIZE;
365 int sy = y % MAX_BUF_YSIZE;
366 int tile = Draw[y][x];
367 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
368 int obj = g->unique_identifier;
370 boolean redraw_screen_tile = FALSE;
372 /* re-calculate crumbled state of this tile */
373 if (g->has_crumbled_graphics)
375 for (i = 0; i < 4; i++)
377 int xx = x + xy[i][0];
378 int yy = y + xy[i][1];
381 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
382 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
385 tile_next = Draw[yy][xx];
387 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
392 redraw_screen_tile = (screentiles[sy][sx] != obj ||
393 crumbled_state[sy][sx] != crm);
396 /* !!! TEST ONLY -- CHANGE THIS !!! */
397 if (!game.use_native_emc_graphics_engine)
398 redraw_screen_tile = TRUE;
401 /* only redraw screen tiles if they (or their crumbled state) changed */
402 if (redraw_screen_tile)
404 DrawLevelField_EM(x, y, sx, sy, FALSE);
405 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
407 screentiles[sy][sx] = obj;
408 crumbled_state[sy][sx] = crm;
410 redraw[sx][sy] = TRUE;
418 /* blit players to the screen
420 * handles transparency and movement
423 static void blitplayer(struct PLAYER *ply)
430 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
431 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
432 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
436 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
437 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
439 /* some casts to "int" are needed because of negative calculation values */
440 int dx = (int)ply->x - (int)ply->oldx;
441 int dy = (int)ply->y - (int)ply->oldy;
442 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
443 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
444 int new_x = old_x + SIGN(dx);
445 int new_y = old_y + SIGN(dy);
446 int old_sx = old_x % MAX_BUF_XSIZE;
447 int old_sy = old_y % MAX_BUF_XSIZE;
448 int new_sx = new_x % MAX_BUF_XSIZE;
449 int new_sy = new_y % MAX_BUF_XSIZE;
451 int old_crm = crumbled_state[old_sy][old_sx];
453 int new_crm = crumbled_state[new_sy][new_sx];
455 /* only diggable elements can be crumbled in the classic EM engine */
456 boolean player_is_digging = (new_crm != 0);
459 x1 %= MAX_BUF_XSIZE * TILEX;
460 y1 %= MAX_BUF_YSIZE * TILEY;
461 x2 %= MAX_BUF_XSIZE * TILEX;
462 y2 %= MAX_BUF_YSIZE * TILEY;
465 if (player_is_digging)
468 /* draw the field the player is moving from (under the player) */
469 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
470 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
473 /* draw the field the player is moving to (under the player) */
474 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
475 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
477 /* draw the player (masked) over the element he is just digging away */
478 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
481 /* draw the field the player is moving from (masked over the player) */
482 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)
511 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
512 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
518 game.centered_player_nr = getCenteredPlayerNr_EM();
521 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
523 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
524 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
526 for (y = 0; y < MAX_BUF_YSIZE; y++)
528 for (x = 0; x < MAX_BUF_XSIZE; x++)
530 screentiles[y][x] = -1;
531 crumbled_state[y][x] = 0;
535 DrawAllGameValues(lev.required, dynamite_state, lev.score,
536 lev.time, all_keys_state);
540 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
542 boolean ffwd_delay = (tape.playing && tape.fast_forward);
543 boolean no_delay = (tape.warp_forward);
544 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
545 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
549 if (quick_relocation)
551 int offset = game.scroll_delay_value;
553 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
555 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
556 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
557 player->jx - MIDPOSX);
559 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
560 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
561 player->jy - MIDPOSY);
565 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
566 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
567 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
569 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
570 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
571 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
573 /* don't scroll over playfield boundaries */
574 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
575 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
577 /* don't scroll over playfield boundaries */
578 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
579 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
582 RedrawPlayfield(TRUE, 0,0,0,0);
586 int scroll_xx = -999, scroll_yy = -999;
588 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
590 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
593 int fx = FX, fy = FY;
595 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
596 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
597 player->jx - MIDPOSX);
599 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
600 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
601 player->jy - MIDPOSY);
603 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
604 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
606 if (dx == 0 && dy == 0) /* no scrolling needed at all */
612 fx += dx * TILEX / 2;
613 fy += dy * TILEY / 2;
618 /* scroll in two steps of half tile size to make things smoother */
619 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
621 Delay(wait_delay_value);
623 /* scroll second step to align at full tile size */
625 Delay(wait_delay_value);
630 Delay(wait_delay_value);
635 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
637 int max_dx = 0, max_dy = 0;
638 int player_nr = game_em.last_moving_player;
641 for (i = 0; i < MAX_PLAYERS; i++)
645 int sx = PLAYER_SCREEN_X(i);
646 int sy = PLAYER_SCREEN_Y(i);
648 if (game_em.last_player_direction[i] != MV_NONE &&
649 (ABS(sx - center_x) > max_dx ||
650 ABS(sy - center_y) > max_dy))
652 max_dx = MAX(max_dx, ABS(sx - center_x));
653 max_dy = MAX(max_dy, ABS(sy - center_y));
663 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
665 boolean num_checked_players = 0;
668 for (i = 0; i < MAX_PLAYERS; i++)
672 int sx = PLAYER_SCREEN_X(i);
673 int sy = PLAYER_SCREEN_Y(i);
675 if (num_checked_players == 0)
682 *sx1 = MIN(*sx1, sx);
683 *sy1 = MIN(*sy1, sy);
684 *sx2 = MAX(*sx2, sx);
685 *sy2 = MAX(*sy2, sy);
688 num_checked_players++;
693 boolean checkIfAllPlayersFitToScreen()
695 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
697 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
699 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
700 sy2 - sy1 <= SCR_FIELDY * TILEY);
703 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
705 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
707 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
709 *sx = (sx1 + sx2) / 2;
710 *sy = (sy1 + sy2) / 2;
713 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
714 int center_x, int center_y)
716 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
718 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
720 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
721 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
724 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
728 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
730 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
731 max_dy <= SCR_FIELDY * TILEY / 2);
734 void RedrawPlayfield_EM(boolean force_redraw)
737 boolean all_players_visible = checkIfAllPlayersAreVisible();
739 boolean draw_new_player_location = FALSE;
740 boolean quick_relocation = setup.quick_switch;
742 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
745 boolean game.set_centered_player = getSetCenteredPlayer_EM();
746 int game.centered_player_nr_next = getCenteredPlayerNr_EM();
749 int max_center_distance_player_nr =
750 getMaxCenterDistancePlayerNr(screen_x, screen_y);
752 int player_nr = game_em.last_moving_player;
754 int stepsize = TILEX / 8;
755 int offset = game.scroll_delay_value * TILEX;
756 int offset_x = offset;
757 int offset_y = offset;
758 int screen_x_old = screen_x;
759 int screen_y_old = screen_y;
763 if (game.set_centered_player)
765 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
767 /* switching to "all players" only possible if all players fit to screen */
768 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
770 game.centered_player_nr_next = game.centered_player_nr;
771 game.set_centered_player = FALSE;
774 /* do not switch focus to non-existing (or non-active) player */
775 if (game.centered_player_nr_next >= 0 &&
776 !ply[game.centered_player_nr_next].alive)
778 game.centered_player_nr_next = game.centered_player_nr;
779 game.set_centered_player = FALSE;
784 /* also allow focus switching when screen is scrolled to half tile */
786 if (!scrolling) /* screen currently aligned at tile position */
790 if (game.set_centered_player)
792 if (game.centered_player_nr != game.centered_player_nr_next)
795 game.centered_player_nr = game.centered_player_nr_next;
797 draw_new_player_location = TRUE;
800 game.set_centered_player = FALSE;
804 if (game.centered_player_nr == -1)
807 if (draw_new_player_location || offset == 0)
809 if (draw_new_player_location)
812 setScreenCenteredToAllPlayers(&sx, &sy);
817 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
818 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
820 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
821 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
827 sx = PLAYER_SCREEN_X(game.centered_player_nr);
828 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
831 if (draw_new_player_location && quick_relocation)
833 screen_x = VALID_SCREEN_X(sx);
834 screen_y = VALID_SCREEN_Y(sy);
835 screen_x_old = screen_x;
836 screen_y_old = screen_y;
844 if (draw_new_player_location && !quick_relocation)
847 unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
849 unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
851 int wait_delay_value = game_frame_delay_value;
852 int screen_xx = VALID_SCREEN_X(sx);
853 int screen_yy = VALID_SCREEN_Y(sy);
855 while (screen_x != screen_xx || screen_y != screen_yy)
857 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
858 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
859 int dxx = 0, dyy = 0;
861 if (dx == 0 && dy == 0) /* no scrolling needed at all */
866 if (ABS(screen_xx - screen_x) >= TILEX)
868 screen_x -= dx * TILEX;
869 dxx = dx * TILEX / 2;
873 screen_x = screen_xx;
877 if (ABS(screen_yy - screen_y) >= TILEY)
879 screen_y -= dy * TILEY;
880 dyy = dy * TILEY / 2;
884 screen_y = screen_yy;
891 if (ABS(screen_xx - screen_x) >= TILEX ||
892 ABS(screen_yy - screen_y) >= TILEY)
894 screen_x -= dx * TILEX;
895 screen_y -= dy * TILEY;
897 dxx = dx * TILEX / 2;
898 dyy = dy * TILEY / 2;
902 screen_x = screen_xx;
903 screen_y = screen_yy;
909 screen_x -= dx * TILEX;
910 screen_y -= dy * TILEY;
912 dxx += dx * TILEX / 2;
913 dyy += dy * TILEY / 2;
918 /* scroll in two steps of half tile size to make things smoother */
924 for (i = 0; i < MAX_PLAYERS; i++)
929 Delay(wait_delay_value);
931 /* scroll second step to align at full tile size */
941 for (i = 0; i < MAX_PLAYERS; i++)
946 Delay(wait_delay_value);
949 screen_x_old = screen_x;
950 screen_y_old = screen_y;
955 for (y = 0; y < MAX_BUF_YSIZE; y++)
957 for (x = 0; x < MAX_BUF_XSIZE; x++)
959 screentiles[y][x] = -1;
960 crumbled_state[y][x] = 0;
965 /* calculate new screen scrolling position, with regard to scroll delay */
966 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
967 sx - offset_x > screen_x ? sx - offset_x :
969 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
970 sy - offset_y > screen_y ? sy - offset_y :
974 printf("::: (%d, %d) => (%d, %d) [(%d, %d), (%d, %d)] [%d, %d] [%d / %d]\n",
975 screen_x_old, screen_y_old,
977 ply[max_center_distance_player_nr].oldx,
978 ply[max_center_distance_player_nr].x,
979 ply[max_center_distance_player_nr].oldy,
980 ply[max_center_distance_player_nr].y,
982 ABS(screen_x - screen_x_old),
983 ABS(screen_y - screen_y_old));
989 /* prevent scrolling further than double player step size when scrolling */
990 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
992 int dx = SIGN(screen_x - screen_x_old);
994 screen_x = screen_x_old + dx * 2 * stepsize;
996 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
998 int dy = SIGN(screen_y - screen_y_old);
1000 screen_y = screen_y_old + dy * 2 * stepsize;
1003 /* prevent scrolling further than double player step size when scrolling */
1004 if (ABS(screen_x - screen_x_old) > 2 * stepsize ||
1005 ABS(screen_y - screen_y_old) > 2 * stepsize)
1007 int dx = SIGN(screen_x - screen_x_old);
1008 int dy = SIGN(screen_y - screen_y_old);
1010 screen_x = screen_x_old + dx * 2 * stepsize;
1011 screen_y = screen_y_old + dy * 2 * stepsize;
1016 /* prevent scrolling further than player step size when scrolling */
1017 if (ABS(screen_x - screen_x_old) > stepsize ||
1018 ABS(screen_y - screen_y_old) > stepsize)
1020 int dx = SIGN(screen_x - screen_x_old);
1021 int dy = SIGN(screen_y - screen_y_old);
1023 screen_x = screen_x_old + dx * stepsize;
1024 screen_y = screen_y_old + dy * stepsize;
1028 /* prevent scrolling away from the other players when focus on all players */
1029 if (game.centered_player_nr == -1)
1032 /* check if all players are still visible with new scrolling position */
1033 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
1034 !checkIfAllPlayersAreVisible(screen_x, screen_y))
1036 /* reset horizontal scroll position to last value, if needed */
1037 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
1038 screen_x = screen_x_old;
1040 /* reset vertical scroll position to last value, if needed */
1041 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
1042 screen_y = screen_y_old;
1045 boolean all_players_visible = checkIfAllPlayersAreVisible();
1047 if (!all_players_visible)
1049 printf("::: not all players visible\n");
1051 screen_x = screen_x_old;
1052 screen_y = screen_y_old;
1057 /* prevent scrolling (for screen correcting) if no player is moving */
1058 if (!game_em.any_player_moving)
1060 screen_x = screen_x_old;
1061 screen_y = screen_y_old;
1065 /* prevent scrolling against the players move direction */
1067 int player_nr = game_em.last_moving_player;
1069 int player_nr = (game.centered_player_nr == -1 ?
1070 max_center_distance_player_nr : game.centered_player_nr);
1071 int player_move_dir = game_em.last_player_direction[player_nr];
1072 int dx = SIGN(screen_x - screen_x_old);
1073 int dy = SIGN(screen_y - screen_y_old);
1075 if ((dx < 0 && player_move_dir != MV_LEFT) ||
1076 (dx > 0 && player_move_dir != MV_RIGHT))
1077 screen_x = screen_x_old;
1079 if ((dy < 0 && player_move_dir != MV_UP) ||
1080 (dy > 0 && player_move_dir != MV_DOWN))
1081 screen_y = screen_y_old;
1086 for (i = 0; i < MAX_PLAYERS; i++)
1087 blitplayer(&ply[i]);
1098 void game_animscreen(void)
1100 RedrawPlayfield_EM(FALSE);
1103 void DrawGameDoorValues_EM()
1109 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1110 int key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1114 if (game.centered_player_nr == -1)
1122 for (i = 0; i < MAX_PLAYERS; i++)
1124 dynamite_state += ply[i].dynamite;
1125 key_state |= ply[i].keys;
1130 dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1131 key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1136 int player_nr = game.centered_player_nr;
1138 dynamite_state = ply[player_nr].dynamite;
1139 key_state = ply[player_nr].keys;
1144 DrawAllGameValues(lev.required, dynamite_state, lev.score,
1145 lev.time, key_state);
1147 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
1148 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);