- }
- else {
- state = HIGH_SCORE_DISPLAY;
- state_timeout=400;
- }
-
- case HIGH_SCORE_DISPLAY:
- // Display de list o high scores mon.
- PutString(surf_screen,180,50,"High scores");
- for (i=0; i<8; i++) {
- char s[1024];
- sprintf(s, "#%1d",i+1);
- PutString(surf_screen, 150, 50+(i+2)*font_height,s);
- snprintscore(s, 1024, high[i].score);
- PutString(surf_screen, 200, 50+(i+2)*font_height,s);
- sprintf(s, "%3s", high[i].name);
- PutString(surf_screen, 330, 50+(i+2)*font_height,s);
- }
-
- }
-
- if (!gameover && state==GAMEPLAY) {
- // Show the freaky shields
- SDL_LockSurface(surf_screen);
- raw_pixels = (Uint16 *) surf_screen->pixels;
- if (initialshield>0 || shieldsup && shieldlevel>0) {
- int x,y,l;
- Uint16 c;
-
- if (initialshield>0) {
- initialshield-=movementrate;
- c = SDL_MapRGB(surf_screen->format,0,255,255);
- }
- else {
- c = heatcolor[(int)shieldlevel];
- shieldlevel-=movementrate;
- }
-
- shieldpulse += 0.2;
- for (p=black_point; p<blackptr; p++) {
- x = p->x + (int)xship + (rnd()+rnd()-1)*sin(shieldpulse)*4 + 1;
- y = p->y + (int)yship + (rnd()+rnd()-1)*sin(shieldpulse)*4 + 1;
- if (x>0 && y>0 && x<XSIZE && y<YSIZE) {
- offset = surf_screen->pitch/2 * y + x;
- raw_pixels[offset] = c;
+ }
+
+ // If it's game over, show the game over graphic in the dead centre
+ switch (state) {
+ case GAME_OVER:
+ if(fadetimer<3.0/faderate) {
+ fadegame = fadetimer/(3.0/faderate);
+ } else {
+ fadegame = 1.0;
+ }
+
+ if(fadetimer<3.0/faderate) {
+ fadeover = 0.0;
+ } else if(fadetimer<6.0/faderate) {
+ fadeover = ((3.0/faderate)-fadetimer)/(6.0/faderate);
+ } else {
+ fadeover = 1.0;
+ }
+
+ src.w = surf_b_game->w;
+ src.h = surf_b_game->h;
+ dest.w = src.w;
+ dest.h = src.h;
+ dest.x = (XSIZE-src.w)/2;
+ dest.y = (YSIZE-src.h)/2-40;
+ SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += movementrate/1.0))));
+ SDL_BlitSurface(surf_b_game,&src,surf_screen,&dest);
+
+ src.w = surf_b_over->w;
+ src.h = surf_b_over->h;
+ dest.w = src.w;
+ dest.h = src.h;
+ dest.x = (XSIZE-src.w)/2;
+ dest.y = (YSIZE-src.h)/2 + 40;
+ SDL_SetAlpha(surf_b_over, SDL_SRCALPHA, (int)(fadeover*(200 + 55*sin(fadetimer))));
+ SDL_BlitSurface(surf_b_over,&src,surf_screen,&dest);
+ break;
+
+ case TITLE_PAGE:
+
+ src.w = surf_b_variations->w;
+ src.h = surf_b_variations->h;
+ dest.w = src.w;
+ dest.h = src.h;
+ dest.x = (XSIZE-src.w)/2 + cos(fadetimer/6.5)*10;
+ dest.y = (YSIZE/2-src.h)/2 + sin(fadetimer/5.0)*10;
+ SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += movementrate/2.0)));
+ SDL_BlitSurface(surf_b_variations,&src,surf_screen,&dest);
+
+ src.w = surf_b_on->w;
+ src.h = surf_b_on->h;
+ dest.w = src.w;
+ dest.h = src.h;
+ dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 1.0)/6.5)*10;
+ dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + 20 + sin((fadetimer + 1.0)/5.0)*10;
+ SDL_SetAlpha(surf_b_on, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-1.0)));
+ SDL_BlitSurface(surf_b_on,&src,surf_screen,&dest);
+
+ src.w = surf_b_rockdodger->w;
+ src.h = surf_b_rockdodger->h;
+ dest.w = src.w;
+ dest.h = src.h;
+ dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 2.0)/6.5)*10;
+ dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + surf_b_on->h + 40 + sin((fadetimer + 2.0)/5)*10;
+ SDL_SetAlpha(surf_b_rockdodger, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-2.0)));
+ SDL_BlitSurface(surf_b_rockdodger,&src,surf_screen,&dest);
+
+ text = "Version " VERSION;
+ x = (XSIZE-SFont_wide(text))/2 + sin(fadetimer/4.5)*10;
+ PutString(surf_screen,x,YSIZE-50 + sin(fadetimer/2)*5,text);
+
+ text = sequence[(int)(fadetimer/40)%NSEQUENCE];
+ //text = "Press SPACE to start!";
+ x = (XSIZE-SFont_wide(text))/2 + cos(fadetimer/4.5)*10;
+ PutString(surf_screen,x,YSIZE-100 + cos(fadetimer/3)*5,text);
+ break;
+
+ case HIGH_SCORE_ENTRY:
+
+ if(score >= high[7].score) {
+ play_tune(2);
+ if(SFont_Input (surf_screen, 330, 50 + (scorerank + 2)*font_height, 300, name)) {
+ // Insert name into high score table
+
+ // Lose the lowest name forever (loser!)
+ //if(high[7].allocated)
+ // free(high[7].name); // THIS WAS CRASHING SO I REMOVED IT
+
+ // Insert new high score
+ high[scorerank].score = score;
+ high[scorerank].name = strdup(name); // MEMORY NEVER FREED!
+ high[scorerank].allocated = 1;
+
+ // Set the global name string to "", ready for the next winner
+ name[0] = 0;
+
+ // Change state to briefly show high scores page
+ state = HIGH_SCORE_DISPLAY;
+ state_timeout = 200;
+
+ // Write the high score table to the file
+ write_high_score_table();
+
+ // Play the title page tune
+ play_tune(0);
+ }
+ } else {
+ state = HIGH_SCORE_DISPLAY;
+ state_timeout = 400;
+ }
+ // FALL THROUGH
+
+ case HIGH_SCORE_DISPLAY:
+ // Display de list o high scores mon.
+ PutString(surf_screen,180,50,"High scores");
+ for(i = 0; i<8; i++) {
+ char s[1024];
+ sprintf(s, "#%1d",i + 1);
+ PutString(surf_screen, 150, 50 + (i + 2)*font_height,s);
+ snprintscore(s, 1024, high[i].score);
+ PutString(surf_screen, 200, 50 + (i + 2)*font_height,s);
+ sprintf(s, "%3s", high[i].name);
+ PutString(surf_screen, 330, 50 + (i + 2)*font_height,s);
+ }
+
+ }
+
+ if(!gameover && state == GAMEPLAY) {
+ SDL_LockSurface(surf_screen);
+ raw_pixels = (Uint16 *) surf_screen->pixels;
+ // Check that the black points on the ship are
+ // still black, and not covered up by rocks.
+ for(p = black_point; p<blackptr; p++) {
+ offset = surf_screen->pitch/2 * (p->y + (int)yship) + p->x + (int)xship;
+ if(raw_pixels[offset]) {
+ // Set the bang flag
+ bang = 1;
+ }