From: Holger Schemel Date: Sat, 25 Jan 2003 13:35:00 +0000 (+0100) Subject: rnd-20030125-2-src X-Git-Tag: 3.0.0^2~161 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=3378979a81f39e4a4082d208bf288492d87f5cd1;p=rocksndiamonds.git rnd-20030125-2-src --- diff --git a/src/conftime.h b/src/conftime.h index 93641032..a0ec7636 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2003-01-25 03:22]" +#define COMPILE_DATE_STRING "[2003-01-25 14:33]" diff --git a/src/game.c b/src/game.c index 09ea5e2e..7f239043 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 @@ -100,6 +102,8 @@ #define NUM_GAME_BUTTONS 6 /* forward declaration for internal use */ +static void ResetGfxAnimation(int, int); + static void InitBeltMovement(void); static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); @@ -115,9 +119,6 @@ static void HandleGameButtons(struct GadgetInfo *); static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS]; -#define IS_ANIMATED(g) (graphic_info[g].anim_frames > 1) -#define IS_LOOP_SOUND(s) (sound_info[s].loop) - /* ------------------------------------------------------------------------- */ /* definition of elements that automatically change to other elements after */ @@ -722,7 +723,7 @@ void InitGame() GfxFrame[x][y] = 0; GfxAction[x][y] = ACTION_DEFAULT; - GfxRandom[x][y] = SimpleRND(1000000); + GfxRandom[x][y] = INIT_GFX_RANDOM(); } } @@ -1251,6 +1252,25 @@ int NewHiScore() return position; } +static void ResetRandomAnimationValue(int x, int y) +{ + int element = Feld[x][y]; + int graphic = el2img(element); + + /* reset random value not until one full delay cycle has reached */ + if (ANIM_MODE(graphic) == ANIM_RANDOM && + GfxFrame[x][y] > ANIM_DELAY(graphic)) + GfxRandom[x][y] = INIT_GFX_RANDOM(); +} + +static void ResetGfxAnimation(int x, int y) +{ + ResetRandomAnimationValue(x, y); + + GfxFrame[x][y] = 0; + GfxAction[x][y] = ACTION_DEFAULT; +} + void InitMovingField(int x, int y, int direction) { int element = Feld[x][y]; @@ -1258,7 +1278,7 @@ void InitMovingField(int x, int y, int direction) int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0); if (!JustStopped[x][y] || direction != MovDir[x][y]) - GfxFrame[x][y] = 0; + ResetGfxAnimation(x, y); MovDir[x][y] = direction; MovDir[newx][newy] = direction; @@ -4338,7 +4358,8 @@ static void ChangeElement(int x, int y) if (MovDelay[x][y] == 0) /* initialize element change */ { MovDelay[x][y] = changing_element[element].change_delay + 1; - GfxFrame[x][y] = 0; + + ResetGfxAnimation(x, y); if (changing_element[element].pre_change_function) changing_element[element].pre_change_function(x, y); @@ -4357,7 +4378,8 @@ static void ChangeElement(int x, int y) else /* finish element change */ { Feld[x][y] = changing_element[element].next_element; - GfxFrame[x][y] = 0; + + ResetGfxAnimation(x, y); DrawLevelField(x, y); @@ -4649,6 +4671,10 @@ void GameActions() element = Feld[x][y]; graphic = el2img(element); + if (ANIM_MODE(graphic) == ANIM_RANDOM && + IS_NEW_FRAME(GfxFrame[x][y], graphic)) + ResetRandomAnimationValue(x, y); + SetRandomAnimationValue(x, y); if (IS_INACTIVE(element)) @@ -6417,7 +6443,8 @@ boolean PlaceBomb(struct PlayerInfo *player) Store[jx][jy] = element; MovDelay[jx][jy] = 96; - GfxFrame[jx][jy] = 0; + + ResetGfxAnimation(jx, jy); if (player->dynamite) { diff --git a/src/libgame/system.h b/src/libgame/system.h index 0b014e8c..a08edfc6 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -318,7 +318,7 @@ struct FontInfo struct AnimInfo { - int simple_random_value; + int random_frame; }; struct JoystickInfo diff --git a/src/libgame/toons.c b/src/libgame/toons.c index 8ecc0d5d..a45720be 100644 --- a/src/libgame/toons.c +++ b/src/libgame/toons.c @@ -64,7 +64,10 @@ int getAnimationFrame(int num_frames, int delay, int mode, int start_frame, { /* note: expect different frames for the same delay cycle! */ - frame = anim.simple_random_value % num_frames; + if (anim.random_frame < 0) + frame = SimpleRND(num_frames); + else + frame = anim.random_frame % num_frames; } if (mode & ANIM_REVERSE) /* use reverse animation direction */ diff --git a/src/main.h b/src/main.h index 637d0f6e..3fc93b73 100644 --- a/src/main.h +++ b/src/main.h @@ -172,6 +172,15 @@ #define PLAYER_NR_GFX(g,i) ((g) + i * (IMG_PLAYER2 - IMG_PLAYER1)) +#define ANIM_FRAMES(g) (graphic_info[g].anim_frames) +#define ANIM_DELAY(g) (graphic_info[g].anim_delay) +#define ANIM_MODE(g) (graphic_info[g].anim_mode) + +#define IS_ANIMATED(g) (ANIM_FRAMES(g) > 1) +#define IS_NEW_FRAME(f, g) ((f) % ANIM_DELAY(g) == 0) + +#define IS_LOOP_SOUND(s) (sound_info[s].loop) + #if 0 diff --git a/src/tools.c b/src/tools.c index 7e24e501..9f42b57d 100644 --- a/src/tools.c +++ b/src/tools.c @@ -457,7 +457,7 @@ static int getGraphicAnimationPhase(int frames, int delay, int mode) void SetRandomAnimationValue(int x, int y) { - anim.simple_random_value = GfxRandom[x][y]; + anim.random_frame = GfxRandom[x][y]; } inline int getGraphicAnimationFrame(int graphic, int sync_frame) @@ -484,18 +484,18 @@ inline void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y, DrawGraphicExt(dst_bitmap, x, y, graphic, frame); } -inline boolean checkDrawGraphicAnimation(int x, int y, int graphic) +inline boolean checkDrawGraphicAnimation(int sx, int sy, int graphic) { - int lx = LEVELX(x), ly = LEVELY(y); + int lx = LEVELX(sx), ly = LEVELY(sy); - return (IN_SCR_FIELD(x, y) && - GfxFrame[lx][ly] % graphic_info[graphic].anim_delay == 0); + return (IN_SCR_FIELD(sx, sy) && IS_NEW_FRAME(GfxFrame[lx][ly], graphic)); } -inline boolean checkDrawLevelGraphicAnimation(int x, int y, int graphic) +inline boolean checkDrawLevelGraphicAnimation(int lx, int ly, int graphic) { - return (IN_SCR_FIELD(SCREENX(x), SCREENY(y)) && - GfxFrame[x][y] % graphic_info[graphic].anim_delay == 0); + int sx = SCREENX(lx), sy = SCREENY(ly); + + return (IN_SCR_FIELD(sx, sy) && IS_NEW_FRAME(GfxFrame[lx][ly], graphic)); } inline boolean DrawGraphicAnimation(int x, int y, int graphic) @@ -529,7 +529,7 @@ boolean DrawLevelElementAnimation(int x, int y, int element) inline void ContinueLevelGraphicAnimation(int x, int y, int graphic) { - if (GfxFrame[x][y] % graphic_info[graphic].anim_delay != 0) + if (!IS_NEW_FRAME(GfxFrame[x][y], graphic)) return; DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);