X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=e3fc38ba736906daf1b8440a5405bf9e6ee105d7;hb=57de370c9ad327ece8d2013095281f6b7bbda658;hp=d7fb2368f8536f59501a5dc05cbe86eb6309eda9;hpb=f5356588a234e34e349c0b1eba02008655fdee87;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index d7fb2368..e3fc38ba 100644 --- a/src/game.c +++ b/src/game.c @@ -101,8 +101,9 @@ #define NUM_GAME_BUTTONS 6 /* forward declaration for internal use */ +static void CloseAllOpenTimegates(void); static void CheckGravityMovement(struct PlayerInfo *); -static void KillHeroUnlessForceField(struct PlayerInfo *); +static void KillHeroUnlessShield(struct PlayerInfo *); static void MapGameButtons(); static void HandleGameButtons(struct GadgetInfo *); @@ -408,7 +409,7 @@ static void InitField(int x, int y, boolean init_game) case EL_LIGHT_SWITCH_ON: if (init_game) - game.light_time_left = 10 * FRAMES_PER_SECOND; + game.light_time_left = level.time_light * FRAMES_PER_SECOND; break; default: @@ -480,8 +481,8 @@ void InitGame() player->last_jx = player->last_jy = 0; player->jx = player->jy = 0; - player->force_field_passive_time_left = 0; - player->force_field_active_time_left = 0; + player->shield_passive_time_left = 0; + player->shield_active_time_left = 0; DigField(player, 0, 0, 0, 0, DF_NO_PUSH); SnapField(player, 0, 0); @@ -515,8 +516,10 @@ void InitGame() AllPlayersGone = FALSE; game.magic_wall_active = FALSE; game.magic_wall_time_left = 0; - game.switchgate_pos = 0; game.light_time_left = 0; + game.timegate_time_left = 0; + game.switchgate_pos = 0; + for (i=0; i<4; i++) { game.belt_dir[i] = MV_NO_MOVING; @@ -696,6 +699,11 @@ void InitGame() DrawAllPlayers(); FadeToFront(); + /* after drawing the level, corect some elements */ + + if (game.timegate_time_left == 0) + CloseAllOpenTimegates(); + if (setup.soft_scrolling) XCopyArea(display, fieldbuffer, backbuffer, gc, FX, FY, SXSIZE, SYSIZE, SX, SY); @@ -1257,7 +1265,7 @@ void Explode(int ex, int ey, int phase, int mode) if (IS_MASSIVE(element) || element == EL_BURNING) continue; - if (IS_PLAYER(x, y) && FORCE_FIELD_ON(PLAYERINFO(x, y))) + if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y))) { if (IS_ACTIVE_BOMB(element)) { @@ -1272,7 +1280,7 @@ void Explode(int ex, int ey, int phase, int mode) if (element == EL_EXPLODING) element = Store2[x][y]; - if (IS_PLAYER(ex, ey) && !FORCE_FIELD_ON(PLAYERINFO(ex, ey))) + if (IS_PLAYER(ex, ey) && !SHIELD_ON(PLAYERINFO(ex, ey))) { switch(StorePlayer[ex][ey]) { @@ -1373,7 +1381,7 @@ void Explode(int ex, int ey, int phase, int mode) int element = Store2[x][y]; if (IS_PLAYER(x, y)) - KillHeroUnlessForceField(PLAYERINFO(x, y)); + KillHeroUnlessShield(PLAYERINFO(x, y)); else if (IS_EXPLOSIVE(element)) { Feld[x][y] = Store2[x][y]; @@ -1650,39 +1658,79 @@ static void ToggleSwitchgateSwitch(int x, int y) } } -static void ToggleLightSwitch(int x, int y) +static void RedrawAllLightSwitchesAndInvisibleElements() { - int element = Feld[x][y]; - int xx, yy; - - game.light_time_left = - (element == EL_LIGHT_SWITCH_OFF ? 10 * FRAMES_PER_SECOND : 0); + int x, y; - for (yy=0; yy 0) { - Feld[xx][yy] = EL_LIGHT_SWITCH_ON; - DrawLevelField(xx, yy); + Feld[x][y] = EL_LIGHT_SWITCH_ON; + DrawLevelField(x, y); } else if (element == EL_LIGHT_SWITCH_ON && game.light_time_left == 0) { - Feld[xx][yy] = EL_LIGHT_SWITCH_OFF; - DrawLevelField(xx, yy); + Feld[x][y] = EL_LIGHT_SWITCH_OFF; + DrawLevelField(x, y); } if (element == EL_INVISIBLE_STEEL || element == EL_UNSICHTBAR || element == EL_SAND_INVISIBLE) + DrawLevelField(x, y); + } + } +} + +static void ToggleLightSwitch(int x, int y) +{ + int element = Feld[x][y]; + + game.light_time_left = + (element == EL_LIGHT_SWITCH_OFF ? + level.time_light * FRAMES_PER_SECOND : 0); + + RedrawAllLightSwitchesAndInvisibleElements(); +} + +static void ActivateTimegateSwitch(int x, int y) +{ + int xx, yy; + + game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND; + + for (yy=0; yy 0) + { + game.timegate_time_left--; + + if (game.timegate_time_left == 0) + CloseAllOpenTimegates(); + } + if (TimeFrames >= (1000 / GameFrameDelay)) { TimeFrames = 0; @@ -4220,12 +4374,12 @@ void GameActions() for (i=0; i 0) - stored_player[i].force_field_active_time_left--; + if (stored_player[i].shield_active_time_left > 0) + stored_player[i].shield_active_time_left--; } } @@ -4390,7 +4544,7 @@ boolean MoveFigureOneStep(struct PlayerInfo *player, #if 1 TestIfBadThingHitsHero(new_jx, new_jy); #else - if (player->force_field_time_left == 0) + if (player->shield_time_left == 0) KillHero(player); #endif } @@ -4710,9 +4864,9 @@ void TestIfGoodThingHitsBadThing(int goodx, int goody) { struct PlayerInfo *player = PLAYERINFO(goodx, goody); - if (player->force_field_active_time_left > 0) + if (player->shield_active_time_left > 0) Bang(killx, killy); - else if (player->force_field_passive_time_left == 0) + else if (player->shield_passive_time_left == 0) KillHero(player); } else @@ -4772,9 +4926,9 @@ void TestIfBadThingHitsGoodThing(int badx, int bady) { struct PlayerInfo *player = PLAYERINFO(killx, killy); - if (player->force_field_active_time_left > 0) + if (player->shield_active_time_left > 0) Bang(badx, bady); - else if (player->force_field_passive_time_left == 0) + else if (player->shield_passive_time_left == 0) KillHero(player); } else @@ -4846,17 +5000,17 @@ void KillHero(struct PlayerInfo *player) if (IS_PFORTE(Feld[jx][jy])) Feld[jx][jy] = EL_LEERRAUM; - /* deactivate force field (else Bang()/Explode() would not work right) */ - player->force_field_passive_time_left = 0; - player->force_field_active_time_left = 0; + /* deactivate shield (else Bang()/Explode() would not work right) */ + player->shield_passive_time_left = 0; + player->shield_active_time_left = 0; Bang(jx, jy); BuryHero(player); } -static void KillHeroUnlessForceField(struct PlayerInfo *player) +static void KillHeroUnlessShield(struct PlayerInfo *player) { - if (!FORCE_FIELD_ON(player)) + if (!SHIELD_ON(player)) KillHero(player); } @@ -4981,16 +5135,16 @@ int DigField(struct PlayerInfo *player, PlaySoundStereo(SND_GONG, PSND_MAX_RIGHT); break; - case EL_FORCE_FIELD_PASSIVE: + case EL_SHIELD_PASSIVE: RemoveField(x, y); - player->force_field_passive_time_left += 10; + player->shield_passive_time_left += 10; PlaySoundLevel(x, y, SND_PONG); break; - case EL_FORCE_FIELD_ACTIVE: + case EL_SHIELD_ACTIVE: RemoveField(x, y); - player->force_field_passive_time_left += 10; - player->force_field_active_time_left += 10; + player->shield_passive_time_left += 10; + player->shield_active_time_left += 10; PlaySoundLevel(x, y, SND_PONG); break; @@ -5137,6 +5291,12 @@ int DigField(struct PlayerInfo *player, return MF_ACTION; break; + case EL_TIMEGATE_SWITCH_OFF: + ActivateTimegateSwitch(x, y); + + return MF_ACTION; + break; + case EL_SP_EXIT: if (local_player->gems_still_needed > 0) return MF_NO_ACTION; @@ -5238,6 +5398,7 @@ int DigField(struct PlayerInfo *player, break; case EL_SWITCHGATE_OPEN: + case EL_TIMEGATE_OPEN: if (!IN_LEV_FIELD(x + dx, y + dy) || !IS_FREE(x + dx, y + dy)) return MF_NO_ACTION;