X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=6a62ab77dfb49fdeae9289a7d94a9b7ff0608d64;hb=a95264fc39b6eae2473bfd6521c7bf3eef5af804;hp=28dde52a06ecf6f8c9035014d546e5f232b2e113;hpb=fa2a77aa4b53bb786e67f35d6c46f759ebe7823d;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 28dde52a..6a62ab77 100644 --- a/src/game.c +++ b/src/game.c @@ -89,6 +89,8 @@ #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value)) #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value)) +#define INIT_GFX_RANDOM() (SimpleRND(1000000)) + /* game button identifiers */ #define GAME_CTRL_ID_STOP 0 #define GAME_CTRL_ID_PAUSE 1 @@ -99,115 +101,94 @@ #define NUM_GAME_BUTTONS 6 + /* forward declaration for internal use */ + static void InitBeltMovement(void); static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); static void KillHeroUnlessProtected(int, int); -void PlaySoundLevel(int, int, int); -void PlaySoundLevelAction(int, int, int); -void PlaySoundLevelElementAction(int, int, int, int); +static void PlaySoundLevel(int, int, int); +static void PlaySoundLevelNearest(int, int, int); +static void PlaySoundLevelAction(int, int, int); +static void PlaySoundLevelElementAction(int, int, int, int); static void MapGameButtons(); static void HandleGameButtons(struct GadgetInfo *); static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS]; -#define SND_ACTION_UNKNOWN 0 -#define SND_ACTION_WAITING 1 -#define SND_ACTION_MOVING 2 -#define SND_ACTION_DIGGING 3 -#define SND_ACTION_COLLECTING 4 -#define SND_ACTION_PASSING 5 -#define SND_ACTION_IMPACT 6 -#define SND_ACTION_PUSHING 7 -#define SND_ACTION_ACTIVATING 8 -#define SND_ACTION_ACTIVE 9 -#define NUM_SND_ACTIONS 10 +/* ------------------------------------------------------------------------- */ +/* definition of elements that automatically change to other elements after */ +/* a specified time, eventually calling a function when changing */ +/* ------------------------------------------------------------------------- */ -static struct -{ - char *text; - int value; - boolean is_loop; -} sound_action_properties[] = +/* forward declaration for changer functions */ +static void InitBuggyBase(int x, int y); +static void WarnBuggyBase(int x, int y); + +static void InitTrap(int x, int y); +static void ActivateTrap(int x, int y); +static void ChangeActiveTrap(int x, int y); + +static void InitRobotWheel(int x, int y); +static void RunRobotWheel(int x, int y); +static void StopRobotWheel(int x, int y); + +static void InitTimegateWheel(int x, int y); +static void RunTimegateWheel(int x, int y); + +struct ChangingElementInfo { - /* insert _all_ loop sound actions here */ - { ".waiting", SND_ACTION_WAITING, TRUE }, - { ".moving", SND_ACTION_MOVING, TRUE }, /* continuos moving */ - { ".active", SND_ACTION_ACTIVE, TRUE }, - { ".growing", SND_ACTION_UNKNOWN, TRUE }, - { ".attacking", SND_ACTION_UNKNOWN, TRUE }, - - /* other (non-loop) sound actions are optional */ - { ".stepping", SND_ACTION_MOVING, FALSE }, /* discrete moving */ - { ".digging", SND_ACTION_DIGGING, FALSE }, - { ".collecting", SND_ACTION_COLLECTING, FALSE }, - { ".passing", SND_ACTION_PASSING, FALSE }, - { ".impact", SND_ACTION_IMPACT, FALSE }, - { ".pushing", SND_ACTION_PUSHING, FALSE }, - { ".activating", SND_ACTION_ACTIVATING, FALSE }, - { NULL, 0, 0 }, + int base_element; + int next_element; + int change_delay; + void (*pre_change_function)(int x, int y); + void (*change_function)(int x, int y); + void (*post_change_function)(int x, int y); }; -static int element_action_sound[MAX_NUM_ELEMENTS][NUM_SND_ACTIONS]; -static boolean is_loop_sound[NUM_SOUND_FILES]; -#define IS_LOOP_SOUND(x) (is_loop_sound[x]) +static struct ChangingElementInfo changing_element_list[] = +{ + { EL_NUT_CRACKING, EL_EMERALD, 6, NULL, NULL, NULL }, + { EL_PEARL_BREAKING, EL_EMPTY, 8, NULL, NULL, NULL }, + { EL_EXIT_OPENING, EL_EXIT_OPEN, 29, NULL, NULL, NULL }, + { EL_SWITCHGATE_OPENING, EL_SWITCHGATE_OPEN, 29, NULL, NULL, NULL }, + { EL_SWITCHGATE_CLOSING, EL_SWITCHGATE_CLOSED, 29, NULL, NULL, NULL }, -#ifdef DEBUG -#if 0 -static unsigned int getStateCheckSum(int counter) -{ - int x, y; - unsigned int mult = 1; - unsigned int checksum = 0; - /* - static short lastFeld[MAX_LEV_FIELDX][MAX_LEV_FIELDY]; - */ - static boolean first_game = TRUE; + { EL_TIMEGATE_OPENING, EL_TIMEGATE_OPEN, 29, NULL, NULL, NULL }, + { EL_TIMEGATE_CLOSING, EL_TIMEGATE_CLOSED, 29, NULL, NULL, NULL }, - for (y=0; ygems_still_needed, 3), FS_SMALL, FC_YELLOW); + int2str(local_player->gems_still_needed, 3), FONT_TEXT_2); DrawText(DX + XX_DYNAMITE, DY + YY_DYNAMITE, - int2str(local_player->dynamite, 3), FS_SMALL, FC_YELLOW); + int2str(local_player->dynamite, 3), FONT_TEXT_2); DrawText(DX + XX_SCORE, DY + YY_SCORE, - int2str(local_player->score, 5), FS_SMALL, FC_YELLOW); + int2str(local_player->score, 5), FONT_TEXT_2); DrawText(DX + XX_TIME, DY + YY_TIME, - int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); -} - - -/* - ============================================================================= - InitGameSound() - ----------------------------------------------------------------------------- - initialize sound effect lookup table for element actions - ============================================================================= -*/ - -void InitGameSound() -{ - int sound_effect_properties[NUM_SOUND_FILES]; - int i, j; - -#if 0 - debug_print_timestamp(0, NULL); -#endif - - for (i=0; i VERSION_IDENT(2,0,1)) - Elementeigenschaften2[EL_WALL_GROWING_ACTIVE] |= EP_BIT_EM_SLIPPERY_WALL; + Properties2[EL_WALL_GROWING_ACTIVE] |= EP_BIT_EM_SLIPPERY_WALL; else - Elementeigenschaften2[EL_WALL_GROWING_ACTIVE] &=~EP_BIT_EM_SLIPPERY_WALL; + Properties2[EL_WALL_GROWING_ACTIVE] &=~EP_BIT_EM_SLIPPERY_WALL; + } + + /* initialize changing elements information */ + for (i=0; ibase_element; + + changing_element[element].base_element = ce->base_element; + changing_element[element].next_element = ce->next_element; + changing_element[element].change_delay = ce->change_delay; + changing_element[element].pre_change_function = ce->pre_change_function; + changing_element[element].change_function = ce->change_function; + changing_element[element].post_change_function = ce->post_change_function; + + i++; } } @@ -721,13 +643,19 @@ void InitGame() player->GfxPos = 0; player->Frame = 0; - player->actual_frame_counter = 0; + player->GfxAction = ACTION_DEFAULT; + + player->use_murphy_graphic = FALSE; + player->use_disk_red_graphic = FALSE; - player->frame_reset_delay = 0; + player->actual_frame_counter = 0; player->last_move_dir = MV_NO_MOVING; player->is_moving = FALSE; + player->is_moving = FALSE; + player->is_waiting = FALSE; + player->move_delay = game.initial_move_delay; player->move_delay_value = game.initial_move_delay_value; @@ -797,12 +725,15 @@ void InitGame() Feld[x][y] = Ur[x][y]; MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0; Store[x][y] = Store2[x][y] = StorePlayer[x][y] = 0; - Frame[x][y] = 0; - GfxAction[x][y] = GFX_ACTION_DEFAULT; AmoebaNr[x][y] = 0; JustStopped[x][y] = 0; Stop[x][y] = FALSE; + ExplodePhase[x][y] = 0; ExplodeField[x][y] = EX_NO_EXPLOSION; + + GfxFrame[x][y] = 0; + GfxAction[x][y] = ACTION_DEFAULT; + GfxRandom[x][y] = INIT_GFX_RANDOM(); } } @@ -962,7 +893,6 @@ void InitGame() DrawLevel(); DrawAllPlayers(); - FadeToFront(); /* after drawing the level, correct some elements */ if (game.timegate_time_left == 0) @@ -972,21 +902,22 @@ void InitGame() BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY); redraw_mask |= REDRAW_FROM_BACKBUFFER; + FadeToFront(); /* copy default game door content to main double buffer */ - BlitBitmap(new_graphic_info[IMG_MENU_DOOR].bitmap, drawto, + BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto, DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY); if (level_nr < 100) - DrawText(DX + XX_LEVEL, DY + YY_LEVEL, - int2str(level_nr, 2), FS_SMALL, FC_YELLOW); + DrawText(DX + XX_LEVEL, DY + YY_LEVEL, int2str(level_nr, 2), FONT_TEXT_2); else { DrawTextExt(drawto, DX + XX_EMERALDS, DY + YY_EMERALDS, - int2str(level_nr, 3), FS_SMALL, FC_SPECIAL3); + int2str(level_nr, 3), FONT_LEVEL_NUMBER, FONT_OPAQUE); BlitBitmap(drawto, drawto, DX + XX_EMERALDS, DY + YY_EMERALDS + 1, - FONT5_XSIZE * 3, FONT5_YSIZE - 1, + getFontWidth(FONT_LEVEL_NUMBER) * 3, + getFontHeight(FONT_LEVEL_NUMBER) - 1, DX + XX_LEVEL - 1, DY + YY_LEVEL + 1); } @@ -1180,7 +1111,7 @@ void GameWon() TimeLeft -= 10; else TimeLeft--; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); + DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); BackToFront(); if (!tape.playing) @@ -1206,7 +1137,7 @@ void GameWon() TimePlayed += 10; else TimePlayed++; - DrawText(DX_TIME, DY_TIME, int2str(TimePlayed, 3), FS_SMALL, FC_YELLOW); + DrawText(DX_TIME, DY_TIME, int2str(TimePlayed, 3), FONT_TEXT_2); BackToFront(); if (!tape.playing) @@ -1217,10 +1148,6 @@ void GameWon() StopSound(SND_GAME_LEVELTIME_BONUS); } -#if 0 - FadeSounds(); -#endif - /* Hero disappears */ DrawLevelField(ExitX, ExitY); BackToFront(); @@ -1331,22 +1258,48 @@ int NewHiScore() return position; } +static void InitPlayerGfxAnimation(struct PlayerInfo *player, int action) +{ + if (player->GfxAction != action) + { + player->GfxAction = action; + player->Frame = 0; + } +} + +static void ResetRandomAnimationValue(int x, int y) +{ + GfxRandom[x][y] = INIT_GFX_RANDOM(); +} + +static void ResetGfxAnimation(int x, int y) +{ + GfxFrame[x][y] = 0; + GfxAction[x][y] = ACTION_DEFAULT; +} + void InitMovingField(int x, int y, int direction) { int element = Feld[x][y]; int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0); int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); - MovDir[x][y] = direction; - MovDir[newx][newy] = direction; + if (!JustStopped[x][y] || direction != MovDir[x][y]) + ResetGfxAnimation(x, y); + + MovDir[newx][newy] = MovDir[x][y] = direction; if (Feld[newx][newy] == EL_EMPTY) Feld[newx][newy] = EL_BLOCKED; if (direction == MV_DOWN && CAN_FALL(element)) - GfxAction[x][y] = GFX_ACTION_FALLING; + GfxAction[x][y] = ACTION_FALLING; else - GfxAction[x][y] = GFX_ACTION_MOVING; + GfxAction[x][y] = ACTION_MOVING; + + GfxFrame[newx][newy] = GfxFrame[x][y]; + GfxAction[newx][newy] = GfxAction[x][y]; + GfxRandom[newx][newy] = GfxRandom[x][y]; } void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y) @@ -1457,7 +1410,7 @@ void RemoveMovingField(int x, int y) Feld[newx][newy] = EL_EMPTY; MovPos[oldx][oldy] = MovDir[oldx][oldy] = MovDelay[oldx][oldy] = 0; MovPos[newx][newy] = MovDir[newx][newy] = MovDelay[newx][newy] = 0; - GfxAction[oldx][oldy] = GfxAction[newx][newy] = GFX_ACTION_DEFAULT; + GfxAction[oldx][oldy] = GfxAction[newx][newy] = ACTION_DEFAULT; DrawLevelField(oldx, oldy); DrawLevelField(newx, newy); @@ -1475,43 +1428,42 @@ void DrawDynamite(int x, int y) if (Store[x][y]) DrawGraphic(sx, sy, el2img(Store[x][y]), 0); - frame = getGraphicAnimationFrame(graphic, 96 - MovDelay[x][y]); - - /* - printf("-> %d: %d [%d]\n", graphic, frame, MovDelay[x][y]); - */ + frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]); +#if 1 + if (Store[x][y]) + DrawGraphicThruMask(sx, sy, graphic, frame); + else + DrawGraphic(sx, sy, graphic, frame); +#else if (game.emulation == EMU_SUPAPLEX) - DrawGraphic(sx, sy, IMG_SP_DISK_RED, 0); + DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame); else if (Store[x][y]) DrawGraphicThruMask(sx, sy, graphic, frame); else DrawGraphic(sx, sy, graphic, frame); +#endif } void CheckDynamite(int x, int y) { - if (MovDelay[x][y]) /* dynamite is still waiting to explode */ + if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */ { MovDelay[x][y]--; - if (MovDelay[x][y]) - { - if (!(MovDelay[x][y] % 6)) - PlaySoundLevelAction(x, y, SND_ACTION_ACTIVE); - if (IS_ACTIVE_BOMB(Feld[x][y])) - { - int delay = (Feld[x][y] == EL_DYNAMITE_ACTIVE ? 12 : 6); + if (MovDelay[x][y] != 0) + { + DrawDynamite(x, y); - if (!(MovDelay[x][y] % delay)) - DrawDynamite(x, y); - } + /* !!! correct: "PlaySoundLevelActionIfLoop" etc. !!! */ + PlaySoundLevelAction(x, y, ACTION_ACTIVE); return; } } - if (Feld[x][y] == EL_DYNAMITE_ACTIVE) + if (Feld[x][y] == EL_DYNAMITE_ACTIVE || + Feld[x][y] == EL_SP_DISK_RED_ACTIVE) StopSound(SND_DYNAMITE_ACTIVE); else StopSound(SND_DYNABOMB_ACTIVE); @@ -1563,7 +1515,7 @@ void Explode(int ex, int ey, int phase, int mode) RemoveMovingField(x, y); } - if (IS_MASSIVE(element) || element == EL_FLAMES) + if (IS_INDESTRUCTIBLE(element) || element == EL_FLAMES) continue; if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y))) @@ -1652,7 +1604,7 @@ void Explode(int ex, int ey, int phase, int mode) Feld[x][y] = EL_EXPLOSION; MovDir[x][y] = MovPos[x][y] = 0; AmoebaNr[x][y] = 0; - Frame[x][y] = 1; + ExplodePhase[x][y] = 1; Stop[x][y] = TRUE; } @@ -1668,7 +1620,7 @@ void Explode(int ex, int ey, int phase, int mode) x = ex; y = ey; - Frame[x][y] = (phase < last_phase ? phase + 1 : 0); + ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0); if (phase == first_phase_after_start) { @@ -1765,7 +1717,7 @@ void DynaExplode(int ex, int ey) int y = ey + j * xy[i % 4][1]; int element; - if (!IN_LEV_FIELD(x, y) || IS_MASSIVE(Feld[x][y])) + if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y])) break; element = Feld[x][y]; @@ -1836,52 +1788,24 @@ void Bang(int x, int y) } } -void Blurb(int x, int y) +void SplashAcid(int x, int y) { int element = Feld[x][y]; if (element != EL_ACID_SPLASH_LEFT && - element != EL_ACID_SPLASH_RIGHT) /* start */ + element != EL_ACID_SPLASH_RIGHT) { PlaySoundLevel(x, y, SND_ACID_SPLASHING); + if (IN_LEV_FIELD(x-1, y) && IS_FREE(x-1, y) && (!IN_LEV_FIELD(x-1, y-1) || !CAN_FALL(MovingOrBlocked2Element(x-1, y-1)))) - { Feld[x-1][y] = EL_ACID_SPLASH_LEFT; - } + if (IN_LEV_FIELD(x+1, y) && IS_FREE(x+1, y) && (!IN_LEV_FIELD(x+1, y-1) || !CAN_FALL(MovingOrBlocked2Element(x+1, y-1)))) - { Feld[x+1][y] = EL_ACID_SPLASH_RIGHT; - } - } - else /* go on */ - { - int graphic = (element == EL_ACID_SPLASH_LEFT ? - IMG_ACID_SPLASH_LEFT : - IMG_ACID_SPLASH_RIGHT); - - if (!MovDelay[x][y]) /* initialize animation counter */ - MovDelay[x][y] = 9; - - if (MovDelay[x][y]) /* continue animation */ - { - MovDelay[x][y]--; - if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(graphic, 8 - MovDelay[x][y]); - - DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame); - } - - if (!MovDelay[x][y]) - { - Feld[x][y] = EL_EMPTY; - DrawLevelField(x, y); - } - } } } @@ -1915,9 +1839,9 @@ static void InitBeltMovement() int graphic = el2img(element); if (game.belt_dir[i] == MV_LEFT) - new_graphic_info[graphic].anim_mode &= ~ANIM_REVERSE; + graphic_info[graphic].anim_mode &= ~ANIM_REVERSE; else - new_graphic_info[graphic].anim_mode |= ANIM_REVERSE; + graphic_info[graphic].anim_mode |= ANIM_REVERSE; } } @@ -1999,9 +1923,9 @@ static void ToggleBeltSwitch(int x, int y) int graphic = el2img(element); if (belt_dir == MV_LEFT) - new_graphic_info[graphic].anim_mode &= ~ANIM_REVERSE; + graphic_info[graphic].anim_mode &= ~ANIM_REVERSE; else - new_graphic_info[graphic].anim_mode |= ANIM_REVERSE; + graphic_info[graphic].anim_mode |= ANIM_REVERSE; } for (yy=0; yy=0 && ZY>=0) + if (element == EL_ROBOT && ZX >= 0 && ZY >= 0) { attr_x = ZX; attr_y = ZY; @@ -2814,7 +2753,7 @@ void StartMoving(int x, int y) if (Stop[x][y]) return; - GfxAction[x][y] = GFX_ACTION_DEFAULT; + GfxAction[x][y] = ACTION_DEFAULT; if (CAN_FALL(element) && y < lev_fieldy - 1) { @@ -2930,14 +2869,22 @@ void StartMoving(int x, int y) EL_BD_MAGIC_WALL_FILLING); Store[x][y] = element; } +#if 0 else if (CAN_SMASH(element) && Feld[x][y+1] == EL_ACID) +#else + else if (CAN_FALL(element) && Feld[x][y+1] == EL_ACID) +#endif { - Blurb(x, y); + SplashAcid(x, y); InitMovingField(x, y, MV_DOWN); started_moving = TRUE; Store[x][y] = EL_ACID; +#if 0 + /* !!! TEST !!! better use "_FALLING" etc. !!! */ + GfxAction[x][y+1] = ACTION_ACTIVE; +#endif } else if (CAN_SMASH(element) && Feld[x][y+1] == EL_BLOCKED && JustStopped[x][y]) @@ -2954,6 +2901,9 @@ void StartMoving(int x, int y) } else if (IS_FREE(x, y+1)) { + if (JustStopped[x][y]) /* prevent animation from being restarted */ + MovDir[x][y] = MV_DOWN; + InitMovingField(x, y, MV_DOWN); started_moving = TRUE; } @@ -3009,7 +2959,7 @@ void StartMoving(int x, int y) InitMovingField(x, y, belt_dir); started_moving = TRUE; - GfxAction[x][y] = GFX_ACTION_DEFAULT; + GfxAction[x][y] = ACTION_DEFAULT; } } } @@ -3048,15 +2998,8 @@ void StartMoving(int x, int y) element != EL_DARK_YAMYAM && element != EL_PACMAN) { -#if 0 - if (element == EL_SPRING) - printf("1--> %d\n", MovDir[x][y]); -#endif TurnRound(x, y); -#if 0 - if (element == EL_SPRING) - printf("2--> %d\n", MovDir[x][y]); -#endif + if (MovDelay[x][y] && (element == EL_BUG || element == EL_SPACESHIP || element == EL_SP_SNIKSNAK || @@ -3071,36 +3014,24 @@ void StartMoving(int x, int y) MovDelay[x][y]--; if (element == EL_ROBOT || - element == EL_YAMYAM || element == EL_DARK_YAMYAM) + element == EL_YAMYAM || + element == EL_DARK_YAMYAM) { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int graphic = el2img(element); - int frame = getGraphicAnimationFrame(graphic, MovDelay[x][y] % 8); - - DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame); - } - - if (MovDelay[x][y] % 4 == 3) - { - if (element == EL_YAMYAM) - PlaySoundLevel(x, y, SND_YAMYAM_WAITING); - else if (element == EL_DARK_YAMYAM) - PlaySoundLevel(x, y, SND_DARK_YAMYAM_WAITING); - } + DrawLevelElementAnimationIfNeeded(x, y, element); + PlaySoundLevelAction(x, y, ACTION_WAITING); } else if (element == EL_SP_ELECTRON) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SP_ELECTRON); + DrawLevelElementAnimationIfNeeded(x, y, element); else if (element == EL_DRAGON) { int i; int dir = MovDir[x][y]; int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0); int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0); - int graphic = (dir == MV_LEFT ? IMG_FLAMES_LEFT1 : - dir == MV_RIGHT ? IMG_FLAMES_RIGHT1 : - dir == MV_UP ? IMG_FLAMES_UP1 : - dir == MV_DOWN ? IMG_FLAMES_DOWN1 : IMG_EMPTY); + int graphic = (dir == MV_LEFT ? IMG_FLAMES1_LEFT : + dir == MV_RIGHT ? IMG_FLAMES1_RIGHT : + dir == MV_UP ? IMG_FLAMES1_UP : + dir == MV_DOWN ? IMG_FLAMES1_DOWN : IMG_EMPTY); int frame = getGraphicAnimationFrame(graphic, -1); for (i=1; i<=3; i++) @@ -3137,7 +3068,7 @@ void StartMoving(int x, int y) if (MovDelay[x][y]) /* element still has to wait some time */ { - PlaySoundLevelAction(x, y, SND_ACTION_WAITING); + PlaySoundLevelAction(x, y, ACTION_WAITING); return; } @@ -3167,7 +3098,7 @@ void StartMoving(int x, int y) IN_LEV_FIELD(newx, newy) && MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID) { - Blurb(x, y); + SplashAcid(x, y); Store[x][y] = EL_ACID; } else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy)) @@ -3348,23 +3279,23 @@ void StartMoving(int x, int y) element == EL_SP_SNIKSNAK || element == EL_MOLE) DrawLevelField(x, y); else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), el2img(element)); + DrawLevelElementAnimationIfNeeded(x, y, element); else if (element == EL_SATELLITE) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SATELLITE); + DrawLevelElementAnimationIfNeeded(x, y, element); else if (element == EL_SP_ELECTRON) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SP_ELECTRON); + DrawLevelElementAnimationIfNeeded(x, y, element); if (DONT_TOUCH(element)) TestIfBadThingTouchesHero(x, y); - PlaySoundLevelAction(x, y, SND_ACTION_WAITING); + PlaySoundLevelAction(x, y, ACTION_WAITING); return; } InitMovingField(x, y, MovDir[x][y]); - PlaySoundLevelAction(x, y, SND_ACTION_MOVING); + PlaySoundLevelAction(x, y, ACTION_MOVING); } if (MovDir[x][y]) @@ -3487,9 +3418,14 @@ void ContinueMoving(int x, int y) MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0; MovDelay[newx][newy] = 0; + /* copy animation control values to new field */ + GfxFrame[newx][newy] = GfxFrame[x][y]; GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */ - GfxAction[x][y] = GFX_ACTION_DEFAULT; + GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */ + ResetGfxAnimation(x, y); /* reset animation values for old field */ + +#if 1 #if 0 if (!CAN_MOVE(element)) MovDir[newx][newy] = 0; @@ -3502,6 +3438,7 @@ void ContinueMoving(int x, int y) if (!CAN_MOVE(element) || (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN)) MovDir[newx][newy] = 0; +#endif #endif DrawLevelField(x, y); @@ -3525,15 +3462,6 @@ void ContinueMoving(int x, int y) } else /* still moving on */ { -#if 0 - if (GfxAction[x][y] == GFX_ACTION_DEFAULT) - { - printf("reset GfxAction...\n"); - - GfxAction[x][y] = GFX_ACTION_MOVING; - } -#endif - DrawLevelField(x, y); } } @@ -3796,6 +3724,7 @@ void AmoebeAbleger(int ax, int ay) { int i; int element = Feld[ax][ay]; + int graphic = el2img(element); int newax = ax, neway = ay; static int xy[4][2] = { @@ -3812,6 +3741,9 @@ void AmoebeAbleger(int ax, int ay) return; } + if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic); + if (!MovDelay[ax][ay]) /* start making new amoeba field */ MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed)); @@ -3943,8 +3875,12 @@ void Life(int ax, int ay) static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */ int life_time = 40; int element = Feld[ax][ay]; + int graphic = el2img(element); boolean changed = FALSE; + if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic); + if (Stop[ax][ay]) return; @@ -4010,371 +3946,126 @@ void Life(int ax, int ay) SND_BIOMAZE_CREATING); } -void RobotWheel(int x, int y) +static void InitRobotWheel(int x, int y) { - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND; - - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; - if (MovDelay[x][y]) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_ROBOT_WHEEL_ACTIVE, -1); - - DrawGraphic(SCREENX(x), SCREENY(y), IMG_ROBOT_WHEEL_ACTIVE, frame); - } - - PlaySoundLevel(x, y, SND_ROBOT_WHEEL_ACTIVE); - - return; - } - } + MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND; +} - Feld[x][y] = EL_ROBOT_WHEEL; - DrawLevelField(x, y); +static void RunRobotWheel(int x, int y) +{ + PlaySoundLevel(x, y, SND_ROBOT_WHEEL_ACTIVE); +} +static void StopRobotWheel(int x, int y) +{ if (ZX == x && ZY == y) ZX = ZY = -1; } -void TimegateWheel(int x, int y) +static void InitTimegateWheel(int x, int y) { - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND; + MovDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND; +} - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; - if (MovDelay[x][y]) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_TIMEGATE_SWITCH_ACTIVE, -1); +static void RunTimegateWheel(int x, int y) +{ + PlaySoundLevel(x, y, SND_TIMEGATE_SWITCH_ACTIVE); +} - DrawGraphic(SCREENX(x), SCREENY(y), IMG_TIMEGATE_SWITCH_ACTIVE, frame); - } +void CheckExit(int x, int y) +{ + if (local_player->gems_still_needed > 0 || + local_player->sokobanfields_still_needed > 0 || + local_player->lights_still_needed > 0) + { + int element = Feld[x][y]; + int graphic = el2img(element); - PlaySoundLevel(x, y, SND_TIMEGATE_SWITCH_ACTIVE); + if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - return; - } + return; } - Feld[x][y] = EL_TIMEGATE_SWITCH; - DrawLevelField(x, y); + Feld[x][y] = EL_EXIT_OPENING; - /* !!! THIS LOOKS WRONG !!! */ - if (ZX == x && ZY == y) - ZX = ZY = -1; + PlaySoundLevelNearest(x, y, SND_EXIT_OPENING); } -void NussKnacken(int x, int y) +void CheckExitSP(int x, int y) { - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 7; - - if (MovDelay[x][y]) /* wait some time before next frame */ + if (local_player->gems_still_needed > 0) { - MovDelay[x][y]--; - if (MovDelay[x][y]) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_NUT_CRACKING, - 6 - MovDelay[x][y]); + int element = Feld[x][y]; + int graphic = el2img(element); - DrawGraphic(SCREENX(x), SCREENY(y), IMG_NUT_CRACKING, frame); - } + if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); - return; - } + return; } - Feld[x][y] = EL_EMERALD; - DrawLevelField(x, y); + Feld[x][y] = EL_SP_EXIT_OPEN; + + PlaySoundLevelNearest(x, y, SND_SP_EXIT_OPENING); } -void BreakingPearl(int x, int y) +static void CloseAllOpenTimegates() { - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 9; + int x, y; - if (MovDelay[x][y]) /* wait some time before next frame */ + for (y=0; ygems_still_needed > 0 || - local_player->sokobanfields_still_needed > 0 || - local_player->lights_still_needed > 0) + if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y)) return; - Feld[x][y] = EL_EXIT_OPENING; - - PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) : - (x > LEVELX(BX2) ? LEVELX(BX2) : x), - y < LEVELY(BY1) ? LEVELY(BY1) : - (y > LEVELY(BY2) ? LEVELY(BY2) : y), - SND_EXIT_OPENING); -} - -void AusgangstuerPruefen_SP(int x, int y) -{ - if (local_player->gems_still_needed > 0) + if (Feld[x][y] == EL_BD_DIAMOND) return; - Feld[x][y] = EL_SP_EXIT_OPEN; - - PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) : - (x > LEVELX(BX2) ? LEVELX(BX2) : x), - y < LEVELY(BY1) ? LEVELY(BY1) : - (y > LEVELY(BY2) ? LEVELY(BY2) : y), - SND_SP_EXIT_OPENING); -} - -void AusgangstuerOeffnen(int x, int y) -{ - int delay = 6; - - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 5 * delay; + if (MovDelay[x][y] == 0) /* next animation frame */ + MovDelay[x][y] = 11 * !SimpleRND(500); - if (MovDelay[x][y]) /* wait some time before next frame */ + if (MovDelay[x][y] != 0) /* wait some time before next frame */ { - int tuer; - MovDelay[x][y]--; - tuer = MovDelay[x][y] / delay; - - if (!(MovDelay[x][y] % delay)) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_EXIT_OPENING, - 29 - MovDelay[x][y]); - - DrawGraphic(SCREENX(x), SCREENY(y), IMG_EXIT_OPENING, frame); - } - } - - if (MovDelay[x][y]) - return; - } - - Feld[x][y] = EL_EXIT_OPEN; - DrawLevelField(x, y); -} - -void OpenSwitchgate(int x, int y) -{ - int delay = 6; - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 5 * delay; + if (setup.direct_draw && MovDelay[x][y]) + SetDrawtoField(DRAW_BUFFERED); - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; + DrawLevelElementAnimation(x, y, Feld[x][y]); - if (!(MovDelay[x][y] % delay)) + if (MovDelay[x][y] != 0) { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_SWITCHGATE_OPENING, - 29 - MovDelay[x][y]); - - DrawGraphic(SCREENX(x), SCREENY(y), IMG_SWITCHGATE_OPENING, frame); - } - } - - if (MovDelay[x][y]) - return; - } - - Feld[x][y] = EL_SWITCHGATE_OPEN; - DrawLevelField(x, y); -} - -void CloseSwitchgate(int x, int y) -{ - int delay = 6; - - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 5 * delay; + int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE, + 10 - MovDelay[x][y]); - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; + DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame); - if (!(MovDelay[x][y] % delay)) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) + if (setup.direct_draw) { - int frame = getGraphicAnimationFrame(IMG_SWITCHGATE_CLOSING, - 29 - MovDelay[x][y]); - - DrawGraphic(SCREENX(x), SCREENY(y), IMG_SWITCHGATE_CLOSING, frame); - } - } - - if (MovDelay[x][y]) - return; - } - - Feld[x][y] = EL_SWITCHGATE_CLOSED; - DrawLevelField(x, y); -} - -void OpenTimegate(int x, int y) -{ - int delay = 6; - - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 5 * delay; - - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; + int dest_x, dest_y; - if (!(MovDelay[x][y] % delay)) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_TIMEGATE_OPENING, - 29 - MovDelay[x][y]); + dest_x = FX + SCREENX(x) * TILEX; + dest_y = FY + SCREENY(y) * TILEY; - DrawGraphic(SCREENX(x), SCREENY(y), IMG_TIMEGATE_OPENING, frame); - } - } - - if (MovDelay[x][y]) - return; - } - - Feld[x][y] = EL_TIMEGATE_OPEN; - DrawLevelField(x, y); -} - -void CloseTimegate(int x, int y) -{ - int delay = 6; - - if (!MovDelay[x][y]) /* next animation frame */ - MovDelay[x][y] = 5 * delay; - - if (MovDelay[x][y]) /* wait some time before next frame */ - { - MovDelay[x][y]--; - - if (!(MovDelay[x][y] % delay)) - { - if (IN_SCR_FIELD(SCREENX(x), SCREENY(y))) - { - int frame = getGraphicAnimationFrame(IMG_TIMEGATE_CLOSING, - 29 - MovDelay[x][y]); - - DrawGraphic(SCREENX(x), SCREENY(y), IMG_TIMEGATE_CLOSING, frame); - } - } - - if (MovDelay[x][y]) - return; - } - - Feld[x][y] = EL_TIMEGATE_CLOSED; - DrawLevelField(x, y); -} - -static void CloseAllOpenTimegates() -{ - int x, y; - - for (y=0; yframe_reset_delay = 0; - if (button1) snapped = SnapField(player, dx, dy); else @@ -4764,20 +4410,7 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action) } } -#if 0 - if (tape.recording && (moved || snapped || bombed)) - { - if (bombed && !moved) - player_action &= JOY_BUTTON; - - stored_player_action[player->index_nr] = player_action; - save_tape_entry = TRUE; - } - else if (tape.playing && snapped) - SnapField(player, 0, 0); /* stop snapping */ -#else stored_player_action[player->index_nr] = player_action; -#endif } else { @@ -4787,81 +4420,24 @@ static void PlayerActions(struct PlayerInfo *player, byte player_action) SnapField(player, 0, 0); CheckGravityMovement(player); -#if 1 + InitPlayerGfxAnimation(player, ACTION_DEFAULT); + if (player->MovPos == 0) /* needed for tape.playing */ player->is_moving = FALSE; -#endif -#if 0 - if (player->MovPos == 0) /* needed for tape.playing */ - player->last_move_dir = MV_NO_MOVING; - - /* !!! CHECK THIS AGAIN !!! - (Seems to be needed for some EL_ROBOT stuff, but breaks - tapes when walking through pipes!) - */ - - /* it seems that "player->last_move_dir" is misused as some sort of - "player->is_just_moving_in_this_moment", which is needed for the - robot stuff (robots don't kill players when they are moving) - */ -#endif - - /* if the player does not move for some time, reset animation to start */ - if (++player->frame_reset_delay > player->move_delay_value) - player->Frame = 0; } -#if 0 - if (tape.recording && num_stored_actions >= MAX_PLAYERS && save_tape_entry) - { - TapeRecordAction(stored_player_action); - num_stored_actions = 0; - save_tape_entry = FALSE; - } -#else if (tape.recording && num_stored_actions >= MAX_PLAYERS) { TapeRecordAction(stored_player_action); num_stored_actions = 0; } -#endif - -#if 0 - if (tape.playing && !tape.pausing && !player_action && - tape.counter < tape.length) - { - int jx = player->jx, jy = player->jy; - int next_joy = - tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT); - - if ((next_joy == JOY_LEFT || next_joy == JOY_RIGHT) && - (player->MovDir != JOY_UP && player->MovDir != JOY_DOWN)) - { - int dx = (next_joy == JOY_LEFT ? -1 : +1); - - if (IN_LEV_FIELD(jx+dx, jy) && IS_PUSHABLE(Feld[jx+dx][jy])) - { - int el = Feld[jx+dx][jy]; - int push_delay = (IS_SB_ELEMENT(el) || el == EL_SATELLITE ? 2 : - (el == EL_BALLOON || el == EL_SPRING) ? 0 : 10); - - if (tape.delay_played + push_delay >= tape.pos[tape.counter].delay) - { - player->MovDir = next_joy; - player->Frame = FrameCounter % 4; - player->Pushing = TRUE; - } - } - } - } -#endif } void GameActions() { static unsigned long action_delay = 0; unsigned long action_delay_value; - int sieb_x = 0, sieb_y = 0; + int magic_wall_x = 0, magic_wall_y = 0; int i, x, y, element, graphic; byte *recorded_player_action; byte summarized_player_action = 0; @@ -4945,36 +4521,20 @@ void GameActions() ScrollScreen(NULL, SCROLL_GO_ON); - - -#ifdef DEBUG -#if 0 - if (TimeFrames == 0 && local_player->active) - { - extern unsigned int last_RND(); - - printf("DEBUG: %03d last RND was %d \t [state checksum is %d]\n", - TimePlayed, last_RND(), getStateCheckSum(TimePlayed)); - } -#endif -#endif - -#ifdef DEBUG -#if 0 - if (GameFrameDelay >= 500) - printf("FrameCounter == %d\n", FrameCounter); -#endif -#endif - FrameCounter++; TimeFrames++; + for (i=0; i 0) JustStopped[x][y]--; + GfxFrame[x][y]++; + #if DEBUG if (IS_BLOCKED(x, y)) { @@ -4997,13 +4557,19 @@ void GameActions() element = Feld[x][y]; graphic = el2img(element); + if (graphic_info[graphic].anim_global_sync) + GfxFrame[x][y] = FrameCounter; + + if (ANIM_MODE(graphic) == ANIM_RANDOM && + IS_NEXT_FRAME(GfxFrame[x][y], graphic)) + ResetRandomAnimationValue(x, y); + + SetRandomAnimationValue(x, y); + if (IS_INACTIVE(element)) { - -#if 1 - if (new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); -#endif + if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); continue; } @@ -5012,18 +4578,14 @@ void GameActions() { StartMoving(x, y); -#if 1 - if (Feld[x][y] == EL_EMERALD && - new_graphic_info[graphic].anim_frames > 1 && - !IS_MOVING(x, y)) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); -#endif + if (IS_ANIMATED(graphic) && + !IS_MOVING(x, y) && + !Stop[x][y]) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); if (IS_GEM(element) || element == EL_SP_INFOTRON) EdelsteinFunkeln(x, y); } - -#if 1 else if ((element == EL_ACID || element == EL_EXIT_OPEN || element == EL_SP_EXIT_OPEN || @@ -5032,47 +4594,30 @@ void GameActions() element == EL_EXTRA_TIME || element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY) && - new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); -#endif - + IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); else if (IS_MOVING(x, y)) ContinueMoving(x, y); else if (IS_ACTIVE_BOMB(element)) CheckDynamite(x, y); #if 0 else if (element == EL_EXPLOSION && !game.explosions_delayed) - Explode(x, y, Frame[x][y], EX_NORMAL); + Explode(x, y, ExplodePhase[x][y], EX_NORMAL); #endif else if (element == EL_AMOEBA_CREATING) AmoebeWaechst(x, y); else if (element == EL_AMOEBA_SHRINKING) AmoebaDisappearing(x, y); - #if !USE_NEW_AMOEBA_CODE else if (IS_AMOEBALIVE(element)) AmoebeAbleger(x, y); #endif - else if (element == EL_GAMEOFLIFE || element == EL_BIOMAZE) Life(x, y); - else if (element == EL_ROBOT_WHEEL_ACTIVE) - RobotWheel(x, y); - else if (element == EL_TIMEGATE_SWITCH_ACTIVE) - TimegateWheel(x, y); - else if (element == EL_ACID_SPLASH_LEFT || - element == EL_ACID_SPLASH_RIGHT) - Blurb(x, y); - else if (element == EL_NUT_CRACKING) - NussKnacken(x, y); - else if (element == EL_PEARL_BREAKING) - BreakingPearl(x, y); else if (element == EL_EXIT_CLOSED) - AusgangstuerPruefen(x, y); + CheckExit(x, y); else if (element == EL_SP_EXIT_CLOSED) - AusgangstuerPruefen_SP(x, y); - else if (element == EL_EXIT_OPENING) - AusgangstuerOeffnen(x, y); + CheckExitSP(x, y); else if (element == EL_WALL_GROWING_ACTIVE) MauerWaechst(x, y); else if (element == EL_WALL_GROWING || @@ -5082,51 +4627,31 @@ void GameActions() MauerAbleger(x, y); else if (element == EL_FLAMES) CheckForDragon(x, y); - else if (element == EL_SP_BUGGY_BASE || element == EL_SP_BUGGY_BASE_ACTIVE) - CheckBuggyBase(x, y); - else if (element == EL_TRAP || element == EL_TRAP_ACTIVE) - CheckTrap(x, y); - else if (IS_BELT_ACTIVE(element)) - DrawBeltAnimation(x, y, element); - else if (element == EL_SWITCHGATE_OPENING) - OpenSwitchgate(x, y); - else if (element == EL_SWITCHGATE_CLOSING) - CloseSwitchgate(x, y); - else if (element == EL_TIMEGATE_OPENING) - OpenTimegate(x, y); - else if (element == EL_TIMEGATE_CLOSING) - CloseTimegate(x, y); + else if (IS_AUTO_CHANGING(element)) + ChangeElement(x, y); + else if (element == EL_EXPLOSION) + ; /* drawing of correct explosion animation is handled separately */ + else if (IS_ANIMATED(graphic)) + DrawLevelGraphicAnimationIfNeeded(x, y, graphic); -#if 1 - else if (new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); -#endif + if (IS_BELT_ACTIVE(element)) + PlaySoundLevelAction(x, y, ACTION_ACTIVE); if (game.magic_wall_active) { - boolean sieb = FALSE; int jx = local_player->jx, jy = local_player->jy; - if (element == EL_MAGIC_WALL_FULL || - element == EL_MAGIC_WALL_ACTIVE || - element == EL_MAGIC_WALL_EMPTYING) - { - SiebAktivieren(x, y, 1); - sieb = TRUE; - } - else if (element == EL_BD_MAGIC_WALL_FULL || - element == EL_BD_MAGIC_WALL_ACTIVE || - element == EL_BD_MAGIC_WALL_EMPTYING) - { - SiebAktivieren(x, y, 2); - sieb = TRUE; - } - /* play the element sound at the position nearest to the player */ - if (sieb && ABS(x-jx)+ABS(y-jy) < ABS(sieb_x-jx)+ABS(sieb_y-jy)) + if ((element == EL_MAGIC_WALL_FULL || + element == EL_MAGIC_WALL_ACTIVE || + element == EL_MAGIC_WALL_EMPTYING || + element == EL_BD_MAGIC_WALL_FULL || + element == EL_BD_MAGIC_WALL_ACTIVE || + element == EL_BD_MAGIC_WALL_EMPTYING) && + ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy)) { - sieb_x = x; - sieb_y = y; + magic_wall_x = x; + magic_wall_y = y; } } } @@ -5182,7 +4707,7 @@ void GameActions() if (ExplodeField[x][y]) Explode(x, y, EX_PHASE_START, ExplodeField[x][y]); else if (element == EL_EXPLOSION) - Explode(x, y, Frame[x][y], EX_NORMAL); + Explode(x, y, ExplodePhase[x][y], EX_NORMAL); ExplodeField[x][y] = EX_NO_EXPLOSION; } @@ -5194,14 +4719,14 @@ void GameActions() { if (!(game.magic_wall_time_left % 4)) { - int element = Feld[sieb_x][sieb_y]; + int element = Feld[magic_wall_x][magic_wall_y]; if (element == EL_BD_MAGIC_WALL_FULL || element == EL_BD_MAGIC_WALL_ACTIVE || element == EL_BD_MAGIC_WALL_EMPTYING) - PlaySoundLevel(sieb_x, sieb_y, SND_BD_MAGIC_WALL_ACTIVE); + PlaySoundLevel(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE); else - PlaySoundLevel(sieb_x, sieb_y, SND_MAGIC_WALL_ACTIVE); + PlaySoundLevel(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE); } if (game.magic_wall_time_left > 0) @@ -5289,14 +4814,14 @@ void GameActions() if (TimeLeft <= 10 && setup.time_limit) PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MAX_RIGHT); - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); + DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); if (!TimeLeft && setup.time_limit) for (i=0; iPushing) - player->Frame = 0; - else #if 0 - player->Frame = (player->Frame + 1) % 4; +#if 1 + InitPlayerGfxAnimation(player, ACTION_DEFAULT); #else - player->Frame += 1 * 0; + if (!(moved & MF_MOVING) && !player->Pushing) + player->Frame = 0; +#endif #endif if (moved & MF_MOVING) @@ -5666,8 +5191,6 @@ void ScrollFigure(struct PlayerInfo *player, int mode) { player->actual_frame_counter = FrameCounter; player->GfxPos = move_stepsize * (player->MovPos / move_stepsize); - if (player->Frame) - player->Frame += 1; if (Feld[last_jx][last_jy] == EL_EMPTY) Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING; @@ -5680,7 +5203,6 @@ void ScrollFigure(struct PlayerInfo *player, int mode) player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize; player->GfxPos = move_stepsize * (player->MovPos / move_stepsize); - player->Frame += 1; if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING) Feld[last_jx][last_jy] = EL_EMPTY; @@ -6045,6 +5567,8 @@ int DigField(struct PlayerInfo *player, dy == +1 ? MV_DOWN : MV_NO_MOVING); int element; + player->is_digging = FALSE; + if (player->MovPos == 0) player->Pushing = FALSE; @@ -6099,8 +5623,9 @@ int DigField(struct PlayerInfo *player, case EL_TRAP: case EL_SP_BASE: case EL_SP_BUGGY_BASE: + case EL_SP_BUGGY_BASE_ACTIVATING: RemoveField(x, y); - PlaySoundLevelElementAction(x, y, element, SND_ACTION_DIGGING); + PlaySoundLevelElementAction(x, y, element, ACTION_DIGGING); break; case EL_EMERALD: @@ -6120,9 +5645,8 @@ int DigField(struct PlayerInfo *player, local_player->gems_still_needed = 0; RaiseScoreElement(element); DrawText(DX_EMERALDS, DY_EMERALDS, - int2str(local_player->gems_still_needed, 3), - FS_SMALL, FC_YELLOW); - PlaySoundLevelElementAction(x, y, element, SND_ACTION_COLLECTING); + int2str(local_player->gems_still_needed, 3), FONT_TEXT_2); + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); break; case EL_SPEED_PILL: @@ -6141,7 +5665,7 @@ int DigField(struct PlayerInfo *player, if (level.time > 0) { TimeLeft += 10; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); + DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); } PlaySoundStereo(SND_EXTRA_TIME_COLLECTING, SOUND_MAX_RIGHT); break; @@ -6163,11 +5687,11 @@ int DigField(struct PlayerInfo *player, case EL_SP_DISK_RED: RemoveField(x, y); player->dynamite++; + player->use_disk_red_graphic = (element == EL_SP_DISK_RED); RaiseScoreElement(EL_DYNAMITE); - DrawText(DX_DYNAMITE, DY_DYNAMITE, - int2str(local_player->dynamite, 3), - FS_SMALL, FC_YELLOW); - PlaySoundLevelElementAction(x, y, element, SND_ACTION_COLLECTING); + DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3), + FONT_TEXT_2); + PlaySoundLevelElementAction(x, y, element, ACTION_COLLECTING); break; case EL_DYNABOMB_NR: @@ -6198,14 +5722,15 @@ int DigField(struct PlayerInfo *player, case EL_KEY4: { int key_nr = element - EL_KEY1; + int graphic = el2edimg(element); RemoveField(x, y); player->key[key_nr] = TRUE; RaiseScoreElement(element); DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - IMG_KEY1 + key_nr); + graphic); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - IMG_KEY1 + key_nr); + graphic); PlaySoundLevel(x, y, SND_KEY_COLLECTING); break; } @@ -6216,14 +5741,15 @@ int DigField(struct PlayerInfo *player, case EL_EM_KEY4: { int key_nr = element - EL_EM_KEY1; + int graphic = el2edimg(EL_KEY1 + key_nr); RemoveField(x, y); player->key[key_nr] = TRUE; RaiseScoreElement(element); DrawMiniGraphicExt(drawto, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - IMG_KEY1 + key_nr); + graphic); DrawMiniGraphicExt(window, DX_KEYS + key_nr * MINI_TILEX, DY_KEYS, - IMG_KEY1 + key_nr); + graphic); PlaySoundLevel(x, y, SND_KEY_COLLECTING); break; } @@ -6339,7 +5865,9 @@ int DigField(struct PlayerInfo *player, case EL_SPRING: if (mode == DF_SNAP) return MF_NO_ACTION; + /* no "break" -- fall through to next case */ + /* the following elements can be pushed by "snapping" */ case EL_BD_ROCK: if (dy) @@ -6360,7 +5888,8 @@ int DigField(struct PlayerInfo *player, player->push_delay = FrameCounter; #if 0 if (!FrameReached(&player->push_delay, player->push_delay_value) && - !tape.playing && element != EL_SPRING) + !tape.playing && + element != EL_SPRING) return MF_NO_ACTION; #else if (!FrameReached(&player->push_delay, player->push_delay_value) && @@ -6389,7 +5918,7 @@ int DigField(struct PlayerInfo *player, player->push_delay_value = (element == EL_SPRING ? 0 : 2 + RND(8)); DrawLevelField(x + dx, y + dy); - PlaySoundLevelElementAction(x, y, element, SND_ACTION_PUSHING); + PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); break; case EL_GATE1: @@ -6449,7 +5978,7 @@ int DigField(struct PlayerInfo *player, player->programmed_action = move_direction; DOUBLE_PLAYER_SPEED(player); - PlaySoundLevelElementAction(x, y, element, SND_ACTION_PASSING); + PlaySoundLevelElementAction(x, y, element, ACTION_PASSING); break; case EL_SP_PORT1_LEFT: @@ -6566,7 +6095,7 @@ int DigField(struct PlayerInfo *player, case EL_TIME_ORB_FULL: Feld[x][y] = EL_TIME_ORB_EMPTY; TimeLeft += 10; - DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FS_SMALL, FC_YELLOW); + DrawText(DX_TIME, DY_TIME, int2str(TimeLeft, 3), FONT_TEXT_2); DrawLevelField(x, y); PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MAX_RIGHT); return MF_ACTION; @@ -6647,7 +6176,7 @@ int DigField(struct PlayerInfo *player, { RemoveField(x, y); Feld[x+dx][y+dy] = element; - PlaySoundLevelElementAction(x, y, element, SND_ACTION_PUSHING); + PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); } player->push_delay_value = (element == EL_BALLOON ? 0 : 2); @@ -6671,11 +6200,56 @@ int DigField(struct PlayerInfo *player, break; default: + if (IS_PUSHABLE(element)) + { + if (mode == DF_SNAP) + return MF_NO_ACTION; + + if (CAN_FALL(element) && dy) + return MF_NO_ACTION; + + player->Pushing = TRUE; + + if (!IN_LEV_FIELD(x+dx, y+dy) || !IS_FREE(x+dx, y+dy)) + return MF_NO_ACTION; + + if (dx && real_dy) + { + if (IN_LEV_FIELD(jx, jy+real_dy) && !IS_SOLID(Feld[jx][jy+real_dy])) + return MF_NO_ACTION; + } + else if (dy && real_dx) + { + if (IN_LEV_FIELD(jx+real_dx, jy) && !IS_SOLID(Feld[jx+real_dx][jy])) + return MF_NO_ACTION; + } + + if (player->push_delay == 0) + player->push_delay = FrameCounter; + + if (!FrameReached(&player->push_delay, player->push_delay_value) && + !(tape.playing && tape.file_version < FILE_VERSION_2_0)) + return MF_NO_ACTION; + + RemoveField(x, y); + Feld[x + dx][y + dy] = element; + + player->push_delay_value = 2 + RND(8); + + DrawLevelField(x + dx, y + dy); + PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING); + + break; + } + return MF_NO_ACTION; } player->push_delay = 0; + if (Feld[x][y] != element) /* really digged something */ + player->is_digging = TRUE; + return MF_MOVING; } @@ -6696,6 +6270,7 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) player->Pushing = FALSE; player->snapped = FALSE; + player->is_digging = FALSE; return FALSE; } @@ -6711,6 +6286,7 @@ boolean SnapField(struct PlayerInfo *player, int dx, int dy) return FALSE; player->snapped = TRUE; + player->is_digging = FALSE; DrawLevelField(x, y); BackToFront(); @@ -6734,19 +6310,29 @@ boolean PlaceBomb(struct PlayerInfo *player) if (element != EL_EMPTY) Store[jx][jy] = element; + MovDelay[jx][jy] = 96; + + ResetGfxAnimation(jx, jy); + ResetRandomAnimationValue(jx, jy); + if (player->dynamite) { - Feld[jx][jy] = EL_DYNAMITE_ACTIVE; - MovDelay[jx][jy] = 96; + Feld[jx][jy] = (player->use_disk_red_graphic ? EL_SP_DISK_RED_ACTIVE : + EL_DYNAMITE_ACTIVE); player->dynamite--; + DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3), - FS_SMALL, FC_YELLOW); + FONT_TEXT_2); if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy))) { +#if 1 + DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0); +#else if (game.emulation == EMU_SUPAPLEX) DrawGraphic(SCREENX(jx), SCREENY(jy), IMG_SP_DISK_RED, 0); else DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), IMG_DYNAMITE_ACTIVE, 0); +#endif } PlaySoundLevel(jx, jy, SND_DYNAMITE_DROPPING); @@ -6755,8 +6341,8 @@ boolean PlaceBomb(struct PlayerInfo *player) { Feld[jx][jy] = EL_DYNABOMB_PLAYER1_ACTIVE + (player->element_nr - EL_PLAYER1); - MovDelay[jx][jy] = 96; player->dynabombs_left--; + if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy))) DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0); @@ -6766,10 +6352,29 @@ boolean PlaceBomb(struct PlayerInfo *player) return TRUE; } -void PlaySoundLevel(int x, int y, int nr) +/* ------------------------------------------------------------------------- */ +/* game sound playing functions */ +/* ------------------------------------------------------------------------- */ + +static int *loop_sound_frame = NULL; +static int *loop_sound_volume = NULL; + +void InitPlaySoundLevel() +{ + int num_sounds = getSoundListSize(); + + if (loop_sound_frame != NULL) + free(loop_sound_frame); + + if (loop_sound_volume != NULL) + free(loop_sound_volume); + + loop_sound_frame = checked_calloc(num_sounds * sizeof(int)); + loop_sound_volume = checked_calloc(num_sounds * sizeof(int)); +} + +static void PlaySoundLevel(int x, int y, int nr) { - static int loop_sound_frame[NUM_SOUND_FILES]; - static int loop_sound_volume[NUM_SOUND_FILES]; int sx = SCREENX(x), sy = SCREENY(y); int volume, stereo_position; int max_distance = 8; @@ -6813,24 +6418,33 @@ void PlaySoundLevel(int x, int y, int nr) PlaySoundExt(nr, volume, stereo_position, type); } -void PlaySoundLevelAction(int x, int y, int sound_action) +static void PlaySoundLevelNearest(int x, int y, int sound_action) +{ + PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) : + x > LEVELX(BX2) ? LEVELX(BX2) : x, + y < LEVELY(BY1) ? LEVELY(BY1) : + y > LEVELY(BY2) ? LEVELY(BY2) : y, + sound_action); +} + +static void PlaySoundLevelAction(int x, int y, int sound_action) { PlaySoundLevelElementAction(x, y, Feld[x][y], sound_action); } -void PlaySoundLevelElementAction(int x, int y, int element, int sound_action) +static void PlaySoundLevelElementAction(int x, int y, int element, + int sound_action) { - int sound_effect = element_action_sound[element][sound_action]; + int sound_effect = element_info[element].sound[sound_action]; - if (sound_effect != -1) + if (sound_effect != SND_UNDEFINED) PlaySoundLevel(x, y, sound_effect); } void RaiseScore(int value) { local_player->score += value; - DrawText(DX_SCORE, DY_SCORE, int2str(local_player->score, 5), - FS_SMALL, FC_YELLOW); + DrawText(DX_SCORE, DY_SCORE, int2str(local_player->score, 5), FONT_TEXT_2); } void RaiseScoreElement(int element) @@ -6969,7 +6583,7 @@ void CreateGameButtons() for (i=0; i