-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfx_elements.cpp
329 lines (293 loc) · 9.24 KB
/
gfx_elements.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/************************************************************************************
* gfx_elements.cpp
*
* descp : rendering routines for in-game objects.
*
* auth : javery
*
* path : C:\Program Files\Microsoft Visual Studio\MyProjects\PrimaryCubes3D\gfx_elements.cpp
*
* iDate : 09/21/06
* version:
* TO DO : [ 10/15/06 ] Take code from GFX_ELE_DrawFullCube and transfer to G_SyncSprite
************************************************************************************/
#include "gfx_elements.h"
#include "game.h"
#include <allegro.h>
extern BITMAP* pageOne,*pageTwo,*pageThree;
BITMAP* cubes[ CUBE_COUNT ];
/*
========================================================================
GFX_ELE_DrawGameGrid ( debug )
Debugging version of game grid routine.
========================================================================
*/
void GFX_ELE_DrawGameGrid( pGame_t pGame )
{
/*static*/ int rows = pGame->currentSession.yDimen,
cols = pGame->currentSession.xDimen,
xPadding = pGame->currentSession.xPadding,
yPadding = pGame->currentSession.yPadding,
xMax = pGame->gfxConfig.xDimen, // change for more flexablity.
yMax = pGame->gfxConfig.yDimen;
/*static*/ float deltaX = pGame->currentSession.deltaX,
deltaY = pGame->currentSession.deltaY;
for( int y=0; y<=rows; y++ )
{
// horizontal lines
line( pageOne , xPadding ,
( deltaY * y ) + yPadding ,
xMax - xPadding ,
( deltaY * y ) + yPadding ,
G_COLOR_WHITE );
line( pageTwo , xPadding ,
( deltaY * y ) + yPadding ,
xMax - xPadding ,
( deltaY * y ) + yPadding ,
G_COLOR_BLACK );
line( pageThree , xPadding ,
( deltaY * y ) + yPadding ,
xMax - xPadding ,
( deltaY * y ) + yPadding ,
G_COLOR_WHITE );
}
for( int x=0; x<=cols; x++ )
{
// vertical lines.
line( pageOne , ( deltaX * x ) + xPadding ,
yPadding ,
( deltaX * x ) + xPadding ,
yMax - yPadding ,
G_COLOR_WHITE );
line( pageTwo , ( deltaX * x ) + xPadding ,
yPadding ,
( deltaX * x ) + xPadding ,
yMax - yPadding ,
G_COLOR_BLACK );
line( pageThree , ( deltaX * x ) + xPadding ,
yPadding ,
( deltaX * x ) + xPadding ,
yMax - yPadding ,
G_COLOR_WHITE );
}
}
/*
========================================================================
GFX_ELE_DrawCube
Draws game cube, position regulated by grid-space coordinates.
========================================================================
*/
void GFX_ELE_DrawCube( pGame_t pGame , pCube_t pCube )
{
float deltaX = pGame->currentSession.deltaX,
deltaY = pGame->currentSession.deltaY,
xPadding = pGame->currentSession.xPadding,
yPadding = pGame->currentSession.yPadding;
float xInit = ( pCube->gridPosition.xCol * deltaX + xPadding ) ,
yInit = ( pCube->gridPosition.yRow * deltaY + yPadding ) ,
xTerm = ( pCube->gridPosition.xCol * deltaX + xPadding ) + deltaX,
yTerm = ( pCube->gridPosition.yRow * deltaY + yPadding ) + deltaY;
switch( pCube->frontFace )
{
case PRI_RED:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_RED );
rect( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_YELLOW:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_YELLOW );
rect( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_BLUE:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_BLUE );
rect( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_GREEN:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_GREEN );
break;
}
case SEC_PURPLE:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_PURPLE );
break;
}
case SEC_ORANGE:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_ORANGE );
break;
}
case ALT_STONE:
{
rectfill( pageOne , xInit , yInit , xTerm , yTerm , G_COLOR_STONE );
break;
}
}
if ( pCube->frontFlagged )
{
rectfill( pageOne ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_BLACK );
rect( pageOne ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_WHITE );
}
}
/*
=====================================================================================
GFX_ELE_DrawFullCube
Draws both sides of the cube.
=====================================================================================
*/
void GFX_ELE_DrawFullCube( pGame_t pGame ,pCube_t pCube )
{
float deltaX = pGame->currentSession.deltaX,
deltaY = pGame->currentSession.deltaY,
xPadding = pGame->currentSession.xPadding,
yPadding = pGame->currentSession.yPadding;
float xInit = ( pCube->gridPosition.xCol * deltaX + xPadding ) ,
yInit = ( pCube->gridPosition.yRow * deltaY + yPadding ) ,
xTerm = ( pCube->gridPosition.xCol * deltaX + xPadding ) + deltaX,
yTerm = ( pCube->gridPosition.yRow * deltaY + yPadding ) + deltaY;
// take this code, and transfer it to G_SyncSprite
pCube->cubeSprite[ CUBE_FRONT ].currentPosition.xPosition = xInit;
pCube->cubeSprite[ CUBE_FRONT ].currentPosition.yPosition = yInit;
pCube->cubeSprite[ CUBE_BACK ].currentPosition.xPosition = xInit;
pCube->cubeSprite[ CUBE_BACK ].currentPosition.yPosition = yInit;
switch( pCube->frontFace )
{
case PRI_RED:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_RED );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_YELLOW:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_YELLOW );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_BLUE:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLUE );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_GREEN:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_GREEN );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_PURPLE:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_PURPLE );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_ORANGE:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_ORANGE );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case ALT_STONE:
{
rectfill( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_STONE );
rect( pageTwo , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
default:
{
break;
}
}
// debug stuff...
if ( pCube->frontFlagged )
{
rectfill( pageTwo ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_BLACK );
rect( pageTwo ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_WHITE );
}
switch( pCube->rearFace )
{
case PRI_RED:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_RED );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_YELLOW:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_YELLOW );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case PRI_BLUE:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLUE );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_GREEN:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_GREEN );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_PURPLE:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_PURPLE );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case SEC_ORANGE:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_ORANGE );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
case ALT_STONE:
{
rectfill( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_STONE );
rect( pageThree , xInit , yInit , xTerm , yTerm , G_COLOR_BLACK );
break;
}
}
// debug stuff...
if ( pCube->rearFlagged )
{
rectfill( pageThree ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_BLACK );
rect( pageThree ,
xInit + ( deltaX/1.5 ) , yInit + ( deltaY/1.5 ) ,
xTerm - ( deltaX/1.5 ) , yTerm - ( deltaY/1.5 ) ,
G_COLOR_WHITE );
}
}
/*
=======================================================================================
GFX_ELE_DrawCubeSprite
Draws the sprite version of cube. Relys on cube sprites having first been syncronized.
=======================================================================================
*/
void GFX_ELE_DrawCubeSprite( pGame_t pGame , pCube_t pCube )
{
GFX_SPR_DrawSprite( &pCube->cubeSprite[ CUBE_FRONT ] , pageTwo , 1 , 1 );
GFX_SPR_DrawSprite( &pCube->cubeSprite[ CUBE_BACK ] , pageThree , 1 , 1 );
}