1 /* $Id: score.c,v 1.2 1998/04/30 05:11:58 mrogre Exp $ */
2 /* Copyright (c) 1998 Joe Rumsey (mrogre@mediaone.net) */
3 #include "copyright.h"
4 
5 #include <config.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include "struct.h"
9 #include "Wlib.h"
10 #include "images.h"
11 #include "data.h"
12 #include "defs.h"
13 #include "proto.h"
14 
15 char scorestr[40] = "Score: 0000000", shipstr[4] ="";
16 W_Image *miniship, *extraImage;
17 int drawExtra = 0, extrax, extray;
18 
undo_score()19 void undo_score()
20 {
21     if(drawExtra)
22 	W_ClearArea(baseWin, extrax-(extraImage->width/2), extray-(extraImage->height/2),
23 		    extraImage->width, extraImage->height);
24 }
25 
do_score()26 void do_score()
27 {
28     static int lastscore, lastlevel, lastships;
29 #ifdef SOUND
30     static int lastsounds;
31 #endif
32     if (lastscore != score)
33     {
34 	if ((score > 0) && (score >= nextBonus))
35         {
36 	    ships++;
37 	    extrax = 0 - extraImage->width/2;
38 	    extray = WINHEIGHT/2;
39 	    drawExtra = 1;
40 	    if (nextBonus < BONUSSHIPSCORE)
41 		nextBonus = BONUSSHIPSCORE;
42 	    else
43 		nextBonus += BONUSSHIPSCORE;
44 	}
45     }
46 
47 #ifdef SOUND
48     if (lastscore != score || lastlevel != level || lastships != ships || lastsounds != playSounds)
49 #else
50     if (lastscore != score || lastlevel != level || lastships != ships)
51 #endif
52     {
53     	W_ClearArea(shellWin, 0, 0, WINWIDTH, W_Textheight + 1);
54 	draw_score();
55 	lastscore=score;
56 	lastlevel=level;
57 	lastships=ships;
58 #ifdef SOUND
59         lastsounds=playSounds;
60 #endif
61     }
62 
63     if (drawExtra)
64     {
65 	extrax += 10;
66 	W_DrawImage(baseWin, extrax-(extraImage->width/2), extray-(extraImage->height/2), 0, extraImage, W_White);
67 	if((extrax-(int)extraImage->width/2) > WINWIDTH)
68 	    drawExtra = 0;
69     }
70 }
71 
draw_score()72 void draw_score()
73 {
74     int basex;
75     int i;
76 
77 #ifdef SOUND
78     sprintf(scorestr, "Score: %07d     Level: %02d  %c", score, level, playSounds ? ' ':'Q');
79 #else
80     sprintf(scorestr, "Sore: %07d     Level: %02d", score, level);
81 #endif
82 
83     basex = WINWIDTH/2 - ((strlen(scorestr)/2)*W_Textwidth);
84     W_MaskText(shellWin, basex, 1, W_Grey, scorestr, strlen(scorestr), W_RegularFont);
85     W_MaskText(shellWin, basex+1, 0, W_Yellow, scorestr, strlen(scorestr), W_RegularFont);
86 
87     for(i=0;i<((ships < 6) ? ships : 6);i++) {
88 	W_DrawImage(shellWin, i*(miniship->width+2), 0, 0, miniship, W_White);
89     }
90 
91     if(ships>6) {
92 	sprintf(shipstr, "%d", ships);
93 	basex = 6*(miniship->width+2) + 2;
94 	W_MaskText(shellWin, basex, 1, W_Grey, shipstr, strlen(shipstr), W_RegularFont);
95 	W_MaskText(shellWin, basex+1, 0, W_Yellow, shipstr, strlen(shipstr), W_RegularFont);
96     }
97 }
98 
init_score()99 void init_score()
100 {
101     miniship = getImage(I_MINISHIP);
102     extraImage = getImage(I_EXTRA);
103 }
104 
105