X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=a9c903cceb5bab85072c08f8cb43cf9fcb632eea;hb=2fe139696892ee39f804b5c7315b8f0977ab01ec;hp=ce6ca3ab084668cdfcd63662c5408697270e0fce;hpb=d4665f01d15ba3679f378819710a84d6c2348a9c;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index ce6ca3ab..a9c903cc 100644 --- a/src/game.c +++ b/src/game.c @@ -179,6 +179,50 @@ void GetPlayerConfig() InitJoysticks(); } +static int getBeltNrFromElement(int element) +{ + return (element < EL_BELT2_LEFT ? 0 : + element < EL_BELT3_LEFT ? 1 : + element < EL_BELT4_LEFT ? 2 : 3); +} + +static int getBeltNrFromSwitchElement(int element) +{ + return (element < EL_BELT2_SWITCH_L ? 0 : + element < EL_BELT3_SWITCH_L ? 1 : + element < EL_BELT4_SWITCH_L ? 2 : 3); +} + +static int getBeltDirNrFromSwitchElement(int element) +{ + static int belt_base_element[4] = + { + EL_BELT1_SWITCH_L, + EL_BELT2_SWITCH_L, + EL_BELT3_SWITCH_L, + EL_BELT4_SWITCH_L + }; + + int belt_nr = getBeltNrFromSwitchElement(element); + int belt_dir_nr = element - belt_base_element[belt_nr]; + + return (belt_dir_nr % 3); +} + +static int getBeltDirFromSwitchElement(int element) +{ + static int belt_move_dir[3] = + { + MV_LEFT, + MV_NO_MOVING, + MV_RIGHT + }; + + int belt_dir_nr = getBeltDirNrFromSwitchElement(element); + + return belt_move_dir[belt_dir_nr]; +} + static void InitField(int x, int y, boolean init_game) { switch (Feld[x][y]) @@ -322,6 +366,46 @@ static void InitField(int x, int y, boolean init_game) Feld[x][y] = EL_EM_KEY_4; break; + case EL_BELT1_SWITCH_L: + case EL_BELT1_SWITCH_M: + case EL_BELT1_SWITCH_R: + case EL_BELT2_SWITCH_L: + case EL_BELT2_SWITCH_M: + case EL_BELT2_SWITCH_R: + case EL_BELT3_SWITCH_L: + case EL_BELT3_SWITCH_M: + case EL_BELT3_SWITCH_R: + case EL_BELT4_SWITCH_L: + case EL_BELT4_SWITCH_M: + case EL_BELT4_SWITCH_R: + if (init_game) + { + int belt_nr = getBeltNrFromSwitchElement(Feld[x][y]); + int belt_dir = getBeltDirFromSwitchElement(Feld[x][y]); + int belt_dir_nr = getBeltDirNrFromSwitchElement(Feld[x][y]); + + if (game.belt_dir_nr[belt_nr] == 3) /* initial value */ + { + game.belt_dir[belt_nr] = belt_dir; + game.belt_dir_nr[belt_nr] = belt_dir_nr; + } + else /* more than one switch -- set it like the first switch */ + { + Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr]; + } + } + break; + + case EL_SWITCHGATE_SWITCH_2: /* always start with same switch pos */ + if (init_game) + Feld[x][y] = EL_SWITCHGATE_SWITCH_1; + break; + + case EL_LIGHT_SWITCH_ON: + if (init_game) + game.light_time_left = 10 * FRAMES_PER_SECOND; + break; + default: break; } @@ -423,8 +507,13 @@ void InitGame() AllPlayersGone = FALSE; game.magic_wall_active = FALSE; game.magic_wall_time_left = 0; + game.switchgate_pos = 0; + game.light_time_left = 0; for (i=0; i<4; i++) + { game.belt_dir[i] = MV_NO_MOVING; + game.belt_dir_nr[i] = 3; /* not moving, next moving left */ + } for (i=0; i0 && IS_FREE(x-1, y)); + boolean right_is_free = (x 0) + { + game.light_time_left--; + + if (game.light_time_left == 0) + { + for (y=0; y= (1000 / GameFrameDelay) && !tape.pausing) { TimeFrames = 0; @@ -4386,6 +4588,7 @@ int DigField(struct PlayerInfo *player, break; case EL_ERDREICH: + case EL_SAND_INVISIBLE: Feld[x][y] = EL_LEERRAUM; PlaySoundLevel(x, y, SND_SCHLURF); break; @@ -4423,6 +4626,11 @@ int DigField(struct PlayerInfo *player, PlaySoundLevel(x, y, SND_PONG); break; + case EL_ENVELOPE: + Feld[x][y] = EL_LEERRAUM; + PlaySoundLevel(x, y, SND_PONG); + break; + case EL_DYNAMITE_INACTIVE: case EL_SP_DISK_RED: RemoveField(x, y); @@ -4546,48 +4754,142 @@ int DigField(struct PlayerInfo *player, EL_BELT3_SWITCH_L, EL_BELT4_SWITCH_L }; - static int belt_move_dir[3] = + static int belt_move_dir[4] = { MV_LEFT, MV_NO_MOVING, - MV_RIGHT + MV_RIGHT, + MV_NO_MOVING, }; - int belt_nr = (element < EL_BELT2_SWITCH_L ? 0 : - element < EL_BELT3_SWITCH_L ? 1 : - element < EL_BELT4_SWITCH_L ? 2 : 3); - int belt_dir_nr = element - belt_base_element[belt_nr]; - int belt_dir_nr_next = (belt_dir_nr + 1) % 3; - int belt_dir_next = belt_move_dir[belt_dir_nr_next]; + int belt_nr = getBeltNrFromSwitchElement(element); + int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4; + int belt_dir = belt_move_dir[belt_dir_nr]; int xx, yy; if (player->Switching) return MF_ACTION; - game.belt_dir[belt_nr] = belt_dir_next; + player->Switching = TRUE; + + game.belt_dir_nr[belt_nr] = belt_dir_nr; + game.belt_dir[belt_nr] = belt_dir; + + if (belt_dir_nr == 3) + belt_dir_nr = 1; for (yy=0; yySwitching) + return MF_ACTION; + + player->Switching = TRUE; + + game.switchgate_pos = !game.switchgate_pos; + + for (yy=0; yySwitching) + return MF_ACTION; + player->Switching = TRUE; + game.light_time_left = + (element == EL_LIGHT_SWITCH_OFF ? 10 * FRAMES_PER_SECOND : 0); + + for (yy=0; yy 0) + { + Feld[xx][yy] = EL_LIGHT_SWITCH_ON; + DrawLevelField(xx, yy); + } + else if (element == EL_LIGHT_SWITCH_ON && + game.light_time_left == 0) + { + Feld[xx][yy] = EL_LIGHT_SWITCH_OFF; + DrawLevelField(xx, yy); + } + + if (element == EL_INVISIBLE_STEEL || + element == EL_UNSICHTBAR || + element == EL_SAND_INVISIBLE) + DrawLevelField(xx, yy); + } + } + return MF_ACTION; } break; @@ -4692,6 +4994,18 @@ int DigField(struct PlayerInfo *player, break; + case EL_SWITCHGATE_OPEN: + if (!IN_LEV_FIELD(x + dx, y + dy) || !IS_FREE(x + dx, y + dy)) + return MF_NO_ACTION; + + /* automatically move to the next field with double speed */ + player->programmed_action = move_direction; + DOUBLE_PLAYER_SPEED(player); + + PlaySoundLevel(x, y, SND_GATE); + + break; + case EL_SP_PORT1_LEFT: case EL_SP_PORT2_LEFT: case EL_SP_PORT1_RIGHT: