X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame_em%2Fgraphics.c;h=398ae6e0e303254f319e69931debc5d4b8b0b291;hb=HEAD;hp=3d9649800fc49f31e9da3dce82c8a02750c561e1;hpb=d7bde1388f184dfb73b68c977917462e02f9b61f;p=rocksndiamonds.git diff --git a/src/game_em/graphics.c b/src/game_em/graphics.c index 3d964980..a3e941a5 100644 --- a/src/game_em/graphics.c +++ b/src/game_em/graphics.c @@ -25,12 +25,15 @@ #define VALID_SCREEN_Y(y) ((y) < MIN_SCREEN_Y ? MIN_SCREEN_Y : \ (y) > MAX_SCREEN_Y ? MAX_SCREEN_Y : (y)) -#define PLAYER_SCREEN_X(p) ((( frame) * ply[p].oldx + \ - (8 - frame) * ply[p].x) * TILEX / 8 \ - - ((SCR_FIELDX - 1) * TILEX) / 2) -#define PLAYER_SCREEN_Y(p) ((( frame) * ply[p].oldy + \ - (8 - frame) * ply[p].y) * TILEY / 8 \ - - ((SCR_FIELDY - 1) * TILEY) / 2) +#define PLAYER_POS_X(nr) (((7 - frame) * ply[nr].prev_x + \ + (1 + frame) * ply[nr].x) * TILEX / 8) +#define PLAYER_POS_Y(nr) (((7 - frame) * ply[nr].prev_y + \ + (1 + frame) * ply[nr].y) * TILEY / 8) + +#define PLAYER_SCREEN_X(nr) (PLAYER_POS_X(nr) - \ + (SCR_FIELDX - 1) * TILEX / 2) +#define PLAYER_SCREEN_Y(nr) (PLAYER_POS_Y(nr) - \ + (SCR_FIELDY - 1) * TILEY / 2) #define USE_EXTENDED_GRAPHICS_ENGINE 1 @@ -39,9 +42,23 @@ int frame; /* current screen frame */ int screen_x, screen_y; /* current scroll position */ /* tiles currently on screen */ -static int screentiles[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2]; +static int screen_tiles[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2]; static int crumbled_state[MAX_PLAYFIELD_WIDTH + 2][MAX_PLAYFIELD_HEIGHT + 2]; +/* graphic info for game objects/frames and players/actions/frames */ +struct GraphicInfo_EM graphic_info_em_object[GAME_TILE_MAX][8]; +struct GraphicInfo_EM graphic_info_em_player[MAX_PLAYERS][PLY_MAX][8]; + +static struct XY xy_topdown[] = +{ + { 0, -1 }, + { -1, 0 }, + { +1, 0 }, + { 0, +1 } +}; + +static void setScreenCenteredToAllPlayers(int *, int *); + int getFieldbufferOffsetX_EM(void) { return screen_x % TILEX; @@ -66,48 +83,44 @@ void BlitScreenToBitmap_EM(Bitmap *target_bitmap) int sy = SY + (full_ysize < ysize ? (ysize - full_ysize) / 2 : 0); int sxsize = (full_xsize < xsize ? full_xsize : xsize); int sysize = (full_ysize < ysize ? full_ysize : ysize); + int xxsize = MAX_BUF_XSIZE * TILEX - x; + int yysize = MAX_BUF_YSIZE * TILEY - y; + int xoffset = 2 * CAVE_BUFFER_XOFFSET * TILEX; + int yoffset = 2 * CAVE_BUFFER_YOFFSET * TILEY; - if (x < 2 * TILEX && y < 2 * TILEY) + if (x < xoffset && y < yoffset) { - BlitBitmap(screenBitmap, target_bitmap, x, y, - sxsize, sysize, sx, sy); + BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, sysize, + sx, sy); } - else if (x < 2 * TILEX && y >= 2 * TILEY) + else if (x < xoffset && y >= yoffset) { - BlitBitmap(screenBitmap, target_bitmap, x, y, - sxsize, MAX_BUF_YSIZE * TILEY - y, + BlitBitmap(screenBitmap, target_bitmap, x, y, sxsize, yysize, sx, sy); - BlitBitmap(screenBitmap, target_bitmap, x, 0, - sxsize, y - 2 * TILEY, - sx, sy + MAX_BUF_YSIZE * TILEY - y); + BlitBitmap(screenBitmap, target_bitmap, x, 0, sxsize, y - yoffset, + sx, sy + yysize); } - else if (x >= 2 * TILEX && y < 2 * TILEY) + else if (x >= xoffset && y < yoffset) { - BlitBitmap(screenBitmap, target_bitmap, x, y, - MAX_BUF_XSIZE * TILEX - x, sysize, + BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, sysize, sx, sy); - BlitBitmap(screenBitmap, target_bitmap, 0, y, - x - 2 * TILEX, sysize, - sx + MAX_BUF_XSIZE * TILEX - x, sy); + BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, sysize, + sx + xxsize, sy); } else { - BlitBitmap(screenBitmap, target_bitmap, x, y, - MAX_BUF_XSIZE * TILEX - x, MAX_BUF_YSIZE * TILEY - y, + BlitBitmap(screenBitmap, target_bitmap, x, y, xxsize, yysize, sx, sy); - BlitBitmap(screenBitmap, target_bitmap, 0, y, - x - 2 * TILEX, MAX_BUF_YSIZE * TILEY - y, - sx + MAX_BUF_XSIZE * TILEX - x, sy); - BlitBitmap(screenBitmap, target_bitmap, x, 0, - MAX_BUF_XSIZE * TILEX - x, y - 2 * TILEY, - sx, sy + MAX_BUF_YSIZE * TILEY - y); - BlitBitmap(screenBitmap, target_bitmap, 0, 0, - x - 2 * TILEX, y - 2 * TILEY, - sx + MAX_BUF_XSIZE * TILEX - x, sy + MAX_BUF_YSIZE * TILEY - y); + BlitBitmap(screenBitmap, target_bitmap, 0, y, x - xoffset, yysize, + sx + xxsize, sy); + BlitBitmap(screenBitmap, target_bitmap, x, 0, xxsize, y - yoffset, + sx, sy + yysize); + BlitBitmap(screenBitmap, target_bitmap, 0, 0, x - xoffset, y - yoffset, + sx + xxsize, sy + yysize); } } -void BackToFront_EM(void) +static void BackToFront_EM(void) { BlitBitmap(backbuffer, window, SX, SY, SXSIZE, SYSIZE, SX, SY); } @@ -118,7 +131,7 @@ static struct GraphicInfo_EM *getObjectGraphic(int x, int y) struct GraphicInfo_EM *g = &graphic_info_em_object[tile][frame]; if (!game.use_native_emc_graphics_engine) - getGraphicSourceObjectExt_EM(g, tile, 7 - frame, x - 2, y - 2); + getGraphicSourceObjectExt_EM(g, tile, frame, x - lev.left, y - lev.top); return g; } @@ -128,7 +141,7 @@ static struct GraphicInfo_EM *getPlayerGraphic(int player_nr, int anim) struct GraphicInfo_EM *g = &graphic_info_em_player[player_nr][anim][frame]; if (!game.use_native_emc_graphics_engine) - getGraphicSourcePlayerExt_EM(g, player_nr, anim, 7 - frame); + getGraphicSourcePlayerExt_EM(g, player_nr, anim, frame); return g; } @@ -296,19 +309,14 @@ static void animscreen(void) int x, y, i; int left = screen_x / TILEX; int top = screen_y / TILEY; - static int xy[4][2] = - { - { 0, -1 }, - { -1, 0 }, - { +1, 0 }, - { 0, +1 } - }; + struct XY *xy = xy_topdown; if (!game.use_native_emc_graphics_engine) - for (y = 2; y < CAVE_BUFFER_HEIGHT - 2; y++) - for (x = 2; x < CAVE_BUFFER_WIDTH - 2; x++) + for (y = lev.top; y < lev.bottom; y++) + for (x = lev.left; x < lev.right; x++) SetGfxAnimation_EM(&graphic_info_em_object[lev.draw[x][y]][frame], - lev.draw[x][y], 7 - frame, x - 2, y - 2); + lev.draw[x][y], frame, + x - lev.left, y - lev.top); for (y = top; y < top + MAX_BUF_YSIZE; y++) { @@ -327,8 +335,8 @@ static void animscreen(void) { for (i = 0; i < 4; i++) { - int xx = x + xy[i][0]; - int yy = y + xy[i][1]; + int xx = x + xy[i].x; + int yy = y + xy[i].y; int tile_next; if (xx < 0 || xx >= CAVE_BUFFER_WIDTH || @@ -342,7 +350,7 @@ static void animscreen(void) } } - redraw_screen_tile = (screentiles[sx][sy] != obj || + redraw_screen_tile = (screen_tiles[sx][sy] != obj || crumbled_state[sx][sy] != crm); /* only redraw screen tiles if they (or their crumbled state) changed */ @@ -351,7 +359,7 @@ static void animscreen(void) DrawLevelField_EM(x, y, sx, sy, FALSE); DrawLevelFieldCrumbled_EM(x, y, sx, sy, crm, FALSE); - screentiles[sx][sy] = obj; + screen_tiles[sx][sy] = obj; crumbled_state[sx][sy] = crm; } } @@ -364,16 +372,16 @@ static void animscreen(void) * handles transparency and movement */ -static void blitplayer(struct PLAYER *ply) +static void blitplayer_ext(int nr) { int x1, y1, x2, y2; - if (!ply->alive) + if (!ply[nr].alive) return; /* x1/y1 are left/top and x2/y2 are right/down part of the player movement */ - x1 = (frame * ply->oldx + (8 - frame) * ply->x) * TILEX / 8; - y1 = (frame * ply->oldy + (8 - frame) * ply->y) * TILEY / 8; + x1 = PLAYER_POS_X(nr); + y1 = PLAYER_POS_Y(nr); x2 = x1 + TILEX - 1; y2 = y1 + TILEY - 1; @@ -381,10 +389,10 @@ static void blitplayer(struct PLAYER *ply) (int)(y2 - screen_y) < ((MAX_BUF_YSIZE - 1) * TILEY - 1)) { /* some casts to "int" are needed because of negative calculation values */ - int dx = (int)ply->x - (int)ply->oldx; - int dy = (int)ply->y - (int)ply->oldy; - int old_x = (int)ply->oldx + (7 - (int)frame) * dx / 8; - int old_y = (int)ply->oldy + (7 - (int)frame) * dy / 8; + int dx = (int)ply[nr].x - (int)ply[nr].prev_x; + int dy = (int)ply[nr].y - (int)ply[nr].prev_y; + int old_x = (int)ply[nr].prev_x + (int)frame * dx / 8; + int old_y = (int)ply[nr].prev_y + (int)frame * dy / 8; int new_x = old_x + SIGN(dx); int new_y = old_y + SIGN(dy); int old_sx = old_x % MAX_BUF_XSIZE; @@ -403,7 +411,7 @@ static void blitplayer(struct PLAYER *ply) DrawLevelFieldCrumbled_EM(new_x, new_y, new_sx, new_sy, new_crm, FALSE); /* draw the player (masked) over the element he is just digging away */ - DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, TRUE); + DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, TRUE); /* draw the field the player is moving from (masked over the player) */ DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE); @@ -411,7 +419,7 @@ static void blitplayer(struct PLAYER *ply) else { /* draw the player under the element which is on the same field */ - DrawLevelPlayer_EM(x1, y1, ply->num, ply->anim, FALSE); + DrawLevelPlayer_EM(x1, y1, ply[nr].num, ply[nr].anim, FALSE); /* draw the field the player is moving from (masked over the player) */ DrawLevelField_EM(old_x, old_y, old_sx, old_sy, TRUE); @@ -421,28 +429,66 @@ static void blitplayer(struct PLAYER *ply) } /* redraw screen tiles in the next frame (player may have left the tiles) */ - screentiles[old_sx][old_sy] = -1; - screentiles[new_sx][new_sy] = -1; + screen_tiles[old_sx][old_sy] = -1; + screen_tiles[new_sx][new_sy] = -1; + } +} + +static void blitplayer(int nr) +{ + blitplayer_ext(nr); + + /* check for wrap-around movement ... */ + if (ply[nr].x < lev.left || + ply[nr].x > lev.right - 1) + { + struct PLAYER ply_last = ply[nr]; + int direction = (ply[nr].x < lev.left ? -1 : 1); + int dx = ply[nr].x - ply[nr].prev_x; + + ply[nr].x += -direction * lev.width; + ply[nr].prev_x = ply[nr].x - dx; + + if (!lev.infinite_true) + { + int dy = ply[nr].y - ply[nr].prev_y; + + ply[nr].y += direction; + ply[nr].prev_y = ply[nr].y - dy; + } + + /* draw player entering playfield from the opposite side */ + blitplayer_ext(nr); + + /* ... but keep the old player position until game logic */ + ply[nr] = ply_last; } } void game_initscreen(void) { - int player_nr; - int x,y; + int x, y, sx, sy; - frame = 6; + frame = 1; - player_nr = (game.centered_player_nr != -1 ? game.centered_player_nr : 0); + if (game.centered_player_nr == -1) + { + setScreenCenteredToAllPlayers(&sx, &sy); + } + else + { + sx = PLAYER_SCREEN_X(game.centered_player_nr); + sy = PLAYER_SCREEN_Y(game.centered_player_nr); + } - screen_x = VALID_SCREEN_X(PLAYER_SCREEN_X(player_nr)); - screen_y = VALID_SCREEN_Y(PLAYER_SCREEN_Y(player_nr)); + screen_x = VALID_SCREEN_X(sx); + screen_y = VALID_SCREEN_Y(sy); for (y = 0; y < MAX_BUF_YSIZE; y++) { for (x = 0; x < MAX_BUF_XSIZE; x++) { - screentiles[x][y] = -1; + screen_tiles[x][y] = -1; crumbled_state[x][y] = 0; } } @@ -509,11 +555,13 @@ static void setMinimalPlayerBoundaries(int *sx1, int *sy1, int *sx2, int *sy2) boolean checkIfAllPlayersFitToScreen(void) { int sx1 = 0, sy1 = 0, sx2 = 0, sy2 = 0; + int scr_fieldx = getScreenFieldSizeX(); + int scr_fieldy = getScreenFieldSizeY(); setMinimalPlayerBoundaries(&sx1, &sy1, &sx2, &sy2); - return (sx2 - sx1 <= SCR_FIELDX * TILEX && - sy2 - sy1 <= SCR_FIELDY * TILEY); + return (sx2 - sx1 <= scr_fieldx * TILEX && + sy2 - sy1 <= scr_fieldy * TILEY); } static void setScreenCenteredToAllPlayers(int *sx, int *sy) @@ -550,6 +598,7 @@ static boolean checkIfAllPlayersAreVisible(int center_x, int center_y) void RedrawPlayfield_EM(boolean force_redraw) { boolean draw_new_player_location = FALSE; + boolean draw_new_player_location_wrap = FALSE; boolean quick_relocation = setup.quick_switch; int max_center_distance_player_nr = getMaxCenterDistancePlayerNr(screen_x, screen_y); @@ -588,9 +637,11 @@ void RedrawPlayfield_EM(boolean force_redraw) game.centered_player_nr = game.centered_player_nr_next; draw_new_player_location = TRUE; + draw_new_player_location_wrap = game.set_centered_player_wrap; force_redraw = TRUE; game.set_centered_player = FALSE; + game.set_centered_player_wrap = FALSE; } if (game.centered_player_nr == -1) @@ -621,11 +672,25 @@ void RedrawPlayfield_EM(boolean force_redraw) if (draw_new_player_location && !quick_relocation) { - unsigned int game_frame_delay_value = getGameFrameDelay_EM(20); - int wait_delay_value = game_frame_delay_value; + unsigned int frame_delay_value_old = GetVideoFrameDelay(); + int wait_delay_value = frame_delay_value_old; int screen_xx = VALID_SCREEN_X(sx); int screen_yy = VALID_SCREEN_Y(sy); + if (draw_new_player_location_wrap) + { + if (lev.infinite_true) + { + // when wrapping around (horizontally), keep vertical player position + screen_yy = screen_y; + } + + // scrolling for wrapping should be faster than for switching players + wait_delay_value /= 4; + } + + SetVideoFrameDelay(wait_delay_value); + while (screen_x != screen_xx || screen_y != screen_yy) { int dx = (screen_xx < screen_x ? +1 : screen_xx > screen_x ? -1 : 0); @@ -664,13 +729,11 @@ void RedrawPlayfield_EM(boolean force_redraw) animscreen(); for (i = 0; i < MAX_PLAYERS; i++) - blitplayer(&ply[i]); + blitplayer(i); BlitScreenToBitmap_EM(backbuffer); BackToFront_EM(); - Delay(wait_delay_value); - /* scroll second step to align at full tile size */ screen_x -= dxx; screen_y -= dyy; @@ -678,14 +741,14 @@ void RedrawPlayfield_EM(boolean force_redraw) animscreen(); for (i = 0; i < MAX_PLAYERS; i++) - blitplayer(&ply[i]); + blitplayer(i); BlitScreenToBitmap_EM(backbuffer); BackToFront_EM(); - - Delay(wait_delay_value); } + SetVideoFrameDelay(frame_delay_value_old); + screen_x_old = screen_x; screen_y_old = screen_y; } @@ -696,7 +759,7 @@ void RedrawPlayfield_EM(boolean force_redraw) { for (x = 0; x < MAX_BUF_XSIZE; x++) { - screentiles[x][y] = -1; + screen_tiles[x][y] = -1; crumbled_state[x][y] = 0; } } @@ -772,5 +835,5 @@ void RedrawPlayfield_EM(boolean force_redraw) animscreen(); for (i = 0; i < MAX_PLAYERS; i++) - blitplayer(&ply[i]); + blitplayer(i); }