X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Ftools.c;h=ebc8cb6dd6a0a0f95b4cc4fe98d4da8953ac4f25;hb=a84bd00a438ff458c2d74d1d1784deefe12bf84a;hp=9a8c477c08332e8e0eb00048b679003ca94c90cd;hpb=1290799ac0be42dc5db602dd113c5185df0a7e03;p=rocksndiamonds.git diff --git a/src/tools.c b/src/tools.c index 9a8c477c..ebc8cb6d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -706,18 +706,29 @@ static int getGraphicAnimationPhase(int frames, int delay, int mode) return phase; } -static int getNewGraphicAnimationFrame(int graphic, int sync_frame) +int getNewGraphicAnimationFrame(int graphic, int sync_frame) { int num_frames = new_graphic_info[graphic].anim_frames; int delay = new_graphic_info[graphic].anim_delay; int mode = new_graphic_info[graphic].anim_mode; - int frame; + int frame = 0; /* animation synchronized with global frame counter, not move position */ if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0) sync_frame = FrameCounter; - if (mode & ANIM_PINGPONG) /* use border frames once */ + if (mode & ANIM_LOOP) /* normal, looping animation */ + { + frame = (sync_frame % (delay * num_frames)) / delay; + } + else if (mode & ANIM_LINEAR) /* normal, non-looping animation */ + { + frame = sync_frame / delay; + + if (frame > num_frames - 1) + frame = num_frames - 1; + } + else if (mode & ANIM_PINGPONG) /* use border frames once */ { int max_anim_frames = 2 * num_frames - 2; @@ -731,8 +742,6 @@ static int getNewGraphicAnimationFrame(int graphic, int sync_frame) frame = (sync_frame % (delay * max_anim_frames)) / delay; frame = (frame < num_frames ? frame : max_anim_frames - frame - 1); } - else /* mode == ANIM_NORMAL || mode == ANIM_REVERSE */ - frame = (sync_frame % (delay * num_frames)) / delay; if (mode & ANIM_REVERSE) /* use reverse animation direction */ frame = num_frames - frame - 1; @@ -758,7 +767,11 @@ void DrawNewGraphicAnimationExt(int x, int y, int graphic, int mask_mode) { int delay = new_graphic_info[graphic].anim_delay; +#if 0 if (!(FrameCounter % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) +#else + if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) +#endif { int frame = getNewGraphicAnimationFrame(graphic, -1); @@ -902,11 +915,11 @@ void DrawNewGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic, Bitmap *src_bitmap = new_graphic_info[graphic].bitmap; int src_x = new_graphic_info[graphic].src_x; int src_y = new_graphic_info[graphic].src_y; + int offset_x = new_graphic_info[graphic].offset_x; + int offset_y = new_graphic_info[graphic].offset_y; - if (new_graphic_info[graphic].anim_vertical) - src_y += frame * TILEY; - else - src_x += frame * TILEX; + src_x += frame * offset_x; + src_y += frame * offset_y; BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y); } @@ -983,11 +996,11 @@ void DrawNewGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y, GC drawing_gc = src_bitmap->stored_clip_gc; int src_x = new_graphic_info[graphic].src_x; int src_y = new_graphic_info[graphic].src_y; + int offset_x = new_graphic_info[graphic].offset_x; + int offset_y = new_graphic_info[graphic].offset_y; - if (new_graphic_info[graphic].anim_vertical) - src_y += frame * TILEY; - else - src_x += frame * TILEX; + src_x += frame * offset_x; + src_y += frame * offset_y; SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y); BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y); @@ -1187,6 +1200,8 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, GC drawing_gc; int src_x; int src_y; + int offset_x; + int offset_y; int width = TILEX, height = TILEY; int cx = 0, cy = 0; @@ -1266,11 +1281,11 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame, drawing_gc = src_bitmap->stored_clip_gc; src_x = new_graphic_info[graphic].src_x; src_y = new_graphic_info[graphic].src_y; + offset_x = new_graphic_info[graphic].offset_x; + offset_y = new_graphic_info[graphic].offset_y; - if (new_graphic_info[graphic].anim_vertical) - src_y += frame * TILEY; - else - src_x += frame * TILEX; + src_x += frame * offset_x; + src_y += frame * offset_y; src_x += cx; src_y += cy; @@ -1344,7 +1359,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, } else if (element == EL_SP_ELECTRON) { - graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); + graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_LOOP); } else if (element == EL_MOLE || element == EL_PENGUIN || element == EL_PIG || element == EL_DRAGON) @@ -1370,11 +1385,11 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, } else if (element == EL_SATELLITE) { - graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); + graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_LOOP); } else if (element == EL_ACID) { - graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_NORMAL); + graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_LOOP); } else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY) { @@ -1438,6 +1453,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, else if (rechts_massiv) graphic = GFX_MAUER_L; } +#if 0 else if ((element == EL_INVISIBLE_STEELWALL || element == EL_INVISIBLE_WALL || element == EL_INVISIBLE_SAND) && game.light_time_left) @@ -1446,6 +1462,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, element == EL_INVISIBLE_WALL ? GFX_UNSICHTBAR_ON : GFX_SAND_INVISIBLE_ON); } +#endif if (dx || dy) DrawGraphicShifted(x, y, dx, dy, graphic, cut_mode, mask_mode); @@ -1455,101 +1472,60 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element, DrawGraphic(x, y, graphic); } +inline static int getFramePosition(int x, int y) +{ + int element = Feld[x][y]; + int frame_pos = -1; + + if (element == EL_QUICKSAND_FULL || + element == EL_MAGIC_WALL_FULL || + element == EL_BD_MAGIC_WALL_FULL) + frame_pos = -1; + else if (IS_MOVING(x, y) || CAN_MOVE(element) || CAN_FALL(element)) + frame_pos = ABS(MovPos[x][y]) / (TILEX / 8); + + return frame_pos; +} + +inline static int getGfxAction(int x, int y) +{ + int gfx_action = GFX_ACTION_DEFAULT; + + if (GfxAction[x][y] != GFX_ACTION_DEFAULT) + gfx_action = GfxAction[x][y]; + else if (IS_MOVING(x, y)) + gfx_action = GFX_ACTION_MOVING; + + return gfx_action; +} + void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, int cut_mode, int mask_mode) { int ux = LEVELX(x), uy = LEVELY(y); int move_dir = MovDir[ux][uy]; - int move_pos = ABS(MovPos[ux][uy]) / (TILEX / 8); - int graphic = el_dir2img(element, move_dir); + int move_pos = getFramePosition(ux, uy); + int gfx_action = getGfxAction(ux, uy); + int graphic = el_dir_act2img(element, move_dir, gfx_action); int frame = getNewGraphicAnimationFrame(graphic, move_pos); - int phase8 = move_pos; - int phase4 = phase8 / 2; - int phase2 = phase8 / 4; - - int dir = move_dir; /* !!! THROW AWAY LATER !!! */ - if (0) + if (element == EL_WALL_GROWING) { - ; - } -#if 0 - else if (element == EL_PACMAN || element == EL_BUG || - element == EL_SPACESHIP) - { - graphic += 1 * !phase2; + boolean left_stopped = FALSE, right_stopped = FALSE; - if (dir == MV_UP) - graphic += 1 * 2; - else if (dir == MV_LEFT) - graphic += 2 * 2; - else if (dir == MV_DOWN) - graphic += 3 * 2; - } - else if (element == EL_SP_SNIKSNAK) - { - if (dir == MV_LEFT) - graphic = GFX_SP_SNIKSNAK_LEFT; - else if (dir == MV_RIGHT) - graphic = GFX_SP_SNIKSNAK_RIGHT; - else if (dir == MV_UP) - graphic = GFX_SP_SNIKSNAK_UP; - else - graphic = GFX_SP_SNIKSNAK_DOWN; + if (!IN_LEV_FIELD(ux - 1, uy) || IS_MAUER(Feld[ux - 1][uy])) + left_stopped = TRUE; + if (!IN_LEV_FIELD(ux + 1, uy) || IS_MAUER(Feld[ux + 1][uy])) + right_stopped = TRUE; - graphic += (phase8 < 4 ? phase8 : 7 - phase8); - } - else if (element == EL_SP_ELECTRON) - { - graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); - } -#endif - else if (element == EL_MOLE || element == EL_PENGUIN || - element == EL_PIG || element == EL_DRAGON) - { - if (dir == MV_LEFT) - graphic = (element == EL_MOLE ? GFX_MOLE_LEFT : - element == EL_PENGUIN ? GFX_PINGUIN_LEFT : - element == EL_PIG ? GFX_SCHWEIN_LEFT : GFX_DRACHE_LEFT); - else if (dir == MV_RIGHT) - graphic = (element == EL_MOLE ? GFX_MOLE_RIGHT : - element == EL_PENGUIN ? GFX_PINGUIN_RIGHT : - element == EL_PIG ? GFX_SCHWEIN_RIGHT : GFX_DRACHE_RIGHT); - else if (dir == MV_UP) - graphic = (element == EL_MOLE ? GFX_MOLE_UP : - element == EL_PENGUIN ? GFX_PINGUIN_UP : - element == EL_PIG ? GFX_SCHWEIN_UP : GFX_DRACHE_UP); - else - graphic = (element == EL_MOLE ? GFX_MOLE_DOWN : - element == EL_PENGUIN ? GFX_PINGUIN_DOWN : - element == EL_PIG ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN); - - graphic += phase4; - } - else if (element == EL_SATELLITE) - { -#if 1 - graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL); -#else - graphic = GFX_SONDE_START + getNewGraphicAnimationFrame(graphic, move_pos); -#endif - } - else if (element == EL_ACID) - { -#if 1 - graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_NORMAL); -#else - graphic = GFX_GEBLUBBER + getNewGraphicAnimationFrame(graphic, move_pos); -#endif - } - else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY) - { - graphic += !phase2; - } - else if (element == EL_BALLOON) - { - graphic += phase4; + if (left_stopped && right_stopped) + graphic = IMG_WALL; + else if (left_stopped) + graphic = IMG_WALL_GROWING_ACTIVE_RIGHT; + else if (right_stopped) + graphic = IMG_WALL_GROWING_ACTIVE_LEFT; } +#if 0 else if ((element == EL_ROCK || element == EL_SP_ZONK || element == EL_BD_ROCK || @@ -1563,9 +1539,9 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, element == EL_SP_ZONK || element == EL_BD_ROCK) { - if (dir == MV_LEFT) + if (move_dir == MV_LEFT) graphic += (4 - phase4) % 4; - else if (dir == MV_RIGHT) + else if (move_dir == MV_RIGHT) graphic += phase4; else graphic += phase2 * 2; @@ -1574,47 +1550,16 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element, graphic += phase2; } } - else if (element == EL_MAGIC_WALL_ACTIVE || - element == EL_MAGIC_WALL_EMPTYING || - element == EL_BD_MAGIC_WALL_ACTIVE || - element == EL_BD_MAGIC_WALL_EMPTYING || - element == EL_MAGIC_WALL_FULL || - element == EL_BD_MAGIC_WALL_FULL) - { -#if 1 - graphic += 3 + getGraphicAnimationPhase(4, 4, ANIM_REVERSE); -#else - graphic += 3 + getNewGraphicAnimationFrame(graphic, move_pos); #endif - } else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING) { - graphic = (element == EL_AMOEBA_DEAD ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT); - graphic += (x + 2 * y + 4) % 4; - } - else if (element == EL_WALL_GROWING) - { - boolean links_massiv = FALSE, rechts_massiv = FALSE; + graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 : + element == EL_AMOEBA_WET ? IMG_AMOEBA_WET_PART1 : + element == EL_AMOEBA_DRY ? IMG_AMOEBA_DRY_PART1 : + element == EL_AMOEBA_FULL ? IMG_AMOEBA_FULL_PART1 : + IMG_AMOEBA_DEAD_PART1); - if (!IN_LEV_FIELD(ux-1, uy) || IS_MAUER(Feld[ux-1][uy])) - links_massiv = TRUE; - if (!IN_LEV_FIELD(ux+1, uy) || IS_MAUER(Feld[ux+1][uy])) - rechts_massiv = TRUE; - - if (links_massiv && rechts_massiv) - graphic = GFX_MAUERWERK; - else if (links_massiv) - graphic = GFX_MAUER_R; - else if (rechts_massiv) - graphic = GFX_MAUER_L; - } - else if ((element == EL_INVISIBLE_STEELWALL || - element == EL_INVISIBLE_WALL || - element == EL_INVISIBLE_SAND) && game.light_time_left) - { - graphic = (element == EL_INVISIBLE_STEELWALL ? GFX_INVISIBLE_STEEL_ON : - element == EL_INVISIBLE_WALL ? GFX_UNSICHTBAR_ON : - GFX_SAND_INVISIBLE_ON); + graphic += (x + 2 * y + 4) % 4; } if (dx || dy) @@ -3026,7 +2971,6 @@ int el2gfx_OLD(int element) case EL_EXIT_OPENING: return GFX_AUSGANG_ACT; case EL_EXIT_OPEN: return GFX_AUSGANG_AUF; case EL_SP_EXIT_OPEN: return GFX_SP_EXIT; - case EL_PLAYER: return GFX_SPIELFIGUR; case EL_PLAYER1: return GFX_SPIELER1; case EL_PLAYER2: return GFX_SPIELER2; case EL_PLAYER3: return GFX_SPIELER3; @@ -3104,6 +3048,7 @@ int el2gfx_OLD(int element) case EL_PACMAN_LEFT: return GFX_PACMAN_LEFT; case EL_PACMAN_DOWN: return GFX_PACMAN_DOWN; case EL_INVISIBLE_WALL: return GFX_UNSICHTBAR; + case EL_INVISIBLE_WALL_ACTIVE: return GFX_UNSICHTBAR_ON; case EL_WALL_EMERALD: return GFX_ERZ_EDEL; case EL_WALL_DIAMOND: return GFX_ERZ_DIAM; case EL_LAMP: return GFX_BIRNE_AUS; @@ -3128,10 +3073,10 @@ int el2gfx_OLD(int element) case EL_BD_MAGIC_WALL_EMPTYING: return GFX_MAGIC_WALL_BD_EMPTY; case EL_BD_MAGIC_WALL_FULL: return GFX_MAGIC_WALL_BD_FULL; case EL_BD_MAGIC_WALL_DEAD: return GFX_MAGIC_WALL_BD_DEAD; - case EL_DYNABOMB_ACTIVE_1: return GFX_DYNABOMB; - case EL_DYNABOMB_ACTIVE_2: return GFX_DYNABOMB; - case EL_DYNABOMB_ACTIVE_3: return GFX_DYNABOMB; - case EL_DYNABOMB_ACTIVE_4: return GFX_DYNABOMB; + case EL_DYNABOMB_PLAYER1_ACTIVE: return GFX_DYNABOMB; + case EL_DYNABOMB_PLAYER2_ACTIVE: return GFX_DYNABOMB; + case EL_DYNABOMB_PLAYER3_ACTIVE: return GFX_DYNABOMB; + case EL_DYNABOMB_PLAYER4_ACTIVE: return GFX_DYNABOMB; case EL_DYNABOMB_NR: return GFX_DYNABOMB_NR; case EL_DYNABOMB_SZ: return GFX_DYNABOMB_SZ; case EL_DYNABOMB_XL: return GFX_DYNABOMB_XL; @@ -3153,6 +3098,7 @@ int el2gfx_OLD(int element) case EL_SP_ZONK: return GFX_SP_ZONK; /* ^^^^^^^^^^ non-standard position in supaplex graphic set! */ case EL_INVISIBLE_STEELWALL: return GFX_INVISIBLE_STEEL; + case EL_INVISIBLE_STEELWALL_ACTIVE: return GFX_INVISIBLE_STEEL_ON; case EL_BLACK_ORB: return GFX_BLACK_ORB; case EL_EM_GATE1: return GFX_EM_GATE_1; case EL_EM_GATE2: return GFX_EM_GATE_2; @@ -3242,6 +3188,7 @@ int el2gfx_OLD(int element) case EL_MOLE_DOWN: return GFX_MOLE_DOWN; case EL_STEELWALL_SLANTED: return GFX_STEEL_SLANTED; case EL_INVISIBLE_SAND: return GFX_SAND_INVISIBLE; + case EL_INVISIBLE_SAND_ACTIVE: return GFX_SAND_INVISIBLE_ON; case EL_DX_UNKNOWN_15: return GFX_DX_UNKNOWN_15; case EL_DX_UNKNOWN_42: return GFX_DX_UNKNOWN_42; case EL_TIMEGATE_OPEN: return GFX_TIMEGATE_OPEN; @@ -3308,6 +3255,12 @@ int el2gfx_OLD(int element) int el2gfx(int element) { +#if 1 + int graphic_OLD = el2gfx_OLD(element); + + return graphic_OLD; +#else + int graphic_NEW = element_info[element].graphic[GFX_ACTION_DEFAULT]; #if DEBUG @@ -3326,10 +3279,17 @@ int el2gfx(int element) #endif return graphic_NEW; +#endif } int el2img(int element) { +#if 1 + int graphic_NEW = element_info[element].graphic[GFX_ACTION_DEFAULT]; + + return graphic_NEW; +#else + switch(element) { case EL_BD_BUTTERFLY: return IMG_BD_BUTTERFLY; @@ -3340,17 +3300,19 @@ int el2img(int element) break; } - return IMG_EMPTY_SPACE; + return IMG_EMPTY; +#endif } int el_dir2img(int element, int direction) { - if (element_info[element].has_direction_graphic[GFX_ACTION_DEFAULT]) - { - int i = LOG_MV_DIR(direction); + return el_dir_act2img(element, direction, GFX_ACTION_DEFAULT); +} - return element_info[element].direction_graphic[GFX_ACTION_DEFAULT][i]; - } - else - return el2img(element); +int el_dir_act2img(int element, int direction, int action) +{ + action = graphics_action_mapping[action]; + direction = MV_DIR_BIT(direction); + + return element_info[element].direction_graphic[action][direction]; }