From: Holger Schemel Date: Fri, 23 Mar 2018 22:19:59 +0000 (+0100) Subject: added centering levels that are smaller than the playfield (MM engine) X-Git-Tag: 4.1.0.0~11 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=14801844faf14be284c590b66f030c6bf7cea5c2;p=rocksndiamonds.git added centering levels that are smaller than the playfield (MM engine) --- diff --git a/src/game_mm/mm_game.c b/src/game_mm/mm_game.c index 0a9d2da6..7d22eb30 100644 --- a/src/game_mm/mm_game.c +++ b/src/game_mm/mm_game.c @@ -751,15 +751,18 @@ void InitGameActions_MM() void AddLaserEdge(int lx, int ly) { - if (lx < -2 || ly < -2 || lx >= SXSIZE + 2 || ly >= SYSIZE + 2) + int clx = dSX + lx; + int cly = dSY + ly; + + if (clx < -2 || cly < -2 || clx >= SXSIZE + 2 || cly >= SYSIZE + 2) { Error(ERR_WARN, "AddLaserEdge: out of bounds: %d, %d", lx, ly); return; } - laser.edge[laser.num_edges].x = SX + 2 + lx; - laser.edge[laser.num_edges].y = SY + 2 + ly; + laser.edge[laser.num_edges].x = cSX2 + lx; + laser.edge[laser.num_edges].y = cSY2 + ly; laser.num_edges++; laser.redraw = TRUE; @@ -781,8 +784,8 @@ boolean StepBehind() { int x = LX - XS; int y = LY - YS; - int last_x = laser.edge[laser.num_edges - 1].x - SX - 2; - int last_y = laser.edge[laser.num_edges - 1].y - SY - 2; + int last_x = laser.edge[laser.num_edges - 1].x - cSX2; + int last_y = laser.edge[laser.num_edges - 1].y - cSY2; return ((x - last_x) * XS < 0 || (y - last_y) * YS < 0); } @@ -860,8 +863,8 @@ int ScanPixel() } else { - pixel = (SX + px < REAL_SX || SX + px >= REAL_SX + FULL_SXSIZE || - SY + py < REAL_SY || SY + py >= REAL_SY + FULL_SYSIZE); + pixel = (cSX + px < REAL_SX || cSX + px >= REAL_SX + FULL_SXSIZE || + cSY + py < REAL_SY || cSY + py >= REAL_SY + FULL_SYSIZE); } if ((Sign[laser.current_angle] & (1 << i)) && pixel) @@ -1191,8 +1194,8 @@ void DrawLaserExt(int start_edge, int num_edges, int mode) if (start_edge == 0) laser.current_angle = laser.start_angle; - LX = laser.edge[start_edge].x - (SX + 2); - LY = laser.edge[start_edge].y - (SY + 2); + LX = laser.edge[start_edge].x - cSX2; + LY = laser.edge[start_edge].y - cSY2; XS = 2 * Step[laser.current_angle].x; YS = 2 * Step[laser.current_angle].y; @@ -2329,7 +2332,7 @@ void OpenSurpriseBall(int x, int y) getGraphicSource(graphic, 0, &bitmap, &gx, &gy); BlitBitmap(bitmap, drawto, gx + dx, gy + dy, 6, 6, - SX + x * TILEX + dx, SY + y * TILEY + dy); + cSX + x * TILEX + dx, cSY + y * TILEY + dy); MarkTileDirty(x, y); } @@ -2540,7 +2543,7 @@ static void Explode_MM(int x, int y, int phase, int mode) getGraphicSource(graphic, graphic_phase, &bitmap, &src_x, &src_y); BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY, - FX + x * TILEX, FY + y * TILEY); + cFX + x * TILEX, cFY + y * TILEY); MarkTileDirty(x, y); } @@ -2991,24 +2994,24 @@ boolean ObjHit(int obx, int oby, int bits) if (bits & HIT_POS_CENTER) { - if (CheckLaserPixel(SX + obx + 15, - SY + oby + 15)) + if (CheckLaserPixel(cSX + obx + 15, + cSY + oby + 15)) return TRUE; } if (bits & HIT_POS_EDGE) { for (i = 0; i < 4; i++) - if (CheckLaserPixel(SX + obx + 31 * (i % 2), - SY + oby + 31 * (i / 2))) + if (CheckLaserPixel(cSX + obx + 31 * (i % 2), + cSY + oby + 31 * (i / 2))) return TRUE; } if (bits & HIT_POS_BETWEEN) { for (i = 0; i < 4; i++) - if (CheckLaserPixel(SX + 4 + obx + 22 * (i % 2), - SY + 4 + oby + 22 * (i / 2))) + if (CheckLaserPixel(cSX + 4 + obx + 22 * (i % 2), + cSY + 4 + oby + 22 * (i / 2))) return TRUE; } @@ -3542,8 +3545,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) /* laser.num_edges--; - LX = laser.edge[laser.num_edges].x - (SX + 2); - LY = laser.edge[laser.num_edges].y - (SY + 2); + LX = laser.edge[laser.num_edges].x - cSX2; + LY = laser.edge[laser.num_edges].y - cSY2; */ for (i = (laser.num_damages > 0 ? laser.num_damages - 1 : 0); i >= 0; i--) @@ -3596,12 +3599,12 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) { if (laser.wall_mask & (1 << i)) { - if (CheckLaserPixel(SX + ELX * TILEX + 14 + (i % 2) * 2, - SY + ELY * TILEY + 31 * (i / 2))) + if (CheckLaserPixel(cSX + ELX * TILEX + 14 + (i % 2) * 2, + cSY + ELY * TILEY + 31 * (i / 2))) break; - if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2), - SY + ELY * TILEY + 14 + (i / 2) * 2)) + if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2), + cSY + ELY * TILEY + 14 + (i / 2) * 2)) break; } } @@ -3612,8 +3615,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) { if (laser.wall_mask & (1 << i)) { - if (CheckLaserPixel(SX + ELX * TILEX + 31 * (i % 2), - SY + ELY * TILEY + 31 * (i / 2))) + if (CheckLaserPixel(cSX + ELX * TILEX + 31 * (i % 2), + cSY + ELY * TILEY + 31 * (i / 2))) break; } } @@ -3622,8 +3625,8 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode) if (laser.num_beamers > 0 || k1 < 1 || k2 < 4 || k3 < 4 || - CheckLaserPixel(SX + ELX * TILEX + 14, - SY + ELY * TILEY + 14)) + CheckLaserPixel(cSX + ELX * TILEX + 14, + cSY + ELY * TILEY + 14)) { laser.num_edges = r; laser.num_damages = d; @@ -3838,8 +3841,8 @@ void MovePacMen() getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y); CT = FrameCounter; - ox = SX + ox * TILEX; - oy = SY + oy * TILEY; + ox = cSX + ox * TILEX; + oy = cSY + oy * TILEY; for (i = 1; i < 33; i += 2) BlitBitmap(bitmap, window, @@ -4336,8 +4339,8 @@ static int getAngleFromTouchDelta(int dx, int dy, int base) int getButtonFromTouchPosition(int x, int y, int dst_mx, int dst_my) { // calculate start (source) position to be at the middle of the tile - int src_mx = SX + x * TILESIZE_VAR + TILESIZE_VAR / 2; - int src_my = SY + y * TILESIZE_VAR + TILESIZE_VAR / 2; + int src_mx = cSX + x * TILESIZE_VAR + TILESIZE_VAR / 2; + int src_my = cSY + y * TILESIZE_VAR + TILESIZE_VAR / 2; int dx = dst_mx - src_mx; int dy = dst_my - src_my; int element; diff --git a/src/game_mm/mm_main.c b/src/game_mm/mm_main.c index 2209d092..7eafc2f5 100644 --- a/src/game_mm/mm_main.c +++ b/src/game_mm/mm_main.c @@ -31,6 +31,11 @@ struct LaserInfo laser; short LX,LY, XS,YS, ELX,ELY; short CT,Ct; +int dSX, dSY; +int cSX, cSY; +int cSX2, cSY2; +int cFX, cFY; + Pixel pen_fg, pen_bg, pen_ray, pen_magicolor[2]; int color_status; diff --git a/src/game_mm/mm_main.h b/src/game_mm/mm_main.h index 3322a57e..de3248ae 100644 --- a/src/game_mm/mm_main.h +++ b/src/game_mm/mm_main.h @@ -251,6 +251,11 @@ extern struct GlobalInfo global; extern short LX, LY, XS, YS, ELX, ELY; extern short CT, Ct; +extern int dSX, dSY; +extern int cSX, cSY; +extern int cSX2, cSY2; +extern int cFX, cFY; + extern Pixel pen_fg, pen_bg, pen_ray, pen_magicolor[2]; extern int color_status; @@ -264,10 +269,6 @@ extern char *element_info[]; extern int num_element_info; /* often used screen positions */ -#define SX 8 -#define SY 8 -#define REAL_SX (SX - 2) -#define REAL_SY (SY - 2) #define DX 534 #define DY 60 #define EX DX diff --git a/src/game_mm/mm_tools.c b/src/game_mm/mm_tools.c index 93ab8221..1a27d91a 100644 --- a/src/game_mm/mm_tools.c +++ b/src/game_mm/mm_tools.c @@ -17,11 +17,34 @@ #include "mm_tools.h" +void SetDrawtoField_MM(int mode) +{ + int full_xsize = lev_fieldx * TILESIZE_VAR; + int full_ysize = lev_fieldy * TILESIZE_VAR; + + // distance (delta) from screen border (SX/SY) to centered level playfield + dSX = (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0); + dSY = (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0); + + // for convenience, absolute screen position to centered level playfield + cSX = SX + dSX; + cSY = SY + dSY; + cSX2 = SX + dSX + 2; // including playfield border + cSY2 = SY + dSY + 2; // including playfield border + + if (mode == DRAW_TO_BACKBUFFER) + { + cFX = FX + dSX; + cFY = FY + dSY; + } +} + void ClearWindow() { ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE); - SetDrawtoField(DRAW_BACKBUFFER); + SetDrawtoField(DRAW_TO_BACKBUFFER); + SetDrawtoField_MM(DRAW_TO_BACKBUFFER); redraw_mask |= REDRAW_FIELD; } @@ -34,7 +57,7 @@ void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame) getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y); BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY, - FX + x * TILEX, FY + y * TILEY); + cFX + x * TILEX, cFY + y * TILEY); } void DrawGraphic_MM(int x, int y, int graphic) @@ -48,7 +71,7 @@ void DrawGraphic_MM(int x, int y, int graphic) } #endif - DrawGraphicExt_MM(drawto_field, FX + x*TILEX, FY + y*TILEY, graphic); + DrawGraphicExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY, graphic); MarkTileDirty(x, y); } @@ -74,7 +97,7 @@ void DrawGraphicThruMask_MM(int x, int y, int graphic) } #endif - DrawGraphicThruMaskExt_MM(drawto_field, FX + x * TILEX, FY + y * TILEY, + DrawGraphicThruMaskExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY, graphic); MarkTileDirty(x,y); @@ -96,7 +119,7 @@ void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y, void DrawMiniGraphic_MM(int x, int y, int graphic) { - DrawMiniGraphicExt_MM(drawto, SX + x * MINI_TILEX, SY + y * MINI_TILEY, + DrawMiniGraphicExt_MM(drawto, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY, graphic); MarkTileDirty(x / 2, y / 2); @@ -205,8 +228,8 @@ void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic, src_x += cx; src_y += cy; - dest_x = FX + x * TILEX + dx; - dest_y = FY + y * TILEY + dy; + dest_x = cFX + x * TILEX + dx; + dest_y = cFY + y * TILEY + dy; #if DEBUG if (!IN_SCR_FIELD(x,y)) @@ -432,8 +455,8 @@ void DrawWallsExt_MM(int x, int y, int element, int draw_mask) for (i = 0; i < 4; i++) { - int dest_x = SX + x * TILEX + MINI_TILEX * (i % 2); - int dest_y = SY + y * TILEY + MINI_TILEY * (i / 2); + int dest_x = cSX + x * TILEX + MINI_TILEX * (i % 2); + int dest_y = cSY + y * TILEY + MINI_TILEY * (i / 2); if (!((1 << i) & draw_mask)) continue; @@ -472,8 +495,8 @@ void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask) int frame; Bitmap *bitmap; int src_x, src_y; - int dst_x = SX + x * TILEX + (i % 2) * MINI_TILEX; - int dst_y = SY + y * TILEY + (i / 2) * MINI_TILEY; + int dst_x = cSX + x * TILEX + (i % 2) * MINI_TILEX; + int dst_y = cSY + y * TILEY + (i / 2) * MINI_TILEY; if (bit_mask & (1 << i)) { diff --git a/src/game_mm/mm_tools.h b/src/game_mm/mm_tools.h index d7a050de..3fdee2fb 100644 --- a/src/game_mm/mm_tools.h +++ b/src/game_mm/mm_tools.h @@ -16,10 +16,6 @@ #include "main_mm.h" -/* for SetDrawtoField */ -#define DRAW_DIRECT 0 -#define DRAW_BUFFERED 1 -#define DRAW_BACKBUFFER 2 /* for DrawElementShifted */ #define NO_CUTTING 0 diff --git a/src/tools.c b/src/tools.c index dc847065..695a5362 100644 --- a/src/tools.c +++ b/src/tools.c @@ -360,30 +360,26 @@ static int getLevelFromScreenY_SP(int sy) static int getLevelFromScreenX_MM(int sx) { -#if 0 int level_xsize = level.native_mm_level->fieldx; int full_xsize = level_xsize * TILESIZE_VAR; sx -= (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0); -#endif int px = sx - SX; - int lx = px / TILESIZE_VAR; + int lx = (px + TILESIZE_VAR) / TILESIZE_VAR - 1; return lx; } static int getLevelFromScreenY_MM(int sy) { -#if 0 int level_ysize = level.native_mm_level->fieldy; int full_ysize = level_ysize * TILESIZE_VAR; sy -= (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0); -#endif int py = sy - SY; - int ly = py / TILESIZE_VAR; + int ly = (py + TILESIZE_VAR) / TILESIZE_VAR - 1; return ly; }