X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fgame.c;h=8d88167b277ece9f7ddce9e0ebfcd0a030f523aa;hp=6d5ca5bc30f068ad08f84f09564a5fb1947a9dd8;hb=c3d03cdffce070695ba0520d00667b42b8460087;hpb=d0893e6987c21c25ec137438a18cfe1288362139 diff --git a/src/game.c b/src/game.c index 6d5ca5bc..8d88167b 100644 --- a/src/game.c +++ b/src/game.c @@ -10,8 +10,6 @@ * q99492@pbhrzx.uni-paderborn.de * *----------------------------------------------------------* * game.c * -* * -* Letzte Aenderung: 15.06.1995 * ***********************************************************/ #include "game.h" @@ -20,620 +18,8 @@ #include "screens.h" #include "sound.h" #include "init.h" - -BOOL CreateNewScoreFile() -{ - int i,j,k; - char filename[MAX_FILENAME]; - char empty_alias[MAX_NAMELEN]; - FILE *file; - - sprintf(filename,"%s/%s/%s", - SCORE_PATH,leveldir[leveldir_nr].filename,SCORE_FILENAME); - - if (!(file=fopen(filename,"w"))) - return(FALSE); - - for(i=0;i=MAX_TAPELEN) - break; - tape.pos[i].joystickdata = fgetc(file); - tape.pos[i].delay = fgetc(file); - if (feof(file)) - break; - } - - if (i != tape.length) - fprintf(stderr,"%s: level recording file '%s' corrupted!\n", - progname,filename); - - fclose(file); - - master_tape = tape; -} - -void LoadScore(int level_nr) -{ - int i,j; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; - FILE *file; - - sprintf(filename,"%s/%s/%s", - SCORE_PATH,leveldir[leveldir_nr].filename,SCORE_FILENAME); - - if (!(file=fopen(filename,"r"))) - { - if (!CreateNewScoreFile()) - { - fprintf(stderr,"%s: cannot create score file '%s'!\n", - progname,filename); - } - else if (!(file=fopen(filename,"r"))) - { - fprintf(stderr,"%s: cannot load score for level %d!\n", - progname,level_nr); - } - } - - if (file) - { - fgets(cookie,SCORE_COOKIE_LEN,file); - if (strcmp(cookie,SCORE_COOKIE)) /* ungültiges Format? */ - { - fprintf(stderr,"%s: wrong format of score file!\n",progname); - fclose(file); - file = NULL; - } - } - - if (file) - { - fseek(file, - SCORE_COOKIE_LEN-1+level_nr*(MAX_SCORE_ENTRIES*(MAX_NAMELEN+2)), - SEEK_SET); - for(i=0;i> 24) & 0xff,file); - fputc((tape.random_seed >> 16) & 0xff,file); - fputc((tape.random_seed >> 8) & 0xff,file); - fputc((tape.random_seed >> 0) & 0xff,file); - - fputc((tape.date >> 24) & 0xff,file); - fputc((tape.date >> 16) & 0xff,file); - fputc((tape.date >> 8) & 0xff,file); - fputc((tape.date >> 0) & 0xff,file); - - fputc((tape.length >> 24) & 0xff,file); - fputc((tape.length >> 16) & 0xff,file); - fputc((tape.length >> 8) & 0xff,file); - fputc((tape.length >> 0) & 0xff,file); - - for(i=0;i=0) SaveScore(level_nr); @@ -1123,6 +545,9 @@ void Explode(int ex, int ey, int phase) if (!IN_LEV_FIELD(x,y) || IS_MASSIV(element)) continue; + if (center_element==EL_AMOEBA2DIAM && (x!=ex || y!=ey)) + continue; + if (element==EL_EXPLODING) element = Store2[x][y]; @@ -1130,19 +555,25 @@ void Explode(int ex, int ey, int phase) Store[x][y] = ((x==ex && y==ey) ? EL_DIAMANT : EL_EDELSTEIN); else if (center_element==EL_MAMPFER) Store[x][y] = level.mampfer_inhalt[MampferNr][x-ex+1][y-ey+1]; - else if (Feld[x][y]==EL_ERZ_1) + else if (center_element==EL_AMOEBA2DIAM) + Store[x][y] = level.amoebe_inhalt; + else if (element==EL_ERZ_EDEL) Store[x][y] = EL_EDELSTEIN; - else if (Feld[x][y]==EL_ERZ_2) + else if (element==EL_ERZ_DIAM) Store[x][y] = EL_DIAMANT; else if (!IS_PFORTE(Store[x][y])) Store[x][y] = EL_LEERRAUM; - if (x!=ex || y!=ey) + if (x!=ex || y!=ey || center_element==EL_AMOEBA2DIAM) Store2[x][y] = element; + if (AmoebaNr[x][y] && (element==EL_AMOEBE_VOLL || element==EL_AMOEBING)) + AmoebaCnt[AmoebaNr[x][y]]--; + RemoveMovingField(x,y); Feld[x][y] = EL_EXPLODING; MovDir[x][y] = MovPos[x][y] = 0; + AmoebaNr[x][y] = 0; Frame[x][y] = 1; Stop[x][y] = TRUE; } @@ -1176,6 +607,8 @@ void Explode(int ex, int ey, int phase) Store2[x][y] = 0; Bang(x,y); } + else if (element==EL_AMOEBA2DIAM) + AmoebeUmwandeln(x,y); } if (phase==last_phase) @@ -1307,7 +740,10 @@ void Impact(int x, int y) if (object_hit && PLAYER(x,y+1)) KillHero(); else - Feld[x][y] = EL_AMOEBING2; + { + Feld[x][y] = EL_AMOEBING; + Store[x][y] = EL_AMOEBE_NASS; + } return; } @@ -1380,6 +816,10 @@ void Impact(int x, int y) case EL_SCHLUESSEL4: sound = SND_KINK; break; + case EL_ZEIT_VOLL: + case EL_ZEIT_LEER: + sound = SND_DENG; + break; default: sound = -1; break; @@ -1623,9 +1063,10 @@ void StartMoving(int x, int y) } else if (element==EL_TROPFEN) { - Feld[x][y] = EL_AMOEBING2; + Feld[x][y] = EL_AMOEBING; + Store[x][y] = EL_AMOEBE_NASS; } - else if (SLIPPERY(Feld[x][y+1]) && !Store[x][y+1]) + 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)); @@ -1701,12 +1142,20 @@ void StartMoving(int x, int y) else if (element==EL_MAMPFER && IN_LEV_FIELD(newx,newy) && Feld[newx][newy]==EL_DIAMANT) { - Feld[newx][newy] = EL_LEERRAUM; - DrawLevelField(newx,newy); + if (IS_MOVING(newx,newy)) + RemoveMovingField(newx,newy); + else + { + Feld[newx][newy] = EL_LEERRAUM; + DrawLevelField(newx,newy); + } } else if (element==EL_PACMAN && IN_LEV_FIELD(newx,newy) && IS_AMOEBOID(Feld[newx][newy])) { + if (AmoebaNr[newx][newy] && Feld[newx][newy]==EL_AMOEBE_VOLL) + AmoebaCnt[AmoebaNr[newx][newy]]--; + Feld[newx][newy] = EL_LEERRAUM; DrawLevelField(newx,newy); } @@ -1782,10 +1231,10 @@ void ContinueMoving(int x, int y) Feld[newx][newy] = EL_SALZSAEURE; element = EL_SALZSAEURE; } - else if (Store[x][y]==EL_AMOEBE2) + else if (Store[x][y]==EL_AMOEBE_NASS) { Store[x][y] = 0; - Feld[x][y] = EL_AMOEBE2; + Feld[x][y] = EL_AMOEBE_NASS; } MovPos[x][y] = MovDir[x][y] = 0; @@ -1816,6 +1265,112 @@ void ContinueMoving(int x, int y) } } +int AmoebeNachbarNr(int ax, int ay) +{ + int i; + int element = Feld[ax][ay]; + int group_nr = 0; + static int xy[4][2] = + { + 0,-1, + -1,0, + +1,0, + 0,+1 + }; + + for(i=0;i<4;i++) + { + int x = ax+xy[i%4][0]; + int y = ay+xy[i%4][1]; + + if (!IN_LEV_FIELD(x,y)) + continue; + + if (Feld[x][y]==element && AmoebaNr[x][y]>0) + group_nr = AmoebaNr[x][y]; + } + + return(group_nr); +} + +void AmoebenVereinigen(int ax, int ay) +{ + int i,x,y,xx,yy; + int new_group_nr = AmoebaNr[ax][ay]; + static int xy[4][2] = + { + 0,-1, + -1,0, + +1,0, + 0,+1 + }; + + if (!new_group_nr) + return; + + for(i=0;i<4;i++) + { + x = ax+xy[i%4][0]; + y = ay+xy[i%4][1]; + + if (!IN_LEV_FIELD(x,y)) + continue; + + if ((Feld[x][y]==EL_AMOEBE_VOLL || Feld[x][y]==EL_AMOEBE_TOT) && + AmoebaNr[x][y] != new_group_nr) + { + int old_group_nr = AmoebaNr[x][y]; + + AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr]; + AmoebaCnt[old_group_nr] = 0; + + for(yy=0;yy0) return(MF_NO_ACTION); - LevelSolved = TRUE; + LevelSolved = GameOver = TRUE; PlaySoundLevel(x,y,SND_BUING); break; + case EL_BIRNE_AUS: + Feld[x][y] = EL_BIRNE_EIN; + DrawLevelField(x,y); + PlaySoundLevel(x,y,SND_DENG); + return(MF_ACTION); + break; + case EL_ZEIT_VOLL: + Feld[x][y] = EL_ZEIT_LEER; + DrawLevelField(x,y); + PlaySoundStereo(SND_GONG,PSND_MAX_RIGHT); + return(MF_ACTION); + break; default: return(MF_NO_ACTION); break; @@ -2897,202 +2477,3 @@ void TapeErase() { tape.length = 0; } - -void DrawVideoDisplay(unsigned long state, unsigned long value) -{ - int i; - int part1 = 0, part2 = 1; - int xpos = 0, ypos = 1, xsize = 2, ysize = 3; - static char *monatsname[12] = - { - "JAN", "FEB", "MAR", "APR", "MAY", "JUN", - "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" - }; - static int video_pos[10][2][4] = - { - VIDEO_PLAY_LABEL_XPOS, VIDEO_PLAY_LABEL_YPOS, - VIDEO_PLAY_LABEL_XSIZE,VIDEO_PLAY_LABEL_YSIZE, - VIDEO_PLAY_SYMBOL_XPOS, VIDEO_PLAY_SYMBOL_YPOS, - VIDEO_PLAY_SYMBOL_XSIZE,VIDEO_PLAY_SYMBOL_YSIZE, - - VIDEO_REC_LABEL_XPOS, VIDEO_REC_LABEL_YPOS, - VIDEO_REC_LABEL_XSIZE,VIDEO_REC_LABEL_YSIZE, - VIDEO_REC_SYMBOL_XPOS, VIDEO_REC_SYMBOL_YPOS, - VIDEO_REC_SYMBOL_XSIZE,VIDEO_REC_SYMBOL_YSIZE, - - VIDEO_PAUSE_LABEL_XPOS, VIDEO_PAUSE_LABEL_YPOS, - VIDEO_PAUSE_LABEL_XSIZE,VIDEO_PAUSE_LABEL_YSIZE, - VIDEO_PAUSE_SYMBOL_XPOS, VIDEO_PAUSE_SYMBOL_YPOS, - VIDEO_PAUSE_SYMBOL_XSIZE,VIDEO_PAUSE_SYMBOL_YSIZE, - - VIDEO_DATE_LABEL_XPOS, VIDEO_DATE_LABEL_YPOS, - VIDEO_DATE_LABEL_XSIZE,VIDEO_DATE_LABEL_YSIZE, - VIDEO_DATE_XPOS, VIDEO_DATE_YPOS, - VIDEO_DATE_XSIZE,VIDEO_DATE_YSIZE, - - 0,0, - 0,0, - VIDEO_TIME_XPOS, VIDEO_TIME_YPOS, - VIDEO_TIME_XSIZE,VIDEO_TIME_YSIZE, - - VIDEO_BUTTON_PLAY_XPOS, VIDEO_BUTTON_ANY_YPOS, - VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE, - 0,0, - 0,0, - - VIDEO_BUTTON_REC_XPOS, VIDEO_BUTTON_ANY_YPOS, - VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE, - 0,0, - 0,0, - - VIDEO_BUTTON_PAUSE_XPOS, VIDEO_BUTTON_ANY_YPOS, - VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE, - 0,0, - 0,0, - - VIDEO_BUTTON_STOP_XPOS, VIDEO_BUTTON_ANY_YPOS, - VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE, - 0,0, - 0,0, - - VIDEO_BUTTON_EJECT_XPOS, VIDEO_BUTTON_ANY_YPOS, - VIDEO_BUTTON_XSIZE,VIDEO_BUTTON_YSIZE, - 0,0, - 0,0 - }; - - for(i=0;i<20;i++) - { - if (state & (1< STATE_ON / PRESS_OFF */ - cx = DOOR_GFX_PAGEX4; - else - cx = DOOR_GFX_PAGEX3; /* i gerade => STATE_OFF / PRESS_ON */ - - if (video_pos[pos][part1][0]) - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + video_pos[pos][part1][xpos], - cy + video_pos[pos][part1][ypos], - video_pos[pos][part1][xsize], - video_pos[pos][part1][ysize], - VX + video_pos[pos][part1][xpos], - VY + video_pos[pos][part1][ypos]); - if (video_pos[pos][part2][0]) - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + video_pos[pos][part2][xpos], - cy + video_pos[pos][part2][ypos], - video_pos[pos][part2][xsize], - video_pos[pos][part2][ysize], - VX + video_pos[pos][part2][xpos], - VY + video_pos[pos][part2][ypos]); - } - } - - if (state & VIDEO_STATE_DATE_ON) - { - int tag = value % 100; - int monat = (value/100) % 100; - int jahr = (value/10000); - - DrawText(VX+VIDEO_DATE_XPOS,VY+VIDEO_DATE_YPOS, - int2str(tag,2),FS_SMALL,FC_SPECIAL1); - DrawText(VX+VIDEO_DATE_XPOS+27,VY+VIDEO_DATE_YPOS, - monatsname[monat],FS_SMALL,FC_SPECIAL1); - DrawText(VX+VIDEO_DATE_XPOS+64,VY+VIDEO_DATE_YPOS, - int2str(jahr,2),FS_SMALL,FC_SPECIAL1); - } - - if (state & VIDEO_STATE_TIME_ON) - { - int min = value / 60; - int sec = value % 60; - - DrawText(VX+VIDEO_TIME_XPOS,VY+VIDEO_TIME_YPOS, - int2str(min,2),FS_SMALL,FC_SPECIAL1); - DrawText(VX+VIDEO_TIME_XPOS+27,VY+VIDEO_TIME_YPOS, - int2str(sec,2),FS_SMALL,FC_SPECIAL1); - } - - if (state & VIDEO_STATE_DATE) - redraw_mask |= REDRAW_VIDEO_1; - if ((state & ~VIDEO_STATE_DATE) & VIDEO_STATE) - redraw_mask |= REDRAW_VIDEO_2; - if (state & VIDEO_PRESS) - redraw_mask |= REDRAW_VIDEO_3; -} - -void DrawSoundDisplay(unsigned long state) -{ - int pos, cx = DOOR_GFX_PAGEX4, cy = 0; - - pos = (state & BUTTON_SOUND_MUSIC ? SOUND_BUTTON_MUSIC_XPOS : - state & BUTTON_SOUND_LOOPS ? SOUND_BUTTON_LOOPS_XPOS : - SOUND_BUTTON_SOUND_XPOS); - - if (state & BUTTON_ON) - cy -= SOUND_BUTTON_YSIZE; - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + pos,cy + SOUND_BUTTON_ANY_YPOS, - SOUND_BUTTON_XSIZE,SOUND_BUTTON_YSIZE, - DX + pos,DY + SOUND_BUTTON_ANY_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawGameButton(unsigned long state) -{ - int pos, cx = DOOR_GFX_PAGEX4, cy = -GAME_BUTTON_YSIZE; - - pos = (state & BUTTON_GAME_STOP ? GAME_BUTTON_STOP_XPOS : - state & BUTTON_GAME_PAUSE ? GAME_BUTTON_PAUSE_XPOS : - GAME_BUTTON_PLAY_XPOS); - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + pos,cy + GAME_BUTTON_ANY_YPOS, - GAME_BUTTON_XSIZE,GAME_BUTTON_YSIZE, - DX + pos,DY + GAME_BUTTON_ANY_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawChooseButton(unsigned long state) -{ - int pos, cx = DOOR_GFX_PAGEX4, cy = 0; - - pos = (state & BUTTON_OK ? OK_BUTTON_XPOS : NO_BUTTON_XPOS); - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + pos,cy + OK_BUTTON_GFX_YPOS, - OK_BUTTON_XSIZE,OK_BUTTON_YSIZE, - DX + pos,DY + OK_BUTTON_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -} - -void DrawConfirmButton(unsigned long state) -{ - int cx = DOOR_GFX_PAGEX4, cy = 0; - - if (state & BUTTON_PRESSED) - cx = DOOR_GFX_PAGEX3; - - XCopyArea(display,pix[PIX_DOOR],drawto,gc, - cx + CONFIRM_BUTTON_XPOS,cy + CONFIRM_BUTTON_GFX_YPOS, - CONFIRM_BUTTON_XSIZE,CONFIRM_BUTTON_YSIZE, - DX + CONFIRM_BUTTON_XPOS,DY + CONFIRM_BUTTON_YPOS); - - redraw_mask |= REDRAW_DOOR_1; -}