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(tile, frame, &g->bitmap, &g->src_x, &g->src_y,
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(player_nr, anim, frame,
164 &g->bitmap, &g->src_x, &g->src_y);
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 */
223 for (i = 0; i < 4; i++)
227 int width, height, cx, cy;
229 if (i == 1 || i == 2)
231 width = g->crumbled_border_size;
233 cx = (i == 2 ? TILEX - g->crumbled_border_size : 0);
239 height = g->crumbled_border_size;
241 cy = (i == 3 ? TILEY - g->crumbled_border_size : 0);
244 if (width > 0 && height > 0)
246 int src_x = g->crumbled_src_x + cx;
247 int src_y = g->crumbled_src_y + cy;
248 int dst_x = sx * TILEX + cx;
249 int dst_y = sy * TILEY + cy;
253 SetClipOrigin(g->crumbled_bitmap, g->crumbled_bitmap->stored_clip_gc,
254 dst_x - src_x, dst_y - src_y);
255 BlitBitmapMasked(g->crumbled_bitmap, screenBitmap,
256 src_x, src_y, width, height, dst_x, dst_y);
259 BlitBitmap(g->crumbled_bitmap, screenBitmap,
260 src_x, src_y, width, height, dst_x, dst_y);
266 static void DrawLevelPlayer_EM(int x1, int y1, int player_nr, int anim,
269 struct GraphicInfo_EM *g = getPlayerGraphic(player_nr, anim);
270 int src_x = g->src_x, src_y = g->src_y;
273 /* do not draw fields that are outside the visible screen area */
274 if (x1 < screen_x - TILEX || x1 >= screen_x + MAX_BUF_XSIZE * TILEX ||
275 y1 < screen_y - TILEY || y1 >= screen_y + MAX_BUF_YSIZE * TILEY)
278 x1 %= MAX_BUF_XSIZE * TILEX;
279 y1 %= MAX_BUF_YSIZE * TILEY;
283 /* draw the player to current location */
286 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
287 dst_x - src_x, dst_y - src_y);
288 BlitBitmapMasked(g->bitmap, screenBitmap,
289 src_x, src_y, TILEX, TILEY, dst_x, dst_y);
291 /* draw the player to opposite wrap-around column */
292 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
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);
299 /* draw the player to opposite wrap-around row */
301 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
302 SetClipOrigin(g->bitmap, g->bitmap->stored_clip_gc,
303 dst_x - src_x, dst_y - src_y);
304 BlitBitmapMasked(g->bitmap, screenBitmap,
305 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
309 /* draw the player to current location */
312 BlitBitmap(g->bitmap, screenBitmap,
313 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
315 /* draw the player to opposite wrap-around column */
316 dst_x = x1 - MAX_BUF_XSIZE * TILEX;
318 BlitBitmap(g->bitmap, screenBitmap,
319 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
321 /* draw the player to opposite wrap-around row */
323 dst_y = y1 - MAX_BUF_YSIZE * TILEY;
324 BlitBitmap(g->bitmap, screenBitmap,
325 g->src_x, g->src_y, TILEX, TILEY, dst_x, dst_y);
329 /* draw differences between game tiles and screen tiles
331 * implicitly handles scrolling and restoring background under the sprites
334 static void animscreen(void)
337 int left = screen_x / TILEX;
338 int top = screen_y / TILEY;
339 static int xy[4][2] =
347 if (!game.use_native_emc_graphics_engine)
348 for (y = 2; y < EM_MAX_CAVE_HEIGHT - 2; y++)
349 for (x = 2; x < EM_MAX_CAVE_WIDTH - 2; x++)
350 SetGfxAnimation_EM(Draw[y][x], frame, x - 2, y - 2);
352 for (y = top; y < top + MAX_BUF_YSIZE; y++)
354 for (x = left; x < left + MAX_BUF_XSIZE; x++)
356 int sx = x % MAX_BUF_XSIZE;
357 int sy = y % MAX_BUF_YSIZE;
358 int tile = Draw[y][x];
359 struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame];
360 int obj = g->unique_identifier;
362 boolean redraw_screen_tile = FALSE;
364 /* re-calculate crumbled state of this tile */
365 if (g->has_crumbled_graphics)
367 for (i = 0; i < 4; i++)
369 int xx = x + xy[i][0];
370 int yy = y + xy[i][1];
373 if (xx < 0 || xx >= EM_MAX_CAVE_WIDTH ||
374 yy < 0 || yy >= EM_MAX_CAVE_HEIGHT)
377 tile_next = Draw[yy][xx];
379 if (!graphic_info_em_object[tile_next][frame].has_crumbled_graphics)
384 redraw_screen_tile = (screentiles[sy][sx] != obj ||
385 crumbled_state[sy][sx] != crm);
387 /* !!! TEST ONLY -- CHANGE THIS !!! */
388 if (!game.use_native_emc_graphics_engine)
389 redraw_screen_tile = TRUE;
391 /* only redraw screen tiles if they (or their crumbled state) changed */
392 if (redraw_screen_tile)
394 DrawLevelField_EM(x, y, sx, sy, FALSE);
395 DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE);
397 screentiles[sy][sx] = obj;
398 crumbled_state[sy][sx] = crm;
400 redraw[sx][sy] = TRUE;
408 /* blit players to the screen
410 * handles transparency and movement
413 static void blitplayer(struct PLAYER *ply)
420 /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */
421 x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8;
422 y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8;
426 if ((int)(x2 - screen_x) < ((MAX_BUF_XSIZE - 1) * TILEX - 1) &&
427 (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1))
429 /* some casts to "int" are needed because of negative calculation values */
430 int dx = (int)ply->x - (int)ply->oldx;
431 int dy = (int)ply->y - (int)ply->oldy;
432 int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8;
433 int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8;
434 int new_x = old_x + SIGN(dx);
435 int new_y = old_y + SIGN(dy);
436 int old_sx = old_x % MAX_BUF_XSIZE;
437 int old_sy = old_y % MAX_BUF_XSIZE;
438 int new_sx = new_x % MAX_BUF_XSIZE;
439 int new_sy = new_y % MAX_BUF_XSIZE;
441 int old_crm = crumbled_state[old_sy][old_sx];
443 int new_crm = crumbled_state[new_sy][new_sx];
445 /* only diggable elements can be crumbled in the classic EM engine */
446 boolean player_is_digging = (new_crm != 0);
449 x1 %= MAX_BUF_XSIZE * TILEX;
450 y1 %= MAX_BUF_YSIZE * TILEY;
451 x2 %= MAX_BUF_XSIZE * TILEX;
452 y2 %= MAX_BUF_YSIZE * TILEY;
455 if (player_is_digging)
458 /* draw the field the player is moving from (under the player) */
459 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, FALSE);
460 DrawLevelFieldCrumbled_EM(old_x, old_y, old_sx, old_sy, old_crm, FALSE);
463 /* draw the field the player is moving to (under the player) */
464 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, FALSE);
465 DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE);
467 /* draw the player (masked) over the element he is just digging away */
468 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE);
471 /* draw the field the player is moving from (masked over the player) */
472 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
477 /* draw the player under the element which is on the same field */
478 DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE);
480 /* draw the field the player is moving from (masked over the player) */
481 DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE);
483 /* draw the field the player is moving to (masked over the player) */
484 DrawLevelField_EM(new_x, new_y, new_sx, new_sy, TRUE);
487 /* redraw screen tiles in the next frame (player may have left the tiles) */
488 screentiles[old_sy][old_sx] = -1;
489 screentiles[new_sy][new_sx] = -1;
491 /* mark screen tiles as dirty (force screen refresh with changed content) */
492 redraw[old_sx][old_sy] = TRUE;
493 redraw[new_sx][new_sy] = TRUE;
498 void game_initscreen(void)
501 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
502 int all_keys_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
508 game.centered_player_nr = getCenteredPlayerNr_EM();
511 player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0);
513 screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr));
514 screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr));
516 for (y = 0; y < MAX_BUF_YSIZE; y++)
518 for (x = 0; x < MAX_BUF_XSIZE; x++)
520 screentiles[y][x] = -1;
521 crumbled_state[y][x] = 0;
525 DrawAllGameValues(lev.required, dynamite_state, lev.score,
526 lev.time, all_keys_state);
530 void DrawRelocatePlayer(struct PlayerInfo *player, boolean quick_relocation)
532 boolean ffwd_delay = (tape.playing && tape.fast_forward);
533 boolean no_delay = (tape.warp_forward);
534 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
535 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
539 if (quick_relocation)
541 int offset = game.scroll_delay_value;
543 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
545 scroll_x = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
546 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
547 player->jx - MIDPOSX);
549 scroll_y = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
550 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
551 player->jy - MIDPOSY);
555 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
556 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
557 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
559 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
560 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
561 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
563 /* don't scroll over playfield boundaries */
564 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
565 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
567 /* don't scroll over playfield boundaries */
568 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
569 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
572 RedrawPlayfield(TRUE, 0,0,0,0);
576 int scroll_xx = -999, scroll_yy = -999;
578 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
580 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
583 int fx = FX, fy = FY;
585 scroll_xx = (player->jx < SBX_Left + MIDPOSX ? SBX_Left :
586 player->jx > SBX_Right + MIDPOSX ? SBX_Right :
587 player->jx - MIDPOSX);
589 scroll_yy = (player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
590 player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
591 player->jy - MIDPOSY);
593 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
594 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
596 if (dx == 0 && dy == 0) /* no scrolling needed at all */
602 fx += dx * TILEX / 2;
603 fy += dy * TILEY / 2;
608 /* scroll in two steps of half tile size to make things smoother */
609 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
611 Delay(wait_delay_value);
613 /* scroll second step to align at full tile size */
615 Delay(wait_delay_value);
620 Delay(wait_delay_value);
625 static int getMaxCenterDistancePlayerNr(int center_x, int center_y)
627 int max_dx = 0, max_dy = 0;
628 int player_nr = game_em.last_moving_player;
631 for (i = 0; i < MAX_PLAYERS; i++)
635 int sx = PLAYER_SCREEN_X(i);
636 int sy = PLAYER_SCREEN_Y(i);
638 if (game_em.last_player_direction[i] != MV_NONE &&
639 (ABS(sx - center_x) > max_dx ||
640 ABS(sy - center_y) > max_dy))
642 max_dx = MAX(max_dx, ABS(sx - center_x));
643 max_dy = MAX(max_dy, ABS(sy - center_y));
653 static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2)
655 boolean num_checked_players = 0;
658 for (i = 0; i < MAX_PLAYERS; i++)
662 int sx = PLAYER_SCREEN_X(i);
663 int sy = PLAYER_SCREEN_Y(i);
665 if (num_checked_players == 0)
672 *sx1 = MIN(*sx1, sx);
673 *sy1 = MIN(*sy1, sy);
674 *sx2 = MAX(*sx2, sx);
675 *sy2 = MAX(*sy2, sy);
678 num_checked_players++;
683 boolean checkIfAllPlayersFitToScreen()
685 int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0;
687 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
689 return (sx2 - sx1 <= SCR_FIELDX * TILEX &&
690 sy2 - sy1 <= SCR_FIELDY * TILEY);
693 static void setScreenCenteredToAllPlayers(int *sx, int *sy)
695 int sx1 = screen_x, sy1 = screen_y, sx2 = screen_x, sy2 = screen_y;
697 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
699 *sx = (sx1 + sx2) / 2;
700 *sy = (sy1 + sy2) / 2;
703 static void setMaxCenterDistanceForAllPlayers(int *max_dx, int *max_dy,
704 int center_x, int center_y)
706 int sx1 = center_x, sy1 = center_y, sx2 = center_x, sy2 = center_y;
708 setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2);
710 *max_dx = MAX(ABS(sx1 - center_x), ABS(sx2 - center_x));
711 *max_dy = MAX(ABS(sy1 - center_y), ABS(sy2 - center_y));
714 static boolean checkIfAllPlayersAreVisible(int center_x, int center_y)
718 setMaxCenterDistanceForAllPlayers(&max_dx, &max_dy, center_x, center_y);
720 return (max_dx <= SCR_FIELDX * TILEX / 2 &&
721 max_dy <= SCR_FIELDY * TILEY / 2);
724 void RedrawPlayfield_EM(boolean force_redraw)
727 boolean all_players_visible = checkIfAllPlayersAreVisible();
729 boolean draw_new_player_location = FALSE;
730 boolean quick_relocation = setup.quick_switch;
732 boolean scrolling = (screen_x % TILEX != 0 || screen_y % TILEY != 0);
735 boolean game.set_centered_player = getSetCenteredPlayer_EM();
736 int game.centered_player_nr_next = getCenteredPlayerNr_EM();
739 int max_center_distance_player_nr =
740 getMaxCenterDistancePlayerNr(screen_x, screen_y);
742 int player_nr = game_em.last_moving_player;
744 int stepsize = TILEX / 8;
745 int offset = game.scroll_delay_value * TILEX;
746 int offset_x = offset;
747 int offset_y = offset;
748 int screen_x_old = screen_x;
749 int screen_y_old = screen_y;
753 if (game.set_centered_player)
755 boolean all_players_fit_to_screen = checkIfAllPlayersFitToScreen();
757 /* switching to "all players" only possible if all players fit to screen */
758 if (game.centered_player_nr_next == -1 && !all_players_fit_to_screen)
760 game.centered_player_nr_next = game.centered_player_nr;
761 game.set_centered_player = FALSE;
764 /* do not switch focus to non-existing (or non-active) player */
765 if (game.centered_player_nr_next >= 0 &&
766 !ply[game.centered_player_nr_next].alive)
768 game.centered_player_nr_next = game.centered_player_nr;
769 game.set_centered_player = FALSE;
774 /* also allow focus switching when screen is scrolled to half tile */
776 if (!scrolling) /* screen currently aligned at tile position */
780 if (game.set_centered_player)
782 if (game.centered_player_nr != game.centered_player_nr_next)
785 game.centered_player_nr = game.centered_player_nr_next;
787 draw_new_player_location = TRUE;
790 game.set_centered_player = FALSE;
794 if (game.centered_player_nr == -1)
797 if (draw_new_player_location || offset == 0)
799 if (draw_new_player_location)
802 setScreenCenteredToAllPlayers(&sx, &sy);
807 sx = PLAYER_SCREEN_X(max_center_distance_player_nr);
808 sy = PLAYER_SCREEN_Y(max_center_distance_player_nr);
810 sx = PLAYER_SCREEN_X(game_em.last_moving_player);
811 sy = PLAYER_SCREEN_Y(game_em.last_moving_player);
817 sx = PLAYER_SCREEN_X(game.centered_player_nr);
818 sy = PLAYER_SCREEN_Y(game.centered_player_nr);
821 if (draw_new_player_location && quick_relocation)
823 screen_x = VALID_SCREEN_X(sx);
824 screen_y = VALID_SCREEN_Y(sy);
825 screen_x_old = screen_x;
826 screen_y_old = screen_y;
834 if (draw_new_player_location && !quick_relocation)
837 unsigned long game_frame_delay_value = getGameFrameDelay_EM(20);
839 unsigned long game_frame_delay_value = getGameFrameDelay_EM(25);
841 int wait_delay_value = game_frame_delay_value;
842 int screen_xx = VALID_SCREEN_X(sx);
843 int screen_yy = VALID_SCREEN_Y(sy);
845 while (screen_x != screen_xx || screen_y != screen_yy)
847 int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0);
848 int dy = (screen_yy < screen_y ? +1 : screen_yy > screen_y ? -1 : 0);
849 int dxx = 0, dyy = 0;
851 if (dx == 0 && dy == 0) /* no scrolling needed at all */
856 if (ABS(screen_xx - screen_x) >= TILEX)
858 screen_x -= dx * TILEX;
859 dxx = dx * TILEX / 2;
863 screen_x = screen_xx;
867 if (ABS(screen_yy - screen_y) >= TILEY)
869 screen_y -= dy * TILEY;
870 dyy = dy * TILEY / 2;
874 screen_y = screen_yy;
881 if (ABS(screen_xx - screen_x) >= TILEX ||
882 ABS(screen_yy - screen_y) >= TILEY)
884 screen_x -= dx * TILEX;
885 screen_y -= dy * TILEY;
887 dxx = dx * TILEX / 2;
888 dyy = dy * TILEY / 2;
892 screen_x = screen_xx;
893 screen_y = screen_yy;
899 screen_x -= dx * TILEX;
900 screen_y -= dy * TILEY;
902 dxx += dx * TILEX / 2;
903 dyy += dy * TILEY / 2;
908 /* scroll in two steps of half tile size to make things smoother */
914 for (i = 0; i < MAX_PLAYERS; i++)
919 Delay(wait_delay_value);
921 /* scroll second step to align at full tile size */
931 for (i = 0; i < MAX_PLAYERS; i++)
936 Delay(wait_delay_value);
939 screen_x_old = screen_x;
940 screen_y_old = screen_y;
945 for (y = 0; y < MAX_BUF_YSIZE; y++)
947 for (x = 0; x < MAX_BUF_XSIZE; x++)
949 screentiles[y][x] = -1;
950 crumbled_state[y][x] = 0;
955 /* calculate new screen scrolling position, with regard to scroll delay */
956 screen_x = VALID_SCREEN_X(sx + offset_x < screen_x ? sx + offset_x :
957 sx - offset_x > screen_x ? sx - offset_x :
959 screen_y = VALID_SCREEN_Y(sy + offset_y < screen_y ? sy + offset_y :
960 sy - offset_y > screen_y ? sy - offset_y :
964 printf("::: (%d, %d) => (%d, %d) [(%d, %d), (%d, %d)] [%d, %d] [%d / %d]\n",
965 screen_x_old, screen_y_old,
967 ply[max_center_distance_player_nr].oldx,
968 ply[max_center_distance_player_nr].x,
969 ply[max_center_distance_player_nr].oldy,
970 ply[max_center_distance_player_nr].y,
972 ABS(screen_x - screen_x_old),
973 ABS(screen_y - screen_y_old));
979 /* prevent scrolling further than double player step size when scrolling */
980 if (ABS(screen_x - screen_x_old) > 2 * stepsize)
982 int dx = SIGN(screen_x - screen_x_old);
984 screen_x = screen_x_old + dx * 2 * stepsize;
986 if (ABS(screen_y - screen_y_old) > 2 * stepsize)
988 int dy = SIGN(screen_y - screen_y_old);
990 screen_y = screen_y_old + dy * 2 * stepsize;
993 /* prevent scrolling further than double player step size when scrolling */
994 if (ABS(screen_x - screen_x_old) > 2 * stepsize ||
995 ABS(screen_y - screen_y_old) > 2 * stepsize)
997 int dx = SIGN(screen_x - screen_x_old);
998 int dy = SIGN(screen_y - screen_y_old);
1000 screen_x = screen_x_old + dx * 2 * stepsize;
1001 screen_y = screen_y_old + dy * 2 * stepsize;
1006 /* prevent scrolling further than player step size when scrolling */
1007 if (ABS(screen_x - screen_x_old) > stepsize ||
1008 ABS(screen_y - screen_y_old) > stepsize)
1010 int dx = SIGN(screen_x - screen_x_old);
1011 int dy = SIGN(screen_y - screen_y_old);
1013 screen_x = screen_x_old + dx * stepsize;
1014 screen_y = screen_y_old + dy * stepsize;
1018 /* prevent scrolling away from the other players when focus on all players */
1019 if (game.centered_player_nr == -1)
1022 /* check if all players are still visible with new scrolling position */
1023 if (checkIfAllPlayersAreVisible(screen_x_old, screen_y_old) &&
1024 !checkIfAllPlayersAreVisible(screen_x, screen_y))
1026 /* reset horizontal scroll position to last value, if needed */
1027 if (!checkIfAllPlayersAreVisible(screen_x, screen_y_old))
1028 screen_x = screen_x_old;
1030 /* reset vertical scroll position to last value, if needed */
1031 if (!checkIfAllPlayersAreVisible(screen_x_old, screen_y))
1032 screen_y = screen_y_old;
1035 boolean all_players_visible = checkIfAllPlayersAreVisible();
1037 if (!all_players_visible)
1039 printf("::: not all players visible\n");
1041 screen_x = screen_x_old;
1042 screen_y = screen_y_old;
1047 /* prevent scrolling (for screen correcting) if no player is moving */
1048 if (!game_em.any_player_moving)
1050 screen_x = screen_x_old;
1051 screen_y = screen_y_old;
1055 /* prevent scrolling against the players move direction */
1057 int player_nr = game_em.last_moving_player;
1059 int player_nr = (game.centered_player_nr == -1 ?
1060 max_center_distance_player_nr : game.centered_player_nr);
1061 int player_move_dir = game_em.last_player_direction[player_nr];
1062 int dx = SIGN(screen_x - screen_x_old);
1063 int dy = SIGN(screen_y - screen_y_old);
1065 if ((dx < 0 && player_move_dir != MV_LEFT) ||
1066 (dx > 0 && player_move_dir != MV_RIGHT))
1067 screen_x = screen_x_old;
1069 if ((dy < 0 && player_move_dir != MV_UP) ||
1070 (dy > 0 && player_move_dir != MV_DOWN))
1071 screen_y = screen_y_old;
1076 for (i = 0; i < MAX_PLAYERS; i++)
1077 blitplayer(&ply[i]);
1088 void game_animscreen(void)
1090 RedrawPlayfield_EM(FALSE);
1093 void DrawGameDoorValues_EM()
1099 int dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1100 int key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1104 if (game.centered_player_nr == -1)
1112 for (i = 0; i < MAX_PLAYERS; i++)
1114 dynamite_state += ply[i].dynamite;
1115 key_state |= ply[i].keys;
1120 dynamite_state = ply[0].dynamite; /* !!! ONLY PLAYER 1 !!! */
1121 key_state = ply[0].keys | ply[1].keys | ply[2].keys | ply[3].keys;
1126 int player_nr = game.centered_player_nr;
1128 dynamite_state = ply[player_nr].dynamite;
1129 key_state = ply[player_nr].keys;
1134 DrawAllGameValues(lev.required, dynamite_state, lev.score,
1135 lev.time, key_state);
1137 DrawAllGameValues(lev.required, ply1.dynamite, lev.score,
1138 DISPLAY_TIME(lev.time), ply1.keys | ply2.keys);