X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=af0b7413103ef3c897535dbcdcc0af31be4e3d0e;hb=9cb181e05e485435ef48586dd4f2811ba1e672b3;hp=be311d801f790c1e62d5091c7e4acd9ca63b020a;hpb=cb8b58732432cc7f3163446dedd54c63126b23c3;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index be311d80..af0b7413 100644 --- a/src/game.c +++ b/src/game.c @@ -85,27 +85,38 @@ #define EX_TYPE_DYNA (1 << 4) #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER) +#if 1 +#define PANEL_DEACTIVATED(p) ((p)->x < 0 || (p)->y < 0) +#define PANEL_XPOS(p) (DX + ALIGNED_MENU_XPOS(p)) +#define PANEL_YPOS(p) (DY + ALIGNED_MENU_YPOS(p)) +#else #define PANEL_DEACTIVATED(p) ((p).x < 0 || (p).y < 0) +#define PANEL_XPOS(p) (ALIGNED_XPOS((p).x, (p).width, (p).align)) +#define PANEL_YPOS(p) ((p).y) +#endif /* special positions in the game control window (relative to control window) */ -#define XX_LEVEL1 (game.panel.level.x) -#define XX_LEVEL2 (game.panel.level.x - 1) -#define YY_LEVEL (game.panel.level.y) -#define XX_EMERALDS (game.panel.gems.x) -#define YY_EMERALDS (game.panel.gems.y) -#define XX_DYNAMITE (game.panel.inventory.x) -#define YY_DYNAMITE (game.panel.inventory.y) -#define XX_KEYS (game.panel.keys.x) -#define YY_KEYS (game.panel.keys.y) -#define XX_SCORE (game.panel.score.x) -#define YY_SCORE (game.panel.score.y) -#define XX_TIME1 (game.panel.time.x) -#define XX_TIME2 (game.panel.time.x + 1) -#define YY_TIME (game.panel.time.y) +#define XX_LEVEL1 (PANEL_XPOS(game.panel.level)) +#define XX_LEVEL2 (PANEL_XPOS(game.panel.level) - 1) +#define XX_LEVEL (PANEL_XPOS(game.panel.level)) +#define YY_LEVEL (PANEL_YPOS(game.panel.level)) +#define XX_EMERALDS (PANEL_XPOS(game.panel.gems)) +#define YY_EMERALDS (PANEL_YPOS(game.panel.gems)) +#define XX_DYNAMITE (PANEL_XPOS(game.panel.inventory)) +#define YY_DYNAMITE (PANEL_YPOS(game.panel.inventory)) +#define XX_KEYS (PANEL_XPOS(game.panel.keys)) +#define YY_KEYS (PANEL_YPOS(game.panel.keys)) +#define XX_SCORE (PANEL_XPOS(game.panel.score)) +#define YY_SCORE (PANEL_YPOS(game.panel.score)) +#define XX_TIME1 (PANEL_XPOS(game.panel.time)) +#define XX_TIME2 (PANEL_XPOS(game.panel.time) + 1) +#define XX_TIME (PANEL_XPOS(game.panel.time)) +#define YY_TIME (PANEL_YPOS(game.panel.time)) /* special positions in the game control window (relative to main window) */ #define DX_LEVEL1 (DX + XX_LEVEL1) #define DX_LEVEL2 (DX + XX_LEVEL2) +#define DX_LEVEL (DX + XX_LEVEL) #define DY_LEVEL (DY + YY_LEVEL) #define DX_EMERALDS (DX + XX_EMERALDS) #define DY_EMERALDS (DY + YY_EMERALDS) @@ -117,6 +128,7 @@ #define DY_SCORE (DY + YY_SCORE) #define DX_TIME1 (DX + XX_TIME1) #define DX_TIME2 (DX + XX_TIME2) +#define DX_TIME (DX + XX_TIME) #define DY_TIME (DY + YY_TIME) /* values for delayed check of falling and moving elements and for collision */ @@ -1317,65 +1329,195 @@ static inline void InitField_WithBug2(int x, int y, boolean init_game) */ } -inline void DrawGameValue_Emeralds(int value) +#if 1 + +void DrawGameValue_Emeralds(int value) { - int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2; + struct TextPosInfo *pos = &game.panel.gems; + int font_nr = FONT_TEXT_2; + int font_width = getFontWidth(font_nr); + int digits = pos->chars; - if (PANEL_DEACTIVATED(game.panel.gems)) + if (PANEL_DEACTIVATED(pos)) return; - DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2); + pos->width = digits * font_width; + + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); } -inline void DrawGameValue_Dynamite(int value) +void DrawGameValue_Dynamite(int value) { - int xpos = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2; + struct TextPosInfo *pos = &game.panel.inventory; + int font_nr = FONT_TEXT_2; + int font_width = getFontWidth(font_nr); + int digits = pos->chars; - if (PANEL_DEACTIVATED(game.panel.inventory)) + if (PANEL_DEACTIVATED(pos)) + return; + + pos->width = digits * font_width; + + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); +} + +void DrawGameValue_Score(int value) +{ + struct TextPosInfo *pos = &game.panel.score; + int font_nr = FONT_TEXT_2; + int font_width = getFontWidth(font_nr); + int digits = pos->chars; + + if (PANEL_DEACTIVATED(pos)) + return; + + pos->width = digits * font_width; + + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); +} + +void DrawGameValue_Time(int value) +{ + struct TextPosInfo *pos = &game.panel.time; + static int last_value = -1; + int digits1 = 3; + int digits2 = 4; + int digits = pos->chars; + int font1_nr = FONT_TEXT_2; + int font2_nr = FONT_TEXT_1; + int font_nr = font1_nr; + boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE); + + if (PANEL_DEACTIVATED(pos)) + return; + + if (use_dynamic_digits) /* use dynamic number of digits */ + { + digits = (value < 1000 ? digits1 : digits2); + font_nr = (value < 1000 ? font1_nr : font2_nr); + } + + /* clear background if value just changed its size (dynamic digits only) */ + if (use_dynamic_digits && (last_value < 1000) != (value < 1000)) + { + int width1 = digits1 * getFontWidth(font1_nr); + int width2 = digits2 * getFontWidth(font2_nr); + int max_width = MAX(width1, width2); + int max_height = MAX(getFontHeight(font1_nr), getFontHeight(font2_nr)); + + pos->width = max_width; + + ClearRectangleOnBackground(drawto, PANEL_XPOS(pos), PANEL_YPOS(pos), + max_width, max_height); + } + + pos->width = digits * getFontWidth(font_nr); + + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); + + last_value = value; +} + +void DrawGameValue_Level(int value) +{ + struct TextPosInfo *pos = &game.panel.level; + int digits1 = 2; + int digits2 = 3; + int digits = pos->chars; + int font1_nr = FONT_TEXT_2; + int font2_nr = FONT_TEXT_1; + int font_nr = font1_nr; + boolean use_dynamic_digits = (digits == -1 ? TRUE : FALSE); + + if (PANEL_DEACTIVATED(pos)) return; - DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2); + if (use_dynamic_digits) /* use dynamic number of digits */ + { + digits = (level_nr < 100 ? digits1 : digits2); + font_nr = (level_nr < 100 ? font1_nr : font2_nr); + } + + pos->width = digits * getFontWidth(font_nr); + + DrawText(PANEL_XPOS(pos), PANEL_YPOS(pos), int2str(value, digits), font_nr); } -inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) +void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) { + struct TextPosInfo *pos = &game.panel.keys; int base_key_graphic = EL_KEY_1; int i; - if (PANEL_DEACTIVATED(game.panel.keys)) + if (PANEL_DEACTIVATED(pos)) return; if (level.game_engine_type == GAME_ENGINE_TYPE_EM) base_key_graphic = EL_EM_KEY_1; + pos->width = 4 * MINI_TILEX; + /* currently only 4 of 8 possible keys are displayed */ for (i = 0; i < STD_NUM_KEYS; i++) { - int x = XX_KEYS + i * MINI_TILEX; - int y = YY_KEYS; + int src_x = DOOR_GFX_PAGEX5 + 18; + int src_y = DOOR_GFX_PAGEY1 + 123; + int dst_x = PANEL_XPOS(pos) + i * MINI_TILEX; + int dst_y = PANEL_YPOS(pos); if (key[i]) - DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i)); + DrawMiniGraphicExt(drawto, dst_x, dst_y, el2edimg(base_key_graphic + i)); else - BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, - DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y); + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, src_x, src_y, + MINI_TILEX, MINI_TILEY, dst_x, dst_y); } } -inline void DrawGameValue_Score(int value) +#else + +void DrawGameValue_Emeralds(int value) { - int xpos = (5 * 14 - 5 * getFontWidth(FONT_TEXT_2)) / 2; + int font_nr = FONT_TEXT_2; + int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2; + + if (PANEL_DEACTIVATED(game.panel.gems)) + return; + + DrawText(DX_EMERALDS + xpos, DY_EMERALDS, int2str(value, 3), font_nr); +} + +void DrawGameValue_Dynamite(int value) +{ + int font_nr = FONT_TEXT_2; + int xpos = (3 * 14 - 3 * getFontWidth(font_nr)) / 2; + + if (PANEL_DEACTIVATED(game.panel.inventory)) + return; + + DrawText(DX_DYNAMITE + xpos, DY_DYNAMITE, int2str(value, 3), font_nr); +} + +void DrawGameValue_Score(int value) +{ + int font_nr = FONT_TEXT_2; + int xpos = (5 * 14 - 5 * getFontWidth(font_nr)) / 2; if (PANEL_DEACTIVATED(game.panel.score)) return; - DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), FONT_TEXT_2); + DrawText(DX_SCORE + xpos, DY_SCORE, int2str(value, 5), font_nr); } -inline void DrawGameValue_Time(int value) +void DrawGameValue_Time(int value) { - int xpos3 = (3 * 14 - 3 * getFontWidth(FONT_TEXT_2)) / 2; - int xpos4 = (4 * 10 - 4 * getFontWidth(FONT_LEVEL_NUMBER)) / 2; + int font1_nr = FONT_TEXT_2; +#if 1 + int font2_nr = FONT_TEXT_1; +#else + int font2_nr = FONT_LEVEL_NUMBER; +#endif + int xpos3 = (3 * 14 - 3 * getFontWidth(font1_nr)) / 2; + int xpos4 = (4 * 10 - 4 * getFontWidth(font2_nr)) / 2; if (PANEL_DEACTIVATED(game.panel.time)) return; @@ -1385,22 +1527,56 @@ inline void DrawGameValue_Time(int value) ClearRectangleOnBackground(drawto, DX_TIME1, DY_TIME, 14 * 3, 14); if (value < 1000) - DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), FONT_TEXT_2); + DrawText(DX_TIME1 + xpos3, DY_TIME, int2str(value, 3), font1_nr); else - DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER); + DrawText(DX_TIME2 + xpos4, DY_TIME, int2str(value, 4), font2_nr); } -inline void DrawGameValue_Level(int value) +void DrawGameValue_Level(int value) { + int font1_nr = FONT_TEXT_2; +#if 1 + int font2_nr = FONT_TEXT_1; +#else + int font2_nr = FONT_LEVEL_NUMBER; +#endif + if (PANEL_DEACTIVATED(game.panel.level)) return; if (level_nr < 100) - DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), FONT_TEXT_2); + DrawText(DX_LEVEL1, DY_LEVEL, int2str(value, 2), font1_nr); else - DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), FONT_LEVEL_NUMBER); + DrawText(DX_LEVEL2, DY_LEVEL, int2str(value, 3), font2_nr); } +void DrawGameValue_Keys(int key[MAX_NUM_KEYS]) +{ + int base_key_graphic = EL_KEY_1; + int i; + + if (PANEL_DEACTIVATED(game.panel.keys)) + return; + + if (level.game_engine_type == GAME_ENGINE_TYPE_EM) + base_key_graphic = EL_EM_KEY_1; + + /* currently only 4 of 8 possible keys are displayed */ + for (i = 0; i < STD_NUM_KEYS; i++) + { + int x = XX_KEYS + i * MINI_TILEX; + int y = YY_KEYS; + + if (key[i]) + DrawMiniGraphicExt(drawto, DX + x,DY + y, el2edimg(base_key_graphic + i)); + else + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, + DOOR_GFX_PAGEX5 + x, y, MINI_TILEX, MINI_TILEY, DX + x,DY + y); + } +} + +#endif + void DrawAllGameValues(int emeralds, int dynamite, int score, int time, int key_bits) { @@ -10389,25 +10565,51 @@ static boolean AllPlayersInVisibleScreen() void ScrollLevel(int dx, int dy) { + int i, x, y; + + /* only horizontal XOR vertical scroll direction allowed */ + if ((dx == 0 && dy == 0) || (dx != 0 && dy != 0)) + return; + +#if 1 + int xsize = (BX2 - BX1 + 1); + int ysize = (BY2 - BY1 + 1); + int start = (dx != 0 ? (dx == -1 ? BX1 : BX2) : (dy == -1 ? BY1 : BY2)); + int end = (dx != 0 ? (dx == -1 ? BX2 : BX1) : (dy == -1 ? BY2 : BY1)); + int step = (start < end ? +1 : -1); + + for (i = start; i != end; i += step) + { + BlitBitmap(drawto_field, drawto_field, + FX + TILEX * (dx != 0 ? i + step : 0), + FY + TILEY * (dy != 0 ? i + step : 0), + TILEX * (dx != 0 ? 1 : xsize), + TILEY * (dy != 0 ? 1 : ysize), + FX + TILEX * (dx != 0 ? i : 0), + FY + TILEY * (dy != 0 ? i : 0)); + } + +#else + int softscroll_offset = (setup.soft_scrolling ? TILEX : 0); - int x, y; BlitBitmap(drawto_field, drawto_field, FX + TILEX * (dx == -1) - softscroll_offset, FY + TILEY * (dy == -1) - softscroll_offset, - SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset, - SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset, + SXSIZE - TILEX * (dx != 0) + 2 * softscroll_offset, + SYSIZE - TILEY * (dy != 0) + 2 * softscroll_offset, FX + TILEX * (dx == 1) - softscroll_offset, FY + TILEY * (dy == 1) - softscroll_offset); +#endif - if (dx) + if (dx != 0) { x = (dx == 1 ? BX1 : BX2); for (y = BY1; y <= BY2; y++) DrawScreenField(x, y); } - if (dy) + if (dy != 0) { y = (dy == 1 ? BY1 : BY2); for (x = BX1; x <= BX2; x++)