X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=095f635e392c97e90af23bdadabd84c3546d3eef;hb=a2f9307de12b6111ff7076fed2e4140619f1ac5d;hp=3b52b06824f111c5e8e29c792a347a32773b200f;hpb=081f176501bc84d81d6f9d27d6170e70e4a23661;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 3b52b068..095f635e 100644 --- a/src/game.c +++ b/src/game.c @@ -114,6 +114,11 @@ static void HandleGameButtons(struct GadgetInfo *); static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS]; + +/* ------------------------------------------------------------------------- */ +/* sound definitions */ +/* ------------------------------------------------------------------------- */ + #define SND_ACTION_UNKNOWN 0 #define SND_ACTION_WAITING 1 #define SND_ACTION_MOVING 2 @@ -157,6 +162,32 @@ static boolean is_loop_sound[NUM_SOUND_FILES]; #define IS_LOOP_SOUND(x) (is_loop_sound[x]) +/* ------------------------------------------------------------------------- + definition of elements that automatically change to other elements after + a specified time, eventually calling a function when changing + ------------------------------------------------------------------------- */ + +struct ChangingElementInfo +{ + int base_element; + int next_element; + int change_delay; + void (*changer_function)(int x, int y); +}; + +static struct ChangingElementInfo changing_element_list[] = +{ + { EL_NUT_CRACKING, EL_EMERALD, 6, NULL }, + { EL_PEARL_BREAKING, EL_EMPTY, 8, NULL }, + { EL_UNDEFINED, EL_UNDEFINED, -1, NULL } +}; + +static struct ChangingElementInfo changing_element[MAX_NUM_ELEMENTS]; + +#define IS_AUTO_CHANGING(e) (changing_element[e].base_element != EL_UNDEFINED) + + + #ifdef DEBUG #if 0 static unsigned int getStateCheckSum(int counter) @@ -518,6 +549,7 @@ void InitGameSound() debug_print_timestamp(0, NULL); #endif + /* initialize sound effect for all elements to "no sound" */ 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].changer_function = ce->changer_function; + + i++; } } @@ -3095,7 +3150,7 @@ void StartMoving(int x, int y) } } else if (element == EL_SP_ELECTRON) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SP_ELECTRON); + DrawLevelElementAnimation(x, y, element); else if (element == EL_DRAGON) { int i; @@ -3353,11 +3408,11 @@ 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)); + DrawLevelElementAnimation(x, y, element); else if (element == EL_SATELLITE) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SATELLITE); + DrawLevelElementAnimation(x, y, element); else if (element == EL_SP_ELECTRON) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_SP_ELECTRON); + DrawLevelElementAnimation(x, y, element); if (DONT_TOUCH(element)) TestIfBadThingTouchesHero(x, y); @@ -4132,7 +4187,7 @@ void SiebAktivieren(int x, int y, int type) { int graphic = (type == 1 ? IMG_MAGIC_WALL_FULL : IMG_BD_MAGIC_WALL_FULL); - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelGraphicAnimation(x, y, graphic); } void AusgangstuerPruefen(int x, int y) @@ -4343,7 +4398,7 @@ void EdelsteinFunkeln(int x, int y) return; if (Feld[x][y] == EL_BD_DIAMOND) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), IMG_BD_DIAMOND); + DrawLevelElementAnimation(x, y, el2img(Feld[x][y])); else { if (!MovDelay[x][y]) /* next animation frame */ @@ -4359,7 +4414,7 @@ void EdelsteinFunkeln(int x, int y) #if 0 DrawGraphic(SCREENX(x), SCREENY(y), el2img(Feld[x][y]), 0); #else - DrawGraphicAnimation(SCREENX(x), SCREENY(y), el2img(Feld[x][y])); + DrawLevelElementAnimation(x, y, Feld[x][y]); #endif if (MovDelay[x][y]) @@ -4712,15 +4767,43 @@ static void DrawBeltAnimation(int x, int y, int element) if (belt_dir != MV_NO_MOVING) { - int graphic = el2img(element); - - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelElementAnimation(x, y, element); if (!(FrameCounter % 2)) - PlaySoundLevel(x, y, SND_CONVEYOR_BELT_ACTIVE); + PlaySoundLevelAction(x, y, SND_ACTION_ACTIVE); } } +static void ChangeElement(int x, int y) +{ + int element = Feld[x][y]; + int change_delay = changing_element[element].change_delay; + + if (!MovDelay[x][y]) /* next animation frame */ + { + MovDelay[x][y] = change_delay + 1; + GfxFrame[x][y] = 0; + } + + if (MovDelay[x][y]) /* wait some time before next frame */ + { + MovDelay[x][y]--; + + if (MovDelay[x][y]) + { + DrawLevelElementAnimation(x, y, element); + + return; + } + } + + Feld[x][y] = changing_element[element].next_element; + DrawLevelField(x, y); + + if (changing_element[element].changer_function) + changing_element[element].changer_function(x, y); +} + static void PlayerActions(struct PlayerInfo *player, byte player_action) { static byte stored_player_action[MAX_PLAYERS]; @@ -5009,7 +5092,7 @@ void GameActions() #if 1 if (new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelGraphicAnimation(x, y, graphic); #endif continue; @@ -5023,7 +5106,7 @@ void GameActions() if (Feld[x][y] == EL_EMERALD && new_graphic_info[graphic].anim_frames > 1 && !IS_MOVING(x, y)) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelGraphicAnimation(x, y, graphic); #endif if (IS_GEM(element) || element == EL_SP_INFOTRON) @@ -5040,7 +5123,7 @@ void GameActions() element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY) && new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelGraphicAnimation(x, y, graphic); #endif else if (IS_MOVING(x, y)) @@ -5070,10 +5153,12 @@ void GameActions() else if (element == EL_ACID_SPLASH_LEFT || element == EL_ACID_SPLASH_RIGHT) Blurb(x, y); +#if 0 else if (element == EL_NUT_CRACKING) NussKnacken(x, y); else if (element == EL_PEARL_BREAKING) BreakingPearl(x, y); +#endif else if (element == EL_EXIT_CLOSED) AusgangstuerPruefen(x, y); else if (element == EL_SP_EXIT_CLOSED) @@ -5093,8 +5178,10 @@ void GameActions() CheckBuggyBase(x, y); else if (element == EL_TRAP || element == EL_TRAP_ACTIVE) CheckTrap(x, y); +#if 0 else if (IS_BELT_ACTIVE(element)) DrawBeltAnimation(x, y, element); +#endif else if (element == EL_SWITCHGATE_OPENING) OpenSwitchgate(x, y); else if (element == EL_SWITCHGATE_CLOSING) @@ -5104,11 +5191,17 @@ void GameActions() else if (element == EL_TIMEGATE_CLOSING) CloseTimegate(x, y); + else if (IS_AUTO_CHANGING(element)) + ChangeElement(x, y); + #if 1 else if (new_graphic_info[graphic].anim_frames > 1) - DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic); + DrawLevelGraphicAnimation(x, y, graphic); #endif + if (IS_BELT_ACTIVE(element)) + PlaySoundLevelAction(x, y, SND_ACTION_ACTIVE); + if (game.magic_wall_active) { boolean sieb = FALSE;