-
Notifications
You must be signed in to change notification settings - Fork 0
/
gworld.cpp
226 lines (175 loc) · 5.18 KB
/
gworld.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// gworld.c
#include "stdafx.h"
#include "SDLU.h"
#include "main.h"
#include "gworld.h"
#include "blitter.h"
#include "graphics.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
SDL_Surface* blobSurface;
SDL_Surface* maskSurface;
SDL_Surface* charMaskSurface;
SDL_Surface* boardSurface[2];
SDL_Surface* blastSurface;
SDL_Surface* blastMaskSurface;
SDL_Surface* playerSurface[2];
SDL_Surface* playerSpriteSurface[2];
void GetBlobGraphics()
{
MRect myRect;
// Get board
myRect.top = myRect.left = 0;
myRect.right = kBlobHorizSize * kGridAcross;
myRect.bottom = kBlobVertSize * (kGridDown-1);
boardSurface[0] = LoadPICTAsSurface( picBoard, 32 );
boardSurface[1] = LoadPICTAsSurface( picBoardRight, 32 );
if( boardSurface[1] == NULL )
boardSurface[1] = LoadPICTAsSurface( picBoard, 32 );
// Get blob worlds
blobSurface = LoadPICTAsSurface( picBlob, 32 );
maskSurface = LoadPICTAsSurface( picBlobMask, 1 );
charMaskSurface = LoadPICTAsSurface( picCharMask, 1 );
// Get blast worlds
blastSurface = LoadPICTAsSurface( picBlast, 32 );
blastMaskSurface = LoadPICTAsSurface( picBlastMask, 32 );
}
void InitPlayerWorlds()
{
MRect myRect;
SDL_Rect sdlRect;
int count;
myRect.top = myRect.left = 0;
myRect.right = kGridAcross * kBlobHorizSize;
myRect.bottom = kGridDown * kBlobVertSize;
SDLU_MRectToSDLRect( &myRect, &sdlRect );
for( count=0; count<=1; count++ )
{
playerSurface[count] = SDLU_InitSurface( &sdlRect, 32 );
playerSpriteSurface[count] = SDLU_InitSurface( &sdlRect, 32 );
}
}
void SurfaceDrawBoard( int player, const MRect *myRect )
{
MRect srcRect, offsetRect;
SDL_Rect srcSDLRect, offsetSDLRect;
srcRect = *myRect;
if( srcRect.bottom <= kBlobVertSize ) return;
if( srcRect.top < kBlobVertSize ) srcRect.top = kBlobVertSize;
offsetRect = srcRect;
OffsetMRect( &offsetRect, 0, -kBlobVertSize );
SDLU_BlitSurface( boardSurface[player], SDLU_MRectToSDLRect( &offsetRect, &offsetSDLRect ),
SDLU_GetCurrentSurface(), SDLU_MRectToSDLRect( &srcRect, &srcSDLRect ) );
}
void SurfaceDrawBlob( int player, const MRect *myRect, int blob, int state, int charred )
{
SurfaceDrawBoard( player, myRect );
SurfaceDrawSprite( myRect, blob, state );
if( charred & 0x0F )
{
MRect blobRect, charRect, alphaRect;
CalcBlobRect( (charred & 0x0F), kBombTop-1, &charRect );
CalcBlobRect( (charred & 0x0F), kBombBottom-1, &alphaRect );
CalcBlobRect( state, blob-1, &blobRect );
SurfaceBlitWeightedDualAlpha( SDLU_GetCurrentSurface(), blobSurface, charMaskSurface, blobSurface, SDLU_GetCurrentSurface(),
myRect, &charRect, &blobRect, &alphaRect, myRect,
(charred & 0xF0) );
}
}
void SurfaceDrawShadow( const MRect *myRect, int blob, int state )
{
int x;
const MPoint offset[4] = { {-2, 0}, {0, -2}, {2, 0}, {0, 2} };
if( blob > kEmpty )
{
MRect blobRect, destRect;
for( x=0; x<4; x++ )
{
destRect = *myRect;
OffsetMRect( &destRect, offset[x].h, offset[x].v );
CalcBlobRect( state, blob-1, &blobRect );
SurfaceBlitColor( maskSurface, SDLU_GetCurrentSurface(),
&blobRect, &destRect,
0, 0, 0, _5TO8(3) );
}
}
}
void SurfaceDrawColor( const MRect *myRect, int blob, int state, int r, int g, int b, int w )
{
MRect blobRect;
if( blob > kEmpty )
{
CalcBlobRect( state, blob-1, &blobRect );
SurfaceBlitColor( charMaskSurface, SDLU_GetCurrentSurface(),
&blobRect, myRect,
r, g, b, w );
}
}
void SurfaceDrawAlpha( const MRect *myRect, int blob, int mask, int state )
{
if( blob > kEmpty )
{
MRect blobRect, alphaRect;
CalcBlobRect( state, blob-1, &blobRect );
CalcBlobRect( state, mask-1, &alphaRect );
SurfaceBlitAlpha( SDLU_GetCurrentSurface(), blobSurface, blobSurface, SDLU_GetCurrentSurface(),
myRect, &blobRect, &alphaRect, myRect );
}
}
void SurfaceDrawSprite( const MRect *myRect, int blob, int state )
{
MRect blobRect;
if( blob > kEmpty )
{
CalcBlobRect( state, blob-1, &blobRect );
SurfaceBlitBlob( &blobRect, myRect );
}
}
MBoolean PICTExists( int pictID )
{
if( FileExists( QuickResourceName( "PICT", pictID, ".jpg" ) ) )
return true;
if( FileExists( QuickResourceName( "PICT", pictID, ".png" ) ) )
return true;
return false;
}
SDL_Surface* LoadPICTAsSurface( int pictID, int depth )
{
const char* filename;
SDL_Surface* surface;
filename = QuickResourceName( "PICT", pictID, ".jpg" );
if( FileExists( filename ) )
{
surface = IMG_Load( filename );
}
else
{
filename = QuickResourceName( "PICT", pictID, ".png" );
if( FileExists( filename ) )
{
surface = IMG_Load( filename );
}
else
{
// Fail
return NULL;
}
}
if( depth != 0 )
{
SDLU_ChangeSurfaceDepth( &surface, depth );
}
return surface;
}
void DrawPICTInSurface( SDL_Surface* surface, int pictID )
{
SDL_Surface* image;
image = LoadPICTAsSurface( pictID, 0 );
if( image != NULL )
{
SDLU_BlitSurface( image, &image->clip_rect,
surface, &surface->clip_rect );
SDL_FreeSurface( image );
}
}