X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame.c;h=384d7431d4b14e611113d302da44945d288b0089;hp=802c9f5b7874dd4ae8c5641b9e4468c750f335f6;hb=c4baa69cc8d5e8398425e67498b49f4b77f8e477;hpb=4b0f1eb4220d2dbe4cffb288f745661b32c96a5b diff --git a/src/game.c b/src/game.c index 802c9f5b..384d7431 100644 --- a/src/game.c +++ b/src/game.c @@ -23,16 +23,6 @@ #include "tape.h" #include "joystick.h" - - -int tst = 0; -int tst2 = 0; - - - -extern int GameSpeed; -extern int MoveSpeed; - void GetPlayerConfig() { int old_joystick_nr = joystick_nr; @@ -385,7 +375,7 @@ void GameWon() TimeLeft--; DrawText(DX_TIME,DY_TIME,int2str(TimeLeft,3),FS_SMALL,FC_YELLOW); BackToFront(); - Delay(10000); + Delay(10); } if (sound_loops_on) @@ -498,7 +488,7 @@ void InitMovingField(int x, int y, int direction) MovDir[x][y] = direction; MovDir[newx][newy] = direction; - if (Feld[newx][newy]==EL_LEERRAUM) + if (Feld[newx][newy] == EL_LEERRAUM) Feld[newx][newy] = EL_BLOCKED; } @@ -875,7 +865,7 @@ void Blurb(int x, int y) if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ { MovDelay[x][y]--; - if (MovDelay[x][y] && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) + if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) DrawGraphic(SCROLLX(x),SCROLLY(y),graphic+4-MovDelay[x][y]/2); if (!MovDelay[x][y]) @@ -1791,7 +1781,13 @@ void StartMoving(int x, int y) else if (element == EL_BUTTERFLY || element == EL_FIREFLY) DrawGraphicAnimation(x,y, el2gfx(element), 2, 4, ANIM_NORMAL); else if (element==EL_SONDE) - DrawGraphicAnimation(x,y, GFX_SONDE_START, 8, 2, ANIM_NORMAL); + { + int nextJX = JX + (JX - lastJX); + int nextJY = JY + (JY - lastJY); + + if (!(PlayerPushing && PlayerGfxPos && x == nextJX && y == nextJY)) + DrawGraphicAnimation(x,y, GFX_SONDE_START, 8, 2, ANIM_NORMAL); + } return; } @@ -2045,7 +2041,7 @@ void AmoebeWaechst(int x, int y) { MovDelay[x][y] = 7; - if (DelayReached(&sound_delay,sound_delay_value)) + if (DelayReached(&sound_delay, sound_delay_value)) { PlaySoundLevel(x,y,SND_AMOEBE); sound_delay_value = 30; @@ -2055,7 +2051,7 @@ void AmoebeWaechst(int x, int y) if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ { MovDelay[x][y]--; - if (MovDelay[x][y] && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) + if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_AMOEBING+3-MovDelay[x][y]/2); if (!MovDelay[x][y]) @@ -2316,7 +2312,10 @@ void Birne(int x, int y) void Blubber(int x, int y) { - DrawGraphicAnimation(x,y, GFX_GEBLUBBER, 4, 10, ANIM_NORMAL); + if (y > 0 && IS_MOVING(x,y-1) && MovDir[x][y-1] == MV_DOWN) + DrawLevelField(x,y-1); + else + DrawGraphicAnimation(x,y, GFX_GEBLUBBER, 4, 10, ANIM_NORMAL); } void NussKnacken(int x, int y) @@ -2327,7 +2326,7 @@ void NussKnacken(int x, int y) if (MovDelay[x][y]) /* neue Phase / in Wartezustand */ { MovDelay[x][y]--; - if (MovDelay[x][y] && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) + if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_CRACKINGNUT+3-MovDelay[x][y]/2); if (!MovDelay[x][y]) @@ -2340,9 +2339,9 @@ void NussKnacken(int x, int y) void SiebAktivieren(int x, int y, int typ) { - if (SiebAktiv%2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) + if (!(SiebAktiv % 4) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y))) DrawGraphic(SCROLLX(x),SCROLLY(y), - (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%8)/2); + (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%16)/4); } void AusgangstuerPruefen(int x, int y) @@ -2413,14 +2412,25 @@ void EdelsteinFunkeln(int x, int y) int src_x,src_y, dest_x,dest_y; int phase = (MovDelay[x][y]-1)/2; - 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; + if (phase > 2) + phase = 4-phase; + + src_x = SX + GFX_PER_LINE*TILEX; + src_y = SY + phase*TILEY; + dest_x = FX + SCROLLX(x)*TILEX; + dest_y = FY + SCROLLY(y)*TILEY; + /* 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); + */ + + XSetClipMask(display, tile_clip_gc, + tile_clipmask[GFX_MASK_SPARKLING + phase]); + XSetClipOrigin(display, tile_clip_gc, dest_x,dest_y); + XCopyArea(display, pix[PIX_BACK], drawto_field, tile_clip_gc, + src_x,src_y, TILEX,TILEY, dest_x,dest_y); if (direct_draw_on) { @@ -2570,247 +2580,154 @@ void GameActions() { static long action_delay = 0; long action_delay_value; + int sieb_x = 0, sieb_y = 0; + int x, y, element; if (game_status != PLAYING) return; -/* - action_delay_value = - (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY); -*/ - +#ifdef DEBUG action_delay_value = (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameSpeed); - - /* - if (DelayReached(&action_delay, action_delay_value)) - */ - - +#else + action_delay_value = + (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY); +#endif if (PlayerMovPos) ScrollFigure(0); - DrawPlayerField(); - - - - - tst++; - - if (0) - { - static long last_Counter = 0; - long new_Counter = Counter(); - - printf("--> %ld / %ld [%d]\n", - new_Counter - last_Counter, - new_Counter, - FrameCounter); - last_Counter = new_Counter; - } - + /* main game synchronization point */ + WaitUntilDelayReached(&action_delay, action_delay_value); - - - /* - if (!DelayReached(&action_delay, action_delay_value)) + if (tape.pausing || (tape.playing && !TapePlayDelay())) return; - */ - - - while(!DelayReached(&action_delay, action_delay_value)) - Delay(1000); - - - - - /* - printf("-----------\n"); - */ - - + else if (tape.recording) + TapeRecordDelay(); FrameCounter++; + TimeFrames++; - - - /* - if (PlayerMovPos) - ScrollFigure(0); - - DrawPlayerField(); - */ - - - tst2 = tst; - tst = 0; - - - - if (0) - { - static long last_Counter = 0; - long new_Counter = Counter(); - - printf("--> %ld / %ld [%d]\n", - new_Counter - last_Counter, - new_Counter, - FrameCounter); - last_Counter = new_Counter; - } - - - /* - printf("--> %ld / ", Counter()); - */ - - + for(y=0;y0) + JustHit[x][y]--; - - /* - FrameCounter++; - */ - - - TimeFrames++; - - for(y=0;y0) - JustHit[x][y]--; + int oldx,oldy; -#if DEBUG - if (IS_BLOCKED(x,y)) + Blocked2Moving(x,y,&oldx,&oldy); + if (!IS_MOVING(oldx,oldy)) { - 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"); - } + 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>=(100/GameSpeed) && !tape.pausing) + if (TimeLeft>0 && TimeFrames>=(1000/GameSpeed) && !tape.pausing) { TimeFrames = 0; TimeLeft--; @@ -2828,8 +2745,6 @@ void GameActions() } DrawPlayerField(); - - BackToFront(); } void ScrollLevel(int dx, int dy) @@ -2985,79 +2900,23 @@ BOOL MoveFigure(int dx, int dy) void ScrollFigure(int init) { static long actual_frame_counter = 0; - static int oldJX = -1, oldJY = -1; if (init) { - - - PlayerGfxPos = ScrollStepSize * (PlayerMovPos / ScrollStepSize); - - + actual_frame_counter = FrameCounter; /* - ScreenMovPos = PlayerGfxPos; - redraw_mask |= REDRAW_FIELD; - */ - - - - if (0) - { - static long last_Counter = 0; - long new_Counter = Counter(); - - printf("--> %ld / %ld [%d, %d]\n", - new_Counter - last_Counter, - new_Counter, - FrameCounter, - tst2); - last_Counter = new_Counter; - } - - - - - if (oldJX != -1 && oldJY != -1) - DrawLevelElement(oldJX,oldJY, Feld[oldJX][oldJY]); - if (Feld[lastJX][lastJY] == EL_LEERRAUM && IN_LEV_FIELD(lastJX,lastJY-1) && CAN_FALL(Feld[lastJX][lastJY-1])) Feld[lastJX][lastJY] = EL_PLAYER_IS_LEAVING; - DrawLevelElement(lastJX,lastJY, Feld[lastJX][lastJY]); - DrawPlayerField(); + */ - oldJX = lastJX; - oldJY = lastJY; - actual_frame_counter = FrameCounter; - - if (PlayerPushing) - { - int nextJX = JX + (JX - lastJX); - int nextJY = JY + (JY - lastJY); - - if (Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL) - DrawLevelElement(nextJX,nextJY, EL_SOKOBAN_FELD_LEER); - else - DrawLevelElement(nextJX,nextJY, EL_LEERRAUM); - } + if (Feld[lastJX][lastJY] == EL_LEERRAUM) + Feld[lastJX][lastJY] = EL_PLAYER_IS_LEAVING; DrawPlayerField(); - - if (Store[lastJX][lastJY]) - { - DrawGraphic(SCROLLX(lastJX),SCROLLY(lastJY), - el2gfx(Store[lastJX][lastJY])); - DrawGraphicThruMask(SCROLLX(lastJX),SCROLLY(lastJY), - el2gfx(Feld[lastJX][lastJY])); - } - else if (Feld[lastJX][lastJY]==EL_DYNAMIT) - DrawDynamite(lastJX,lastJY); - else - DrawLevelField(lastJX,lastJY); - return; } else if (!FrameReached(&actual_frame_counter,1)) @@ -3066,59 +2925,21 @@ void ScrollFigure(int init) PlayerMovPos += (PlayerMovPos > 0 ? -1 : 1) * TILEX/8; PlayerGfxPos = ScrollStepSize * (PlayerMovPos / ScrollStepSize); - - /* - printf("PlayerGfxPos = %d\n", PlayerGfxPos); - */ - - if (ScreenMovPos && ScreenMovPos != PlayerGfxPos) { ScreenMovPos = PlayerGfxPos; redraw_mask |= REDRAW_FIELD; } - if (Feld[oldJX][oldJY] == EL_PLAYER_IS_LEAVING) - Feld[oldJX][oldJY] = EL_LEERRAUM; + if (Feld[lastJX][lastJY] == EL_PLAYER_IS_LEAVING) + Feld[lastJX][lastJY] = EL_LEERRAUM; - DrawLevelElement(oldJX,oldJY, Feld[oldJX][oldJY]); DrawPlayerField(); - - - if (Store[oldJX][oldJY]) - { - DrawGraphic(SCROLLX(oldJX),SCROLLY(oldJY),el2gfx(Store[oldJX][oldJY])); - DrawGraphicThruMask(SCROLLX(oldJX),SCROLLY(oldJY), - el2gfx(Feld[oldJX][oldJY])); - } - else if (Feld[oldJX][oldJY]==EL_DYNAMIT) - DrawDynamite(oldJX,oldJY); - else - DrawLevelField(oldJX,oldJY); - - if (PlayerPushing) - { - int nextJX = JX + (JX - lastJX); - int nextJY = JY + (JY - lastJY); - - if (PlayerGfxPos) - { - if (Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL) - DrawLevelElement(nextJX,nextJY, EL_SOKOBAN_FELD_LEER); - else - DrawLevelElement(nextJX,nextJY, EL_LEERRAUM); - } - else - DrawLevelElement(nextJX,nextJY, Feld[nextJX][nextJY]); - } - if (!PlayerMovPos) { lastJX = JX; lastJY = JY; - - oldJX = oldJY = -1; } } @@ -3397,12 +3218,12 @@ int DigField(int x, int y, int real_dx, int real_dy, int mode) Feld[x][y] = EL_LEERRAUM; Key[key_nr] = TRUE; RaiseScoreElement(EL_SCHLUESSEL); - DrawMiniGraphicExtHiRes(drawto,gc, - DX_KEYS+key_nr*MINI_TILEX,DY_KEYS, - GFX_SCHLUESSEL1+key_nr); - DrawMiniGraphicExtHiRes(window,gc, - DX_KEYS+key_nr*MINI_TILEX,DY_KEYS, - GFX_SCHLUESSEL1+key_nr); + DrawMiniGraphicExt(drawto,gc, + DX_KEYS+key_nr*MINI_TILEX,DY_KEYS, + GFX_SCHLUESSEL1+key_nr); + DrawMiniGraphicExt(window,gc, + DX_KEYS+key_nr*MINI_TILEX,DY_KEYS, + GFX_SCHLUESSEL1+key_nr); PlaySoundLevel(x,y,SND_PONG); break; }