X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=01d6b72cc2d7df39362f53fe104ae13062ed4192;hb=19b6c35938826bfd71478d7ddaf1a4729420d3b2;hp=46bbbf21fe046ac1bdae9a8e52ec5b9b9ff95717;hpb=046d80f9a1b3fad9d4d3d3aa92dcb3689849aebf;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 46bbbf21..01d6b72c 100644 --- a/src/game.c +++ b/src/game.c @@ -20,6 +20,12 @@ #include "init.h" #include "buttons.h" #include "files.h" +#include "tape.h" +#include "joystick.h" + +extern int Gamespeed; +extern int Movemethod; +extern int Movespeed[2]; void GetPlayerConfig() { @@ -33,15 +39,17 @@ void GetPlayerConfig() player.setup &= ~SETUP_SOUND_MUSIC; } - sound_on = SETUP_SOUND_ON(player.setup); + sound_on = sound_simple_on = SETUP_SOUND_ON(player.setup); sound_loops_on = SETUP_SOUND_LOOPS_ON(player.setup); sound_music_on = SETUP_SOUND_MUSIC_ON(player.setup); toons_on = SETUP_TOONS_ON(player.setup); direct_draw_on = SETUP_DIRECT_DRAW_ON(player.setup); fading_on = SETUP_FADING_ON(player.setup); - autorecord_on = SETUP_RECORD_EACH_GAME_ON(player.setup); + autorecord_on = SETUP_AUTO_RECORD_ON(player.setup); joystick_nr = SETUP_2ND_JOYSTICK_ON(player.setup); quick_doors = SETUP_QUICK_DOORS_ON(player.setup); + scroll_delay_on = SETUP_SCROLL_DELAY_ON(player.setup); + soft_scrolling_on = SETUP_SOFT_SCROLL_ON(player.setup); if (joystick_nr != old_joystick_nr) { @@ -54,29 +62,33 @@ void GetPlayerConfig() void InitGame() { int i,x,y; + BOOL emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */ + BOOL emulate_sb = TRUE; /* unless non-SOKOBAN elements found */ Dynamite = Score = 0; Gems = level.edelsteine; + SokobanFields = Lights = Friends = 0; DynaBombCount = DynaBombSize = DynaBombsLeft = 0; + DynaBombXL = FALSE; Key[0] = Key[1] = Key[2] = Key[3] = FALSE; MampferNr = 0; + FrameCounter = 0; + TimeFrames = 0; TimeLeft = level.time; - CheckMoving = TRUE; - CheckExploding = FALSE; - LevelSolved = GameOver = SiebAktiv = FALSE; + ScreenMovPos = 0; + PlayerMovDir = MV_NO_MOVING; + PlayerMovPos = 0; + PlayerFrame = 0; + PlayerPushing = FALSE; + PlayerGone = LevelSolved = GameOver = SiebAktiv = FALSE; JX = JY = 0; ZX = ZY = -1; - if (tape.recording) - TapeStartRecording(); - else if (tape.playing) - TapeStartPlaying(); - - DigField(0,0,DF_NO_PUSH); + DigField(0,0,0,0,DF_NO_PUSH); SnapField(0,0); for(i=0;i=MIDPOSX-1) scroll_x = @@ -151,6 +199,8 @@ void InitGame() scroll_y = (JY<=lev_fieldy-MIDPOSY ? JY-MIDPOSY : lev_fieldy-SCR_FIELDY+1); + CloseDoor(DOOR_CLOSE_1); + DrawLevel(); DrawLevelElement(JX,JY,EL_SPIELFIGUR); FadeToFront(); @@ -177,9 +227,9 @@ void InitGame() DrawGameButton(BUTTON_GAME_STOP); DrawGameButton(BUTTON_GAME_PAUSE); DrawGameButton(BUTTON_GAME_PLAY); - DrawSoundDisplay(BUTTON_SOUND_MUSIC | (BUTTON_ON * sound_music_on)); - DrawSoundDisplay(BUTTON_SOUND_LOOPS | (BUTTON_ON * sound_loops_on)); - DrawSoundDisplay(BUTTON_SOUND_SOUND | (BUTTON_ON * sound_on)); + DrawSoundDisplay(BUTTON_SOUND_MUSIC | (BUTTON_ON * sound_music_on)); + DrawSoundDisplay(BUTTON_SOUND_LOOPS | (BUTTON_ON * sound_loops_on)); + DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on)); XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc, DX+GAME_CONTROL_XPOS,DY+GAME_CONTROL_YPOS, GAME_CONTROL_XSIZE,2*GAME_CONTROL_YSIZE, @@ -199,15 +249,15 @@ void InitMovDir(int x, int y) int i, element = Feld[x][y]; static int xy[4][2] = { - 0,+1, - +1,0, - 0,-1, - -1,0 + { 0,+1 }, + { +1,0 }, + { 0,-1 }, + { -1,0 } }; static int direction[2][4] = { - MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN, - MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP + { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN }, + { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP } }; switch(element) @@ -226,6 +276,20 @@ void InitMovDir(int x, int y) Feld[x][y] = EL_FLIEGER; MovDir[x][y] = direction[0][element-EL_FLIEGER_R]; break; + case EL_BUTTERFLY_R: + case EL_BUTTERFLY_O: + case EL_BUTTERFLY_L: + case EL_BUTTERFLY_U: + Feld[x][y] = EL_BUTTERFLY; + MovDir[x][y] = direction[0][element-EL_BUTTERFLY_R]; + break; + case EL_FIREFLY_R: + case EL_FIREFLY_O: + case EL_FIREFLY_L: + case EL_FIREFLY_U: + Feld[x][y] = EL_FIREFLY; + MovDir[x][y] = direction[0][element-EL_FIREFLY_R]; + break; case EL_PACMAN_R: case EL_PACMAN_O: case EL_PACMAN_L: @@ -235,7 +299,10 @@ void InitMovDir(int x, int y) break; default: MovDir[x][y] = 1<0) + if (TimeLeft) { - for(;TimeLeft>=0;TimeLeft--) + if (sound_loops_on) + PlaySoundExt(SND_SIRR,PSND_MAX_VOLUME,PSND_MAX_RIGHT,PSND_LOOP); + + while(TimeLeft>0) { if (!sound_loops_on) PlaySoundStereo(SND_SIRR,PSND_MAX_RIGHT); if (TimeLeft && !(TimeLeft % 10)) RaiseScore(level.score[SC_ZEITBONUS]); + if (TimeLeft > 100 && !(TimeLeft % 10)) + TimeLeft -= 10; + else + TimeLeft--; DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW); BackToFront(); Delay(10000); } + + if (sound_loops_on) + StopSound(SND_SIRR); } - if (sound_loops_on) - StopSound(SND_SIRR); FadeSounds(); + /* Hero disappears */ + DrawLevelElement(ExitX,ExitY,Feld[ExitX][ExitY]); + BackToFront(); + if (tape.playing) return; CloseDoor(DOOR_CLOSE_1); + if (tape.recording) + { + TapeStop(); + SaveLevelTape(tape.level_nr); /* Ask to save tape */ + } + if (level_nr==player.handicap && - level_nr6) - phase = 6; - if (Store[x][y]) + DrawGraphic(sx,sy, el2gfx(Store[x][y])); + + if (Feld[x][y]==EL_DYNAMIT) { - DrawGraphic(SCROLLX(x),SCROLLY(y),el2gfx(Store[x][y])); - if (PLAYER(x,y)) - DrawGraphicThruMask(SCROLLX(JX),SCROLLY(JY),GFX_SPIELFIGUR); + if ((phase = (48-MovDelay[x][y])/6) > 6) + phase = 6; + } + else + { + if ((phase = ((48-MovDelay[x][y])/3) % 8) > 3) + phase = 7-phase; } - else if (PLAYER(x,y)) - DrawGraphic(SCROLLX(JX),SCROLLY(JY),GFX_SPIELFIGUR); - if (Store[x][y] || PLAYER(x,y)) - DrawGraphicThruMask(SCROLLX(x),SCROLLY(y),GFX_DYNAMIT+phase); + if (Store[x][y]) + DrawGraphicThruMask(sx,sy, graphic + phase); else - DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_DYNAMIT+phase); + DrawGraphic(sx,sy, graphic + phase); } void CheckDynamite(int x, int y) { - CheckExploding = TRUE; - if (MovDelay[x][y]) /* neues Dynamit / in Wartezustand */ { MovDelay[x][y]--; if (MovDelay[x][y]) { if (!(MovDelay[x][y] % 6)) - { - DrawDynamite(x,y); PlaySoundLevel(x,y,SND_ZISCH); - } + + if (Feld[x][y]==EL_DYNAMIT && !(MovDelay[x][y] % 6)) + DrawDynamite(x,y); + else if (Feld[x][y]==EL_DYNABOMB && !(MovDelay[x][y] % 3)) + DrawDynamite(x,y); return; } @@ -538,14 +639,23 @@ void Explode(int ex, int ey, int phase, int mode) { int center_element = Feld[ex][ey]; - if (center_element==EL_BLOCKED) + if (IS_MOVING(ex,ey) || IS_BLOCKED(ex,ey)) + { center_element = MovingOrBlocked2Element(ex,ey); + RemoveMovingField(ex,ey); + } for(y=ey-1;y rnd_value/8) + MovDir[x][y] = old_move_dir; + else if (can_turn_left && can_turn_right) + MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir); + else if (can_turn_left && rnd > rnd_value/8) + MovDir[x][y] = left_dir; + else if (can_turn_right && rnd > rnd_value/8) + MovDir[x][y] = right_dir; + else + MovDir[x][y] = back_dir; + + if (!IS_FREE(x+move_xy[MovDir[x][y]].x,y+move_xy[MovDir[x][y]].y) && + !IS_GEM(Feld[x+move_xy[MovDir[x][y]].x][y+move_xy[MovDir[x][y]].y])) + MovDir[x][y] = old_move_dir; + + MovDelay[x][y] = 0; + } + else if (element==EL_DRACHE) + { + BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE; + int rnd_value = 24; + int rnd = RND(rnd_value); + + if (IN_LEV_FIELD(left_x,left_y) && IS_FREE(left_x,left_y)) + can_turn_left = TRUE; + if (IN_LEV_FIELD(right_x,right_y) && IS_FREE(right_x,right_y)) + can_turn_right = TRUE; + if (IN_LEV_FIELD(move_x,move_y) && IS_FREE(move_x,move_y)) + can_move_on = TRUE; + + if (can_move_on && rnd > rnd_value/8) + MovDir[x][y] = old_move_dir; + else if (can_turn_left && can_turn_right) + MovDir[x][y] = (rnd < rnd_value/2 ? left_dir : right_dir); + else if (can_turn_left && rnd > rnd_value/8) + MovDir[x][y] = left_dir; + else if (can_turn_right && rnd > rnd_value/8) + MovDir[x][y] = right_dir; + else + MovDir[x][y] = back_dir; + + if (!IS_FREE(x+move_xy[MovDir[x][y]].x,y+move_xy[MovDir[x][y]].y)) + MovDir[x][y] = old_move_dir; - MovDelay[x][y]=3+RND(20); + MovDelay[x][y] = 0; } - else if (element==EL_ZOMBIE) + else if (element==EL_ROBOT || element==EL_SONDE || + element==EL_MAULWURF || element==EL_PINGUIN) { int attr_x = JX, attr_y = JY; + int newx, newy; + + if (PlayerGone) + { + attr_x = ExitX; + attr_y = ExitY; + } - if (ZX>=0 && ZY>=0) + if (element==EL_ROBOT && ZX>=0 && ZY>=0) { attr_x = ZX; attr_y = ZY; } - MovDir[x][y]=MV_NO_MOVING; + if (element==EL_MAULWURF || element==EL_PINGUIN) + { + int i; + static int xy[4][2] = + { + { 0,-1 }, + { -1,0 }, + { +1,0 }, + { 0,+1 } + }; + + for(i=0;i<4;i++) + { + int ex = x+xy[i%4][0]; + int ey = y+xy[i%4][1]; + + if (IN_LEV_FIELD(ex,ey) && Feld[ex][ey] == EL_AUSGANG_AUF) + { + attr_x = ex; + attr_y = ey; + break; + } + } + } + + MovDir[x][y] = MV_NO_MOVING; if (attr_xx) - MovDir[x][y]|=MV_RIGHT; + MovDir[x][y] |= (GameOver ? MV_LEFT : MV_RIGHT); if (attr_yy) - MovDir[x][y]|=MV_DOWN; - if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN))) - MovDir[x][y] &= (RND(2) ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN)); + MovDir[x][y] |= (GameOver ? MV_UP : MV_DOWN); + + if (element==EL_ROBOT) + { + if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN))) + MovDir[x][y] &= (RND(2) ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN)); + Moving2Blocked(x,y,&newx,&newy); + + if (IN_LEV_FIELD(newx,newy) && IS_FREE_OR_PLAYER(newx,newy)) + MovDelay[x][y] = 4+4*!RND(3); + else + MovDelay[x][y] = 8; + } + else + { + MovDelay[x][y] = 1; + + if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN))) + { + BOOL first_horiz = RND(2); + int new_move_dir = MovDir[x][y]; + + MovDir[x][y] = + new_move_dir & (first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN)); + Moving2Blocked(x,y,&newx,&newy); + + if (IN_LEV_FIELD(newx,newy) && + (IS_FREE(newx,newy) || + Feld[newx][newy] == EL_SALZSAEURE || + ((element == EL_MAULWURF || element==EL_PINGUIN) && + (Feld[newx][newy] == EL_AUSGANG_AUF || + IS_MAMPF3(Feld[newx][newy]))))) + return; + + MovDir[x][y] = + new_move_dir & (!first_horiz ? (MV_LEFT|MV_RIGHT) : (MV_UP|MV_DOWN)); + Moving2Blocked(x,y,&newx,&newy); + + if (IN_LEV_FIELD(newx,newy) && + (IS_FREE(newx,newy) || + Feld[newx][newy] == EL_SALZSAEURE || + ((element == EL_MAULWURF || element==EL_PINGUIN) && + (Feld[newx][newy] == EL_AUSGANG_AUF || + IS_MAMPF3(Feld[newx][newy]))))) + return; - MovDelay[x][y] = 8+8*RND(2); + MovDir[x][y] = old_move_dir; + return; + } + } } } @@ -1081,8 +1402,6 @@ void StartMoving(int x, int y) } else if (Feld[x][y+1]==EL_MORAST_LEER) { - CheckMoving = TRUE; - if (!MovDelay[x][y]) MovDelay[x][y] = 16; @@ -1110,6 +1429,23 @@ void StartMoving(int x, int y) Feld[x][y] = EL_CHANGED(Store2[x][y]); Store[x][y] = EL_SIEB_LEER; } + else if (Feld[x][y+1]==EL_SIEB_LEER) + { + if (!MovDelay[x][y]) + MovDelay[x][y] = 2; + + if (MovDelay[x][y]) + { + MovDelay[x][y]--; + if (MovDelay[x][y]) + return; + } + + Feld[x][y] = EL_SIEB_LEER; + Feld[x][y+1] = EL_SIEB_VOLL; + Store2[x][y+1] = EL_CHANGED(Store2[x][y]); + Store2[x][y] = 0; + } } else if (element==EL_SIEB2_VOLL) { @@ -1119,15 +1455,31 @@ void StartMoving(int x, int y) Feld[x][y] = EL_CHANGED2(Store2[x][y]); Store[x][y] = EL_SIEB2_LEER; } + else if (Feld[x][y+1]==EL_SIEB2_LEER) + { + if (!MovDelay[x][y]) + MovDelay[x][y] = 2; + + if (MovDelay[x][y]) + { + MovDelay[x][y]--; + if (MovDelay[x][y]) + return; + } + + Feld[x][y] = EL_SIEB2_LEER; + Feld[x][y+1] = EL_SIEB2_VOLL; + Store2[x][y+1] = EL_CHANGED2(Store2[x][y]); + Store2[x][y] = 0; + } } - else if (CAN_CHANGE(element) && + else if (SiebAktiv && CAN_CHANGE(element) && (Feld[x][y+1]==EL_SIEB_LEER || Feld[x][y+1]==EL_SIEB2_LEER)) { InitMovingField(x,y,MV_DOWN); Store[x][y] = (Feld[x][y+1]==EL_SIEB_LEER ? EL_SIEB_VOLL : EL_SIEB2_VOLL); Store2[x][y+1] = element; - SiebAktiv = 330; } else if (CAN_SMASH(element) && Feld[x][y+1]==EL_SALZSAEURE) { @@ -1150,15 +1502,16 @@ void StartMoving(int x, int y) } else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1]) { - int left = (x>0 && IS_FREE(x-1,y) && - (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE)); - int right = (x0 && IS_FREE(x-1,y) && + (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE)); + BOOL right = (x= 200 && element==EL_AMOEBE_BD) + { + AmoebeUmwandeln2(newax,neway,EL_FELSBROCKEN); + return; + } } } @@ -1638,8 +2185,6 @@ void Life(int ax, int ay) int life_time = 20; int element = Feld[ax][ay]; - CheckExploding = TRUE; - if (Stop[ax][ay]) return; @@ -1668,7 +2213,7 @@ void Life(int ax, int ay) if (!IN_LEV_FIELD(x,y) || (x==xx && y==yy)) continue; - if (((Feld[x][y]==element || (element==EL_LIFE && PLAYER(x,y))) && + if (((Feld[x][y]==element || (element==EL_LIFE && IS_PLAYER(x,y))) && !Stop[x][y]) || (IS_FREE(x,y) && Stop[x][y])) nachbarn++; @@ -1700,10 +2245,9 @@ void Life(int ax, int ay) void Ablenk(int x, int y) { - CheckExploding = TRUE; - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ - MovDelay[x][y] = 33*(level.dauer_ablenk/10); + MovDelay[x][y] = level.dauer_ablenk * FRAMES_PER_SECOND; + if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ { MovDelay[x][y]--; @@ -1717,16 +2261,14 @@ void Ablenk(int x, int y) } } - Feld[x][y]=EL_ABLENK_AUS; + Feld[x][y] = EL_ABLENK_AUS; DrawLevelField(x,y); if (ZX==x && ZY==y) - ZX=ZY=-1; + ZX = ZY = -1; } void Birne(int x, int y) { - CheckExploding = TRUE; - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ MovDelay[x][y] = 400; @@ -1756,26 +2298,11 @@ void Birne(int x, int y) void Blubber(int x, int y) { - CheckExploding = TRUE; - - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ - MovDelay[x][y] = 20; - - if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ - { - int blubber; - - MovDelay[x][y]--; - blubber = MovDelay[x][y]/5; - if (!(MovDelay[x][y]%5) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) - DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_GEBLUBBER+3-blubber); - } + DrawGraphicAnimation(x,y, GFX_GEBLUBBER, 4, 5, ANIM_NORMAL); } void NussKnacken(int x, int y) { - CheckExploding = TRUE; - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ MovDelay[x][y] = 4; @@ -1795,32 +2322,14 @@ void NussKnacken(int x, int y) void SiebAktivieren(int x, int y, int typ) { - CheckExploding = TRUE; - - if (SiebAktiv>1) - { - if (SiebAktiv%2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) - DrawGraphic(SCROLLX(x),SCROLLY(y), - (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%8)/2); - -/* - if (!(SiebAktiv%4)) - PlaySoundLevel(x,y,SND_MIEP); -*/ - - } - else - { - Feld[x][y] = (typ==1 ? EL_SIEB_TOT : EL_SIEB2_TOT); - DrawLevelField(x,y); - } + if (SiebAktiv%2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) + DrawGraphic(SCROLLX(x),SCROLLY(y), + (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%8)/2); } void AusgangstuerPruefen(int x, int y) { - CheckExploding = TRUE; - - if (!Gems) + if (!Gems && !SokobanFields && !Lights) { Feld[x][y] = EL_AUSGANG_ACT; PlaySoundLevel(x,y,SND_OEFFNEN); @@ -1831,8 +2340,6 @@ void AusgangstuerOeffnen(int x, int y) { int speed = 3; - CheckExploding = TRUE; - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ MovDelay[x][y] = 5*speed; @@ -1855,44 +2362,59 @@ void AusgangstuerOeffnen(int x, int y) void AusgangstuerBlinken(int x, int y) { - CheckExploding = TRUE; + DrawGraphicAnimation(x,y, GFX_AUSGANG_AUF, 4, 2, ANIM_OSCILLATE); +} - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ - MovDelay[x][y] = 16; +void EdelsteinFunkeln(int x, int y) +{ + if (!IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)) || IS_MOVING(x,y)) + return; - if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ + if (Feld[x][y] == EL_EDELSTEIN_BD) { - int phase; + const int delay = 2; + const int frames = 4; + int phase = (FrameCounter % (delay*frames)) / delay; - MovDelay[x][y]--; - phase = (MovDelay[x][y] % 16)/2; - if (phase>3) - phase = 7-phase; - if (!(MovDelay[x][y]%2) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) - DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_AUSGANG_AUF+phase); + if (!(FrameCounter % delay)) + DrawGraphic(SCROLLX(x),SCROLLY(y), GFX_EDELSTEIN_BD - phase); } -} + else + { + if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ + MovDelay[x][y] = 6*!SimpleRND(500); -void EdelsteinFunkeln(int x, int y) -{ - int speed = 2; + if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ + { + MovDelay[x][y]--; - CheckExploding = TRUE; + if (direct_draw_on && MovDelay[x][y]) + SetDrawtoField(DRAW_BUFFERED); - if (IS_MOVING(x,y)) - return; + DrawGraphic(SCROLLX(x),SCROLLY(y), el2gfx(Feld[x][y])); - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ - MovDelay[x][y] = 4*speed; + if (MovDelay[x][y]) + { + int src_x,src_y, dest_x,dest_y; + int phase = MovDelay[x][y]-1; - if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ - { - int phase; + src_x = SX+GFX_PER_LINE*TILEX; + src_y = SY+(phase > 2 ? 4-phase : phase)*TILEY; + dest_x = FX+SCROLLX(x)*TILEX; + dest_y = FY+SCROLLY(y)*TILEY; - MovDelay[x][y]--; - phase = MovDelay[x][y]/speed; - if (!(MovDelay[x][y]%speed) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) - DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_EDELSTEIN2-phase); + XSetClipOrigin(display,clip_gc[PIX_BACK],dest_x-src_x,dest_y-src_y); + XCopyArea(display,pix[PIX_BACK],drawto_field,clip_gc[PIX_BACK], + src_x,src_y, TILEX,TILEY, dest_x,dest_y); + + if (direct_draw_on) + { + XCopyArea(display,drawto_field,window,gc, + dest_x,dest_y, TILEX,TILEY, dest_x,dest_y); + SetDrawtoField(DRAW_DIRECT); + } + } + } } } @@ -1900,8 +2422,6 @@ void MauerWaechst(int x, int y) { int speed = 3; - CheckExploding = TRUE; - if (!MovDelay[x][y]) /* neue Phase / noch nicht gewartet */ MovDelay[x][y] = 3*speed; @@ -1940,8 +2460,6 @@ void MauerAbleger(int ax, int ay) BOOL links_frei = FALSE, rechts_frei = FALSE; BOOL links_massiv = FALSE, rechts_massiv = FALSE; - CheckExploding = TRUE; - if (!MovDelay[ax][ay]) /* neue Mauer / noch nicht gewartet */ MovDelay[ax][ay] = 3; @@ -1984,62 +2502,136 @@ void MauerAbleger(int ax, int ay) Feld[ax][ay] = EL_MAUERWERK; } -int GameActions(int mx, int my, int button) +void CheckForDragon(int x, int y) { - static long time_delay=0, action_delay=0; - int Action; - - if (TimeLeft>0 && DelayReached(&time_delay,100) && !tape.pausing) + int i,j; + BOOL dragon_found = FALSE; + static int xy[4][2] = { - TimeLeft--; + { 0,-1 }, + { -1,0 }, + { +1,0 }, + { 0,+1 } + }; - if (tape.recording || tape.playing) - DrawVideoDisplay(VIDEO_STATE_TIME_ON,level.time-TimeLeft); + for(i=0;i<4;i++) + { + for(j=0;j<4;j++) + { + int xx = x + j*xy[i][0], yy = y + j*xy[i][1]; - if (TimeLeft<=10) - PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT); + if (IN_LEV_FIELD(xx,yy) && + (Feld[xx][yy] == EL_BURNING || Feld[xx][yy] == EL_DRACHE)) + { + if (Feld[xx][yy] == EL_DRACHE) + dragon_found = TRUE; + } + else + break; + } + } - DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW); - BackToFront(); + if (!dragon_found) + { + for(i=0;i<4;i++) + { + for(j=0;j<3;j++) + { + int xx = x + j*xy[i][0], yy = y + j*xy[i][1]; + + if (IN_LEV_FIELD(xx,yy) && Feld[xx][yy] == EL_BURNING) + { + Feld[xx][yy] = EL_LEERRAUM; + DrawLevelField(xx,yy); + } + else + break; + } + } } +} - if (!TimeLeft) - KillHero(); +void GameActions() +{ + static long action_delay=0; + long action_delay_value; - Action = (CheckMoving || CheckExploding || SiebAktiv); + if (game_status != PLAYING) + return; /* - if (Action && DelayReached(&action_delay,3)) + action_delay_value = + (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY); */ - if (DelayReached(&action_delay,3)) + action_delay_value = + (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : Gamespeed); + + /* + if (DelayReached(&action_delay, action_delay_value)) + */ + + + + if (PlayerMovPos) + ScrollFigure(0); + + DrawPlayerField(); + + + + + if (!DelayReached(&action_delay, action_delay_value)) + return; + { int x,y,element; + int sieb_x = 0, sieb_y = 0; if (tape.pausing || (tape.playing && !TapePlayDelay())) - return(ACT_GO_ON); + return; else if (tape.recording) TapeRecordDelay(); - CheckMoving = CheckExploding = FALSE; + FrameCounter++; + TimeFrames++; + for(y=0;y0) JustHit[x][y]--; + +#if DEBUG + if (IS_BLOCKED(x,y)) + { + int oldx,oldy; + + Blocked2Moving(x,y,&oldx,&oldy); + if (!IS_MOVING(oldx,oldy)) + { + printf("GameActions(): (BLOCKED=>MOVING) context corrupted!\n"); + printf("GameActions(): BLOCKED: x = %d, y = %d\n",x,y); + printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n",oldx,oldy); + printf("GameActions(): This should never happen!\n"); + } + } +#endif + } for(y=0;y0 && TimeFrames>=25 && !tape.pausing) + { + TimeFrames = 0; + TimeLeft--; + + if (tape.recording || tape.playing) + DrawVideoDisplay(VIDEO_STATE_TIME_ON,level.time-TimeLeft); + + if (TimeLeft<=10) + PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT); + + DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW); + + if (!TimeLeft) + KillHero(); } - return(ACT_GO_ON); + /* + if (PlayerMovPos) + ScrollFigure(0); + */ + + + /* + DrawPlayerField(); + */ + + + DrawPlayerField(); + + + BackToFront(); } void ScrollLevel(int dx, int dy) { int x,y; + int softscroll_offset = (FX == TILEX ? TILEX : 0); + + if (soft_scrolling_on) + { + ScreenMovPos = PlayerMovPos; + redraw_mask |= REDRAW_FIELD; + } XCopyArea(display,drawto_field,drawto_field,gc, - SX+TILEX*(dx==-1),SY+TILEY*(dy==-1), - SXSIZE-TILEX*(dx!=0),SYSIZE-TILEY*(dy!=0), - SX+TILEX*(dx==1),SY+TILEY*(dy==1)); + FX + TILEX*(dx==-1) - softscroll_offset, + FY + TILEY*(dy==-1) - softscroll_offset, + SXSIZE - TILEX*(dx!=0) + 2*softscroll_offset, + SYSIZE - TILEY*(dy!=0) + 2*softscroll_offset, + FX + TILEX*(dx==1) - softscroll_offset, + FY + TILEY*(dy==1) - softscroll_offset); if (dx) { - x = dx==1 ? 0 : SCR_FIELDX-1; - for(y=0;y 0 ? MV_RIGHT : + dy < 0 ? MV_UP : + dy > 0 ? MV_DOWN : MV_NO_MOVING); +/* + if (old_move_dir != PlayerMovDir) + PlayerFrame = 0; + else + PlayerFrame = (PlayerFrame + 1) % 4; +*/ + if (!IN_LEV_FIELD(newJX,newJY)) return(MF_NO_ACTION); @@ -2141,11 +2832,7 @@ BOOL MoveFigureOneStep(int dx, int dy) InitMovingField(JX,JY,MV_DOWN); Store[JX][JY] = EL_SALZSAEURE; ContinueMoving(JX,JY); - - PlaySoundLevel(JX,JY,SND_AUTSCH); - PlaySoundLevel(JX,JY,SND_LACHEN); - GameOver = TRUE; - JX = JY = -1; + BuryHero(); } else KillHero(); @@ -2153,7 +2840,7 @@ BOOL MoveFigureOneStep(int dx, int dy) return(MF_MOVING); } - can_move = DigField(newJX,newJY,DF_DIG); + can_move = DigField(newJX,newJY, real_dx,real_dy, DF_DIG); if (can_move != MF_MOVING) return(can_move); @@ -2162,6 +2849,14 @@ BOOL MoveFigureOneStep(int dx, int dy) JX = newJX; JY = newJY; + + JX2 = oldJX; + JY2 = oldJY; + + PlayerMovPos = (dx > 0 || dy > 0 ? -1 : 1) * 3*TILEX/4; + + ScrollFigure(-1); + if (Store[oldJX][oldJY]) { DrawGraphic(SCROLLX(oldJX),SCROLLY(oldJY),el2gfx(Store[oldJX][oldJY])); @@ -2179,78 +2874,193 @@ BOOL MoveFigureOneStep(int dx, int dy) BOOL MoveFigure(int dx, int dy) { static long move_delay = 0; + static int last_move_dir = MV_NO_MOVING; int moved = MF_NO_ACTION; + int oldJX = JX, oldJY = JY; + + if (PlayerGone || (!dx && !dy)) + return(FALSE); - if (GameOver || (!dx && !dy)) +/* + if (!DelayReached(&move_delay,8) && !tape.playing) return(FALSE); +*/ +/* if (!DelayReached(&move_delay,10) && !tape.playing) return(FALSE); +*/ + +/* + if (!FrameReached(&move_delay,2) && !tape.playing) + return(FALSE); +*/ + + if (Movemethod == 0) + { + if (!DelayReached(&move_delay,Movespeed[0]) && !tape.playing) + return(FALSE); + } + else + { + if (!FrameReached(&move_delay,Movespeed[1]) && !tape.playing) + return(FALSE); + } + + + if (last_move_dir & (MV_LEFT | MV_RIGHT)) + { + if (!(moved |= MoveFigureOneStep(0,dy, dx,dy))) + moved |= MoveFigureOneStep(dx,0, dx,dy); + } + else + { + if (!(moved |= MoveFigureOneStep(dx,0, dx,dy))) + moved |= MoveFigureOneStep(0,dy, dx,dy); + } - if (moved |= MoveFigureOneStep(dx,0)) - moved |= MoveFigureOneStep(0,dy); + last_move_dir = MV_NO_MOVING; + + + /* + if (moved |= MoveFigureOneStep(dx,0, dx,dy)) + moved |= MoveFigureOneStep(0,dy, dx,dy); else { - moved |= MoveFigureOneStep(0,dy); - moved |= MoveFigureOneStep(dx,0); + moved |= MoveFigureOneStep(0,dy, dx,dy); + moved |= MoveFigureOneStep(dx,0, dx,dy); } + */ if (moved & MF_MOVING) { int old_scroll_x=scroll_x, old_scroll_y=scroll_y; + int offset = (scroll_delay_on ? 3 : 0); - if (scroll_x!=JX-MIDPOSX && JX>=MIDPOSX-1 && JX<=lev_fieldx-MIDPOSX) - scroll_x = JX-MIDPOSX; - if (scroll_y!=JY-MIDPOSY && JY>=MIDPOSY-1 && JY<=lev_fieldy-MIDPOSY) - scroll_y = JY-MIDPOSY; + if ((scroll_x < JX-MIDPOSX-offset || scroll_x > JX-MIDPOSX+offset) && + JX>=MIDPOSX-1-offset && JX<=lev_fieldx-(MIDPOSX-offset)) + scroll_x = JX-MIDPOSX + (scroll_x < JX-MIDPOSX ? -offset : offset); + if ((scroll_y < JY-MIDPOSY-offset || scroll_y > JY-MIDPOSY+offset) && + JY>=MIDPOSY-1-offset && JY<=lev_fieldy-(MIDPOSY-offset)) + scroll_y = JY-MIDPOSY + (scroll_y < JY-MIDPOSY ? -offset : offset); if (scroll_x!=old_scroll_x || scroll_y!=old_scroll_y) ScrollLevel(old_scroll_x-scroll_x,old_scroll_y-scroll_y); + } - if (Feld[JX][JY]==EL_LEERRAUM) - DrawLevelElement(JX,JY,EL_SPIELFIGUR); - else - DrawGraphicThruMask(SCROLLX(JX),SCROLLY(JY),GFX_SPIELFIGUR); + if (!(moved & MF_MOVING) && !PlayerPushing) + PlayerFrame = 0; + else + PlayerFrame = (PlayerFrame + 1) % 4; + + if (moved & MF_MOVING) + { + if (oldJX != JX && oldJY == JY) + PlayerMovDir = (oldJX < JX ? MV_RIGHT : MV_LEFT); + else if (oldJX == JX && oldJY != JY) + PlayerMovDir = (oldJY < JY ? MV_DOWN : MV_UP); + + DrawLevelField(JX,JY); /* für "ErdreichAnbroeckeln()" */ + + last_move_dir = PlayerMovDir; } TestIfHeroHitsBadThing(); + /* BackToFront(); + */ - if (LevelSolved) - GameWon(); + if (PlayerGone) + RemoveHero(); return(moved); } -void TestIfHeroHitsBadThing() +void ScrollFigure(int init) { - int i, killx = JX,killy = JY; - static int xy[4][2] = - { - 0,-1, - -1,0, - +1,0, - 0,+1 - }; - static int harmless[4] = - { - MV_UP, - MV_LEFT, - MV_RIGHT, - MV_DOWN - }; + static long actual_frame_counter; + static int oldX = -1, oldY = -1; - for(i=0;i<4;i++) + if (init) { - int x,y,element; + if (PlayerMovPos && oldX != -1 && oldY != -1) + { + if (Feld[JX2][JY2] == EL_LEERRAUM) + Feld[JX2][JY2] = EL_UNSICHTBAR; + DrawLevelElement(oldX,oldY, Feld[oldX][oldY]); + DrawPlayerField(); + } - x = JX+xy[i][0]; - y = JY+xy[i][1]; - if (!IN_LEV_FIELD(x,y)) - continue; + oldX = JX2; + oldY = JY2; + actual_frame_counter = FrameCounter; - element = Feld[x][y]; + /* + redraw[redraw_x1 + oldX][redraw_y1 + oldY] = 1; + redraw_tiles++; + */ + + /* + DrawLevelElement(oldX,oldY, Feld[oldX][oldY]); + */ + + DrawPlayerField(); + + return; + } + else if (!FrameReached(&actual_frame_counter,1)) + return; + + PlayerMovPos += (PlayerMovPos > 0 ? -1 : 1) * TILEX/4; + + if (ScreenMovPos) + { + ScreenMovPos = PlayerMovPos; + redraw_mask |= REDRAW_FIELD; + } + + if (Feld[oldX][oldY] == EL_UNSICHTBAR) + Feld[oldX][oldY] = EL_LEERRAUM; + + DrawLevelElement(oldX,oldY, Feld[oldX][oldY]); + DrawPlayerField(); + + if (!PlayerMovPos) + { + JX2 = JX; + JY2 = JY; + } +} + +void TestIfGoodThingHitsBadThing(int goodx, int goody) +{ + int i, killx = goodx, killy = goody; + static int xy[4][2] = + { + { 0,-1 }, + { -1,0 }, + { +1,0 }, + { 0,+1 } + }; + static int harmless[4] = + { + MV_UP, + MV_LEFT, + MV_RIGHT, + MV_DOWN + }; + + for(i=0;i<4;i++) + { + int x,y,element; + + x = goodx+xy[i][0]; + y = goody+xy[i][1]; + if (!IN_LEV_FIELD(x,y)) + continue; + + element = Feld[x][y]; if (DONT_TOUCH(element)) { @@ -2263,13 +3073,78 @@ void TestIfHeroHitsBadThing() } } - if (killx!=JX || killy!=JY) - KillHero(); + if (killx!=goodx || killy!=goody) + { + if (IS_PLAYER(goodx,goody)) + KillHero(); + else + Bang(goodx,goody); + } +} + +void TestIfBadThingHitsGoodThing(int badx, int bady) +{ + int i, killx = badx, killy = bady; + static int xy[4][2] = + { + { 0,-1 }, + { -1,0 }, + { +1,0 }, + { 0,+1 } + }; + static int harmless[4] = + { + MV_UP, + MV_LEFT, + MV_RIGHT, + MV_DOWN + }; + + for(i=0;i<4;i++) + { + int x,y,element; + + x = badx+xy[i][0]; + y = bady+xy[i][1]; + if (!IN_LEV_FIELD(x,y)) + continue; + + element = Feld[x][y]; + + if (element==EL_PINGUIN) + { + if (MovDir[x][y]==harmless[i] && IS_MOVING(x,y)) + continue; + + killx = x; + killy = y; + break; + } + } + + if (killx!=badx || killy!=bady) + Bang(killx,killy); +} + +void TestIfHeroHitsBadThing() +{ + TestIfGoodThingHitsBadThing(JX,JY); } void TestIfBadThingHitsHero() { - TestIfHeroHitsBadThing(); + TestIfGoodThingHitsBadThing(JX,JY); + /* (no typo!) */ +} + +void TestIfFriendHitsBadThing(int x, int y) +{ + TestIfGoodThingHitsBadThing(x,y); +} + +void TestIfBadThingHitsFriend(int x, int y) +{ + TestIfBadThingHitsGoodThing(x,y); } void TestIfBadThingHitsOtherBadThing(int badx, int bady) @@ -2277,10 +3152,10 @@ void TestIfBadThingHitsOtherBadThing(int badx, int bady) int i, killx=badx, killy=bady; static int xy[4][2] = { - 0,-1, - -1,0, - +1,0, - 0,+1 + { 0,-1 }, + { -1,0 }, + { +1,0 }, + { 0,+1 } }; for(i=0;i<4;i++) @@ -2308,27 +3183,47 @@ void TestIfBadThingHitsOtherBadThing(int badx, int bady) void KillHero() { - if (PLAYER(-1,-1)) + if (PlayerGone) return; if (IS_PFORTE(Feld[JX][JY])) Feld[JX][JY] = EL_LEERRAUM; + Bang(JX,JY); + BuryHero(); +} + +void BuryHero() +{ + if (PlayerGone) + return; + PlaySoundLevel(JX,JY,SND_AUTSCH); PlaySoundLevel(JX,JY,SND_LACHEN); - Bang(JX,JY); + GameOver = TRUE; + RemoveHero(); +} + +void RemoveHero() +{ + PlayerGone = TRUE; + + ExitX = ZX = JX; + ExitY = ZY = JY; JX = JY = -1; } -int DigField(int x, int y, int mode) +int DigField(int x, int y, int real_dx, int real_dy, int mode) { int dx = x-JX, dy = y-JY; int element; static long push_delay = 0; - static int push_delay_value = 20; + static int push_delay_value = 5; - if (mode==DF_NO_PUSH) + PlayerPushing = FALSE; + + if (mode == DF_NO_PUSH) { push_delay = 0; return(MF_NO_ACTION); @@ -2342,56 +3237,66 @@ int DigField(int x, int y, int mode) switch(element) { case EL_LEERRAUM: - CheckMoving = TRUE; break; + case EL_ERDREICH: Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; break; + case EL_EDELSTEIN: - case EL_EDELSTEIN2: - case EL_EDELSTEIN3: + case EL_EDELSTEIN_BD: + case EL_EDELSTEIN_GELB: + case EL_EDELSTEIN_ROT: + case EL_EDELSTEIN_LILA: Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; + MovDelay[x][y] = 0; /* wegen EDELSTEIN_BD-Funkeln! */ if (Gems>0) Gems--; - RaiseScore(level.score[SC_EDELSTEIN]); + RaiseScoreElement(EL_EDELSTEIN); DrawText(DX_EMERALDS,DY_EMERALDS,int2str(Gems,3),FS_SMALL,FC_YELLOW); PlaySoundLevel(x,y,SND_PONG); break; + case EL_DIAMANT: Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; Gems -= 3; if (Gems<0) Gems=0; - RaiseScore(level.score[SC_DIAMANT]); + RaiseScoreElement(EL_DIAMANT); DrawText(DX_EMERALDS,DY_EMERALDS,int2str(Gems,3),FS_SMALL,FC_YELLOW); PlaySoundLevel(x,y,SND_PONG); break; + case EL_DYNAMIT_AUS: Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; Dynamite++; - RaiseScore(level.score[SC_DYNAMIT]); + RaiseScoreElement(EL_DYNAMIT); DrawText(DX_DYNAMITE,DY_DYNAMITE,int2str(Dynamite,3),FS_SMALL,FC_YELLOW); PlaySoundLevel(x,y,SND_PONG); break; + case EL_DYNABOMB_NR: Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; DynaBombCount++; DynaBombsLeft++; - RaiseScore(level.score[SC_DYNAMIT]); + RaiseScoreElement(EL_DYNAMIT); PlaySoundLevel(x,y,SND_PONG); break; case EL_DYNABOMB_SZ: + Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; DynaBombSize++; - RaiseScore(level.score[SC_DYNAMIT]); + RaiseScoreElement(EL_DYNAMIT); PlaySoundLevel(x,y,SND_PONG); break; + + case EL_DYNABOMB_XL: + Feld[x][y] = EL_LEERRAUM; + DynaBombXL = TRUE; + RaiseScoreElement(EL_DYNAMIT); + PlaySoundLevel(x,y,SND_PONG); + break; + case EL_SCHLUESSEL1: case EL_SCHLUESSEL2: case EL_SCHLUESSEL3: @@ -2400,9 +3305,8 @@ int DigField(int x, int y, int mode) int key_nr = element-EL_SCHLUESSEL1; Feld[x][y] = EL_LEERRAUM; - CheckMoving = TRUE; Key[key_nr] = TRUE; - RaiseScore(level.score[SC_SCHLUESSEL]); + RaiseScoreElement(EL_SCHLUESSEL); DrawMiniGraphicExtHiRes(drawto,gc, DX_KEYS+key_nr*MINI_TILEX,DY_KEYS, GFX_SCHLUESSEL1+key_nr); @@ -2412,32 +3316,43 @@ int DigField(int x, int y, int mode) PlaySoundLevel(x,y,SND_PONG); break; } + case EL_ABLENK_AUS: Feld[x][y] = EL_ABLENK_EIN; - CheckExploding = TRUE; - ZX=x; - ZY=y; + ZX = x; + ZY = y; DrawLevelField(x,y); return(MF_ACTION); break; + case EL_FELSBROCKEN: case EL_BOMBE: case EL_KOKOSNUSS: case EL_ZEIT_LEER: - if (mode==DF_SNAP) + if (dy || mode==DF_SNAP) return(MF_NO_ACTION); - if (dy || !IN_LEV_FIELD(x+dx,y+dy) || Feld[x+dx][y+dy]!=EL_LEERRAUM) + + PlayerPushing = TRUE; + + if (!IN_LEV_FIELD(x+dx,y+dy) || Feld[x+dx][y+dy] != EL_LEERRAUM) return(MF_NO_ACTION); - if (Counter() > push_delay+4*push_delay_value) - push_delay = Counter(); - if (!DelayReached(&push_delay,push_delay_value) && !tape.playing) + if (real_dy) + { + if (IN_LEV_FIELD(JX,JY+real_dy) && !IS_SOLID(Feld[JX][JY+real_dy])) + return(MF_NO_ACTION); + } + + if (push_delay == 0) + push_delay = FrameCounter; + if (!FrameReached(&push_delay,push_delay_value) && !tape.playing) return(MF_NO_ACTION); Feld[x][y] = EL_LEERRAUM; Feld[x+dx][y+dy] = element; - push_delay_value = 10+RND(30); - CheckMoving = TRUE; + + push_delay_value = 2+RND(8); + DrawLevelField(x+dx,y+dy); if (element==EL_FELSBROCKEN) PlaySoundLevel(x+dx,y+dy,SND_PUSCH); @@ -2446,6 +3361,7 @@ int DigField(int x, int y, int mode) else PlaySoundLevel(x+dx,y+dy,SND_KLOPF); break; + case EL_PFORTE1: case EL_PFORTE2: case EL_PFORTE3: @@ -2453,6 +3369,7 @@ int DigField(int x, int y, int mode) if (!Key[element-EL_PFORTE1]) return(MF_NO_ACTION); break; + case EL_PFORTE1X: case EL_PFORTE2X: case EL_PFORTE3X: @@ -2460,38 +3377,129 @@ int DigField(int x, int y, int mode) if (!Key[element-EL_PFORTE1X]) return(MF_NO_ACTION); break; + case EL_AUSGANG_ZU: case EL_AUSGANG_ACT: /* Tür ist (noch) nicht offen! */ return(MF_NO_ACTION); break; + case EL_AUSGANG_AUF: -/* - if (mode==DF_SNAP || Gems>0) - return(MF_NO_ACTION); -*/ if (mode==DF_SNAP) return(MF_NO_ACTION); - LevelSolved = GameOver = TRUE; + + PlayerGone = TRUE; PlaySoundLevel(x,y,SND_BUING); + + if (!Friends) + LevelSolved = GameOver = TRUE; + break; + case EL_BIRNE_AUS: Feld[x][y] = EL_BIRNE_EIN; + Lights--; DrawLevelField(x,y); PlaySoundLevel(x,y,SND_DENG); return(MF_ACTION); break; + case EL_ZEIT_VOLL: Feld[x][y] = EL_ZEIT_LEER; + TimeLeft += 10; + DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW); DrawLevelField(x,y); PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT); return(MF_ACTION); break; + + case EL_SOKOBAN_FELD_LEER: + break; + + case EL_SOKOBAN_FELD_VOLL: + case EL_SOKOBAN_OBJEKT: + case EL_SONDE: + if (mode==DF_SNAP) + return(MF_NO_ACTION); + + PlayerPushing = TRUE; + + if (!IN_LEV_FIELD(x+dx,y+dy) + || (Feld[x+dx][y+dy] != EL_LEERRAUM + && (Feld[x+dx][y+dy] != EL_SOKOBAN_FELD_LEER + || !IS_SB_ELEMENT(element)))) + 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 (push_delay == 0) + push_delay = FrameCounter; + if (!FrameReached(&push_delay,push_delay_value) && !tape.playing) + return(MF_NO_ACTION); + + if (IS_SB_ELEMENT(element)) + { + if (element == EL_SOKOBAN_FELD_VOLL) + { + Feld[x][y] = EL_SOKOBAN_FELD_LEER; + SokobanFields++; + } + else + Feld[x][y] = EL_LEERRAUM; + + if (Feld[x+dx][y+dy] == EL_SOKOBAN_FELD_LEER) + { + Feld[x+dx][y+dy] = EL_SOKOBAN_FELD_VOLL; + SokobanFields--; + if (element == EL_SOKOBAN_OBJEKT) + PlaySoundLevel(x,y,SND_DENG); + } + else + Feld[x+dx][y+dy] = EL_SOKOBAN_OBJEKT; + } + else + { + Feld[x][y] = EL_LEERRAUM; + Feld[x+dx][y+dy] = element; + } + + push_delay_value = 2; + + DrawLevelField(x,y); + DrawLevelField(x+dx,y+dy); + PlaySoundLevel(x+dx,y+dy,SND_PUSCH); + + if (IS_SB_ELEMENT(element) && + SokobanFields == 0 && game_emulation == EMU_SOKOBAN) + { + LevelSolved = GameOver = TRUE; + PlaySoundLevel(x,y,SND_BUING); + } + + break; + + case EL_MAULWURF: + case EL_PINGUIN: + case EL_SCHWEIN: + case EL_DRACHE: + break; + default: return(MF_NO_ACTION); break; } - push_delay=0; + + push_delay = 0; + return(MF_MOVING); } @@ -2500,7 +3508,7 @@ BOOL SnapField(int dx, int dy) int x = JX+dx, y = JY+dy; static int snapped = FALSE; - if (GameOver || !IN_LEV_FIELD(x,y)) + if (PlayerGone || !IN_LEV_FIELD(x,y)) return(FALSE); if (dx && dy) return(FALSE); @@ -2512,7 +3520,12 @@ BOOL SnapField(int dx, int dy) if (snapped) return(FALSE); - if (!DigField(x,y,DF_SNAP)) + PlayerMovDir = (dx < 0 ? MV_LEFT : + dx > 0 ? MV_RIGHT : + dy < 0 ? MV_UP : + dy > 0 ? MV_DOWN : MV_NO_MOVING); + + if (!DigField(x,y, 0,0, DF_SNAP)) return(FALSE); snapped = TRUE; @@ -2524,12 +3537,19 @@ BOOL SnapField(int dx, int dy) BOOL PlaceBomb(void) { + int element; + + if (PlayerGone) + return(FALSE); + + element = Feld[JX][JY]; + if ((Dynamite==0 && DynaBombsLeft==0) || - Feld[JX][JY]==EL_DYNAMIT || Feld[JX][JY]==EL_DYNABOMB) + element==EL_DYNAMIT || element==EL_DYNABOMB || element==EL_EXPLODING) return(FALSE); - if (Feld[JX][JY]!=EL_LEERRAUM) - Store[JX][JY] = Feld[JX][JY]; + if (element != EL_LEERRAUM) + Store[JX][JY] = element; if (Dynamite) { @@ -2544,13 +3564,9 @@ BOOL PlaceBomb(void) Feld[JX][JY] = EL_DYNABOMB; MovDelay[JX][JY] = 48; DynaBombsLeft--; - - /* ändern, wenn Maske für DYNABOMB vorliegt! */ - - DrawGraphicThruMask(SCROLLX(JX),SCROLLY(JY),GFX_DYNAMIT); + DrawGraphicThruMask(SCROLLX(JX),SCROLLY(JY),GFX_DYNABOMB); } - CheckExploding = TRUE; return(TRUE); } @@ -2558,11 +3574,15 @@ void PlaySoundLevel(int x, int y, int sound_nr) { int sx = SCROLLX(x), sy = SCROLLY(y); int volume, stereo; + int silence_distance = 8; - if (!sound_loops_on && IS_LOOP_SOUND(sound_nr)) + if ((!sound_simple_on && !IS_LOOP_SOUND(sound_nr)) || + (!sound_loops_on && IS_LOOP_SOUND(sound_nr))) return; - if (!IN_LEV_FIELD(x,y)) + if (!IN_LEV_FIELD(x,y) || + sx < -silence_distance || sx >= SCR_FIELDX+silence_distance || + sy < -silence_distance || sy >= SCR_FIELDY+silence_distance) return; volume = PSND_MAX_VOLUME; @@ -2570,10 +3590,10 @@ void PlaySoundLevel(int x, int y, int sound_nr) if (!IN_SCR_FIELD(sx,sy)) { - if (sx<0 || sx>=SCR_FIELDX) - volume = PSND_MAX_VOLUME - 2*ABS(sx-SCR_FIELDX/2); - else - volume = PSND_MAX_VOLUME - 2*ABS(sy-SCR_FIELDY/2); + int dx = ABS(sx-SCR_FIELDX/2)-SCR_FIELDX/2; + int dy = ABS(sy-SCR_FIELDY/2)-SCR_FIELDY/2; + + volume -= volume*(dx > dy ? dx : dy)/silence_distance; } PlaySoundExt(sound_nr, volume, stereo, PSND_NO_LOOP); @@ -2583,199 +3603,46 @@ void RaiseScore(int value) { Score += value; DrawText(DX_SCORE,DY_SCORE,int2str(Score,5),FS_SMALL,FC_YELLOW); - BackToFront(); -} - -void TapeInitRecording() -{ - time_t zeit1 = time(NULL); - struct tm *zeit2 = localtime(&zeit1); - - if (tape.recording || tape.playing) - return; - - tape.level_nr = level_nr; - tape.recording = TRUE; - tape.pausing = TRUE; - tape.date = - 10000*(zeit2->tm_year%100) + 100*zeit2->tm_mon + zeit2->tm_mday; - - DrawVideoDisplay(VIDEO_STATE_REC_ON | VIDEO_STATE_PAUSE_ON,0); - DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date); - DrawVideoDisplay(VIDEO_STATE_TIME_ON,0); -} - -void TapeStartRecording() -{ - tape.length = 0; - tape.counter = 0; - tape.pos[tape.counter].delay = 0; - tape.recording = TRUE; - tape.playing = FALSE; - tape.pausing = FALSE; - tape.random_seed = InitRND(NEW_RANDOMIZE); - DrawVideoDisplay(VIDEO_STATE_REC_ON | VIDEO_STATE_PAUSE_OFF,0); -} - -void TapeStopRecording() -{ - if (!tape.recording) - return; - - tape.length = tape.counter; - tape.recording = FALSE; - tape.pausing = FALSE; - DrawVideoDisplay(VIDEO_STATE_REC_OFF,0); - - master_tape = tape; -} - -void TapeRecordAction(int joy) -{ - if (!tape.recording || tape.pausing) - return; - - if (tape.counter>=MAX_TAPELEN-1) - { - TapeStopRecording(); - return; - } - - if (joy) - { - tape.pos[tape.counter].joystickdata = joy; - tape.counter++; - tape.pos[tape.counter].delay = 0; - } -} - -void TapeRecordDelay() -{ - if (!tape.recording || tape.pausing) - return; - - if (tape.counter>=MAX_TAPELEN) - { - TapeStopRecording(); - return; - } - - tape.pos[tape.counter].delay++; - - if (tape.pos[tape.counter].delay>=255) - { - tape.pos[tape.counter].joystickdata = 0; - tape.counter++; - tape.pos[tape.counter].delay = 0; - } -} - -void TapeTogglePause() -{ - if (!tape.recording && !tape.playing) - return; - - if (tape.pausing) - { - tape.pausing = FALSE; - DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0); - if (game_status==MAINMENU) - HandleMainMenu(SX+16,SY+7*32+16,0,0,MB_MENU_CHOICE); - } - else - { - tape.pausing = TRUE; - DrawVideoDisplay(VIDEO_STATE_PAUSE_ON,0); - } -} - -void TapeInitPlaying() -{ - if (tape.recording || tape.playing || TAPE_IS_EMPTY(tape)) - return; - - tape.playing = TRUE; - tape.pausing = TRUE; - DrawVideoDisplay(VIDEO_STATE_PLAY_ON | VIDEO_STATE_PAUSE_ON,0); - DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date); - DrawVideoDisplay(VIDEO_STATE_TIME_ON,0); } -void TapeStartPlaying() +void RaiseScoreElement(int element) { - tape = master_tape; - - tape.counter = 0; - tape.recording = FALSE; - tape.playing = TRUE; - tape.pausing = FALSE; - InitRND(tape.random_seed); - DrawVideoDisplay(VIDEO_STATE_PLAY_ON | VIDEO_STATE_PAUSE_OFF,0); -} - -void TapeStopPlaying() -{ - if (!tape.playing) - return; - - tape.playing = FALSE; - tape.pausing = FALSE; - DrawVideoDisplay(VIDEO_STATE_PLAY_OFF,0); -} - -int TapePlayAction() -{ - if (!tape.playing || tape.pausing) - return(0); - - if (tape.counter>=tape.length) - { - TapeStopPlaying(); - return(0); - } - - if (!tape.pos[tape.counter].delay) - { - tape.counter++; - return(tape.pos[tape.counter-1].joystickdata); - } - else - return(0); -} - -BOOL TapePlayDelay() -{ - if (!tape.playing || tape.pausing) - return(0); - - if (tape.counter>=tape.length) - { - TapeStopPlaying(); - return(TRUE); - } - - if (tape.pos[tape.counter].delay) - { - tape.pos[tape.counter].delay--; - return(TRUE); - } - else - return(FALSE); -} - -void TapeStop() -{ - TapeStopRecording(); - TapeStopPlaying(); - DrawVideoDisplay(VIDEO_ALL_OFF,0); - if (tape.date && tape.length) + switch(element) { - DrawVideoDisplay(VIDEO_STATE_DATE_ON,tape.date); - DrawVideoDisplay(VIDEO_STATE_TIME_ON,0); + case EL_EDELSTEIN: + RaiseScore(level.score[SC_EDELSTEIN]); + break; + case EL_DIAMANT: + RaiseScore(level.score[SC_DIAMANT]); + break; + case EL_KAEFER: + case EL_BUTTERFLY: + RaiseScore(level.score[SC_KAEFER]); + break; + case EL_FLIEGER: + case EL_FIREFLY: + RaiseScore(level.score[SC_FLIEGER]); + break; + case EL_MAMPFER: + case EL_MAMPFER2: + RaiseScore(level.score[SC_MAMPFER]); + break; + case EL_ROBOT: + RaiseScore(level.score[SC_ROBOT]); + break; + case EL_PACMAN: + RaiseScore(level.score[SC_PACMAN]); + break; + case EL_KOKOSNUSS: + RaiseScore(level.score[SC_KOKOSNUSS]); + break; + case EL_DYNAMIT: + RaiseScore(level.score[SC_DYNAMIT]); + break; + case EL_SCHLUESSEL: + RaiseScore(level.score[SC_SCHLUESSEL]); + break; + default: + break; } } - -void TapeErase() -{ - tape.length = 0; -}