forked from philstopford/CCX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.cpp
executable file
·157 lines (126 loc) · 3.94 KB
/
score.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// score.c
#include "SDL.h"
#include "SDLU.h"
#include <string.h>
#include "main.h"
#include "score.h"
#include "gworld.h"
#include "graphics.h"
#include "blitter.h"
#include "hiscore.h"
#include "gameticks.h"
#include "level.h"
SDL_Surface* scoreSurface;
SDL_Surface* numberSurface;
SDL_Surface* numberMaskSurface;
MRect scoreWindowZRect, scoreWindowRect[2];
MBoolean scoreWindowVisible[2] = {true, true};
long roundStartScore[2], score[2], displayedScore[2], scoreTime[2];
const char characterList[] =
{ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', '.', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', '!', '"', '#',
'$' };
void InitScore( void )
{
const double windowLoc[ ] = { 0.16, 0.84 };
SDL_Rect sdlRect;
scoreWindowZRect.top = scoreWindowZRect.left = 0;
scoreWindowZRect.bottom = 32; scoreWindowZRect.right = 144;
scoreWindowRect[0] = scoreWindowRect[1] = scoreWindowZRect;
CenterRectOnScreen( &scoreWindowRect[0], windowLoc[0], 0.89 );
CenterRectOnScreen( &scoreWindowRect[1], windowLoc[1], 0.89 );
scoreSurface = SDLU_InitSurface( SDLU_MRectToSDLRect( &scoreWindowZRect, &sdlRect ), 16 );
DrawPICTInSurface( scoreSurface, picBoard );
printf("picNumber is %d\n", picNumber);
numberSurface = LoadPICTAsSurface( picNumber, 16 );
printf("picNumbermask is %d\n", picNumberMask);
numberMaskSurface = LoadPICTAsSurface( picNumberMask, 1 );
displayedScore[0] = displayedScore[1] = 0;
score[0] = score[1] = 0;
scoreTime[0] = scoreTime[1] = 0;
}
void UpdateScore( int player )
{
if( GameTickCount( ) >= scoreTime[player] )
{
scoreTime[player] = GameTickCount() + 1;
if( displayedScore[player] < score[player] )
{
if( (score[player] - displayedScore[player]) > 5000 )
{
displayedScore[player] += 1525;
}
else if( (score[player] - displayedScore[player]) > 1000 )
{
displayedScore[player] += 175;
}
else
{
displayedScore[player] += 25;
}
if( displayedScore[player] > score[player] )
displayedScore[player] = score[player];
ShowScore( player );
}
}
}
void ShowScore( int player )
{
SDL_Rect sourceSDLRect, destSDLRect;
MRect myRect;
char myString[256];
int count;
if( !scoreWindowVisible[player] ) return;
if( control[player] == kNobodyControl )
{
}
else
{
sprintf( myString, "%d", displayedScore[player] );
SDLU_AcquireSurface( scoreSurface );
SDLU_BlitSurface( boardSurface[player], &scoreSurface->clip_rect,
scoreSurface, &scoreSurface->clip_rect );
myRect.top = 0;
myRect.left = 2;
myRect.bottom = kNumberVertSize;
myRect.right = myRect.left + kNumberHorizSize;
DrawCharacter( kCharacterScore, &myRect );
OffsetMRect( &myRect, kNumberHorizSize, 0 );
DrawCharacter( kCharacterScore+1, &myRect );
myRect = scoreWindowZRect;
myRect.right -= 2;
myRect.left = myRect.right - kNumberHorizSize;
for( count = strlen(myString) - 1; count >= 0; count-- )
{
DrawCharacter( myString[count], &myRect );
OffsetMRect( &myRect, -kNumberHorizSize - 1, 0 );
}
SDLU_ReleaseSurface( scoreSurface );
SDLU_BlitFrontSurface( scoreSurface,
SDLU_MRectToSDLRect( &scoreWindowZRect, &sourceSDLRect ),
SDLU_MRectToSDLRect( &scoreWindowRect[player], &destSDLRect ) );
}
}
void DrawCharacter( char which, const MRect *myRect )
{
MRect srcRect;
char count, result;
result = -1;
for( count = 0; count < kNumberAmount; count++ )
{
if( characterList[count] == which )
{
result = count;
break;
}
}
if( result == -1 ) return;
srcRect.top = 0;
srcRect.left = result * kNumberHorizSize;
srcRect.bottom = kNumberVertSize;
srcRect.right = srcRect.left + kNumberHorizSize;
SurfaceBlitMask( numberSurface, numberMaskSurface, SDLU_GetCurrentSurface(),
&srcRect, &srcRect, myRect );
}