1 // Apricots finish game routine
2 // Author: M.D.Snellgrove
3 // Date: 26/3/2002
4 // History:
5 
6 // Changes by M Harman for Windows version, June 2003:
7 //   Changes for graphics and font related stuff.
8 
9 // Changes by M Snellgrove 15/7/2003
10 //   SDLfont used for fonts
11 
12 #include "apricots.h"
13 
14 // Draw a winnerbox
15 
winnerbox(gamedata & g,int winner,int player,int y,int control)16 void winnerbox(gamedata &g, int winner, int player, int y, int control){
17 
18   int boxcolour = 4; // red for losers
19   if (player == control){
20     boxcolour = 13; // green if winner
21   }
22   SDL_Rect rect;
23     rect.x = 200;
24     rect.y = 64+y;
25     rect.w = 240;
26     rect.h = 80;
27   SDL_FillRect(g.virtualscreen,&rect,1);
28     rect.x = 201;
29     rect.y = 65+y;
30     rect.w = 238;
31     rect.h = 78;
32   SDL_FillRect(g.virtualscreen,&rect,boxcolour);
33 
34   if (player == control){
35     char winstring[] = "You win!";
36     g.whitefont.writemask(g.virtualscreen, 288, 72+y, winstring);
37     char congrats[] = "Congratulations";
38     g.whitefont.writemask(g.virtualscreen, 260, 122+y, congrats);
39   }else{
40     char losestring[] = "You lose";
41     g.whitefont.writemask(g.virtualscreen, 288, 72+y, losestring);
42     if (control > 0){
43       char winstring[] = "Player x wins";
44       winstring[7] = '0' + control;
45       g.whitefont.writemask(g.virtualscreen, 268, 112+y, winstring);
46     }else{
47       char winstring[] = "Computer (Plane x) wins";
48       winstring[16] = '0' + winner;
49       g.whitefont.writemask(g.virtualscreen, 228, 112+y, winstring);
50     }
51   }
52 
53 }
54 
55 // Main finish game routine
56 
finish_game(gamedata & g)57 void finish_game(gamedata &g){
58 
59 // Stop enginenoise
60   g.sound.stop(0);
61   g.sound.stop(1);
62 // Display winnerbox
63   if (g.winner > 0){
64     winnerbox(g, g.winner, 1, 0, g.planeinfo[g.winner].control);
65     if (g.players == 2){
66       winnerbox(g, g.winner, 2, 240, g.planeinfo[g.winner].control);
67     }
68 // Update display
69     SDL_Rect rect;
70       rect.x = 0;
71       rect.y = 0;
72       rect.w = 640;
73       rect.h = 480;
74     SDL_BlitSurface(g.virtualscreen, &rect, g.physicalscreen, NULL);
75     SDL_UpdateRect(g.physicalscreen, 0, 0, 0, 0);
76     g.sound.play(SOUND_FINISH);
77 // Wait 4 Seconds
78    int then = time(0);
79    while (time(0) - then < 4){}
80   }
81 // Clean up linkedlists
82   g.radar.clearlist();
83   g.gun.clearlist();
84   g.p.clearlist();
85   g.dp.clearlist();
86   g.explosion.clearlist();
87   g.flame.clearlist();
88   g.smoke.clearlist();
89   g.fall.clearlist();
90   g.shot.clearlist();
91   g.drakgun.clearlist();
92   g.laser.clearlist();
93 
94 }
95