-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbacilli.cpp
346 lines (268 loc) · 9.91 KB
/
bacilli.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#include <allegro.h>
#include "game.h"
#include "bacilli.h"
#include "player.h"
extern BITMAP* doubleBuffer;
extern float masterScale;
extern float sineLookup[]; // limit access to TRIG_TABLE_SIZE
extern float cosineLookup[];
static BITMAP* bacilliFrames[ BACILLI_FRAMES ];
static char* fileNames[] =
{
"content/gfx/enemies/bacilli/bc_1.bmp" ,
"content/gfx/enemies/bacilli/bc_2.bmp" ,
"content/gfx/enemies/bacilli/bc_3.bmp" ,
"content/gfx/enemies/bacilli/bc_4.bmp" ,
"content/gfx/enemies/bacilli/bc_5.bmp" ,
"content/gfx/enemies/bacilli/bc_seg_1.bmp" ,
"content/gfx/enemies/bacilli/bc_seg_2.bmp" ,
"content/gfx/enemies/bacilli/bc_seg_3.bmp" ,
"content/gfx/enemies/bacilli/bc_seg_4.bmp" ,
"content/gfx/enemies/bacilli/bc_seg_5.bmp" ,
"content/gfx/enemies/expl_1.bmp" ,
"content/gfx/enemies/expl_2.bmp" ,
"content/gfx/enemies/expl_3.bmp" ,
"content/gfx/enemies/expl_4.bmp" ,
"content/gfx/enemies/expl_5.bmp" ,
"content/gfx/enemies/expl_6.bmp" ,
"content/gfx/enemies/expl_7.bmp" ,
"content/gfx/enemies/expl_8.bmp"
};
static int headRunningAnimation[] =
{
BACILLI_FRAME_00 ,
BACILLI_FRAME_01 ,
BACILLI_FRAME_02 ,
BACILLI_FRAME_02 ,
BACILLI_FRAME_03 ,
BACILLI_FRAME_04 ,
BACILLI_FRAME_03 ,
BACILLI_FRAME_02 ,
BACILLI_FRAME_02 ,
BACILLI_FRAME_01
};
static int segmentRunningAnimation[] =
{
BACILLI_FRAME_05 ,
BACILLI_FRAME_06 ,
BACILLI_FRAME_07 ,
BACILLI_FRAME_07 ,
BACILLI_FRAME_08 ,
BACILLI_FRAME_09 ,
BACILLI_FRAME_08 ,
BACILLI_FRAME_07 ,
BACILLI_FRAME_07 ,
BACILLI_FRAME_06
};
static int explosionSequence[] =
{
BACILLI_FRAME_10 ,
BACILLI_FRAME_11 ,
BACILLI_FRAME_12 ,
BACILLI_FRAME_13 ,
BACILLI_FRAME_14 ,
BACILLI_FRAME_15 ,
BACILLI_FRAME_16 ,
BACILLI_FRAME_17
};
static SequenceInfo_t bacilliSequences[] =
{
{ BACILLI_HEAD_RUNNING_SEQUENCE_STEPS , 0 , headRunningAnimation , 0 , 0 , -1 } ,
{ BACILLI_SEGM_RUNNING_SEQUENCE_STEPS , 0 , segmentRunningAnimation , 0 , 0 , -1 } ,
{ BACILLI_EXPLOSION_SEQUENCE_STEPS , 0 , explosionSequence , 0 , 0 , -1 }
};
// BACILLI ////////////////////////////////////////////////////////////////////////////////////////////
void Bacilli_Spawn( pBacilli_t pBC , int xPosition , int yPosition )
{
pBC->amplitude = rand()%MAX_BACILLI_AMPLITUDE;
pBC->periodFactor = rand()%MAX_BACILLI_PERIOD_FACTOR;
pBC->trigIndex = 0;
if( !pBC->amplitude )
{
pBC->amplitude = 1;
}
if( !pBC->periodFactor )
{
pBC->periodFactor = 1;
}
P_CreateEntity( &pBC->ent , 0 , 0 , BACILLI_SIZE_X , BACILLI_SIZE_Y , xPosition , yPosition , BACILLI_SPEED , 0 , ENTITY_TYPE_BACILLI );
pBC->ent.frames = bacilliFrames;
pBC->ent.animationData.rate = BACILLI_ANIMATION_RATE;
Ent_UpdateAnimationSequence( &pBC->ent , &bacilliSequences[ BACILLI_HEAD_RUNNING_SEQUENCE ] );
Ent_AddExplosions( &pBC->ent , pBC->explosions , BACILLI_EXPLOSIONS , &bacilliSequences[ BACILLI_EXPLOSION_SEQUENCE ] );
}
void Bacilli_Spawn( pBacilli_t pBC , pSpawnPoint_t pSpawnPoint )
{
pBC->amplitude = rand() % MAX_BACILLI_AMPLITUDE;
pBC->periodFactor = rand() % MAX_BACILLI_PERIOD_FACTOR;
pBC->trigIndex = 0;
pBC->ent.entityType = ENTITY_TYPE_BACILLI;
if( !pBC->amplitude ) pBC->amplitude = 1;
if( !pBC->periodFactor ) pBC->periodFactor = 1;
P_CreateEntity( &pBC->ent , 0 , 0 , BACILLI_SIZE_X , BACILLI_SIZE_Y , SCREEN_W , pSpawnPoint->mapCoords.y , BACILLI_SPEED , 0 , ENTITY_TYPE_BACILLI );
pBC->ent.frames = bacilliFrames;
pBC->ent.animationData.rate = BACILLI_ANIMATION_RATE;
Ent_UpdateAnimationSequence( &pBC->ent , &bacilliSequences[ BACILLI_HEAD_RUNNING_SEQUENCE ] );
Ent_AddExplosions( &pBC->ent , pBC->explosions , BACILLI_EXPLOSIONS , &bacilliSequences[ BACILLI_EXPLOSION_SEQUENCE ] );
}
/*
** returns true if it is completely dead, false otherwise
*/
r_boolean Bacilli_Kill( pBacilli_t pBC )
{
return r_true;
}
void Bacilli_Destroy( pBacilli_t pBC )
{
}
r_boolean Bacilli_Run( pBacilli_t pBC )
{
pBC->ent.position.x -= pBC->ent.speed;
if( (pBC->trigIndex * pBC->periodFactor ) >= TRIG_TABLE_SIZE )
{
pBC->trigIndex = 0;
}
else
{
pBC->trigIndex++;
}
// good ole trig-displacement path.
pBC->ent.position.y += pBC->amplitude * cosineLookup[ pBC->trigIndex * pBC->periodFactor ];
// explode if collided
if( pBC->ent.collided )
{
for( int explosion = 0;explosion < BACILLI_EXPLOSIONS;explosion++ )
{
Ent_InitExplosion( &pBC->ent , &pBC->explosions[ explosion ] , BACILLI_EXPLOSION_LENGTH );
}
}
// prepare to kill if sufficently offscreen
return ( pBC->ent.position.x > -30 ) ? ( r_true ) : ( r_false );
}
void Bacilli_Draw( pBacilli_t pBC )
{
int color = ( pBC->ent.collided ) ? makecol( 255 , 255 , 255 ) : makecol( 255 , 105 , 180 );
// ellipsefill( doubleBuffer , pBC->ent.position.x , pBC->ent.position.y , 20 , 10 , color );
G_WriteToDebugWindow( pBC->ent.onscreenTargetID , "%i" , pBC->ent.position.x , pBC->ent.position.y );
Ent_Animate( &pBC->ent );
Ent_Draw( &pBC->ent , 1 , 1 , 0 );
for( int explosion = 0;explosion < BACILLI_EXPLOSIONS;explosion++ )
{
if( pBC->explosions[ explosion ].ent.active )
{
pExplosion_t pEX = &pBC->explosions[ explosion ];
Ent_RunExplosion( &pBC->ent , pEX );
Ent_Animate( &pEX->ent );
Ent_Draw( &pEX->ent , pEX->scale , pEX->scale , 0 );
}
}
}
// DIPLO BACILLI ////////////////////////////////////////////////////////////////////////////////////////////
void DiploBacilli_Spawn( pDiploBacilli_t pDB , int xPosition , int yPosition )
{
pBacilli_t pHead = &pDB->segments[ BACILLI_HEAD_SEGMENT ];
pBacilli_t pTail = &pDB->segments[ BACILLI_SEGMENT_1 ];
// first spawn a randomized head.
Bacilli_Spawn( pHead , xPosition , yPosition );
Bacilli_Spawn( pTail , ( xPosition + pHead->ent.w ) , yPosition ); // some of these values will be overwritten...
// use the generated head to derived the tail segment
pTail->amplitude = pHead->amplitude;
pTail->periodFactor = pHead->periodFactor;
pTail->trigIndex = 0;
// set the ent types
pHead->ent.entityType = ENTITY_TYPE_DIPLOBACILLI;
pTail->ent.entityType = ENTITY_TYPE_DIPLOBACILLI;
// set animation data
pHead->ent.frames = bacilliFrames;
pHead->ent.animationData.rate =
pTail->ent.animationData.rate = BACILLI_ANIMATION_RATE;
Ent_UpdateAnimationSequence( &pHead->ent , &bacilliSequences[ BACILLI_HEAD_RUNNING_SEQUENCE ] );
Ent_UpdateAnimationSequence( &pTail->ent , &bacilliSequences[ BACILLI_SEGM_RUNNING_SEQUENCE ] );
}
void DiploBacilli_Spawn( pDiploBacilli_t pDB , pSpawnPoint_t pSpawnPoint )
{
DiploBacilli_Spawn( pDB , SCREEN_W , pSpawnPoint->mapCoords.y );
}
r_boolean DiploBacilli_Kill( pDiploBacilli_t pDB )
{
return r_true;
}
void DiploBacilli_Destroy( pDiploBacilli_t pDB )
{
}
r_boolean DiploBacilli_Run( pDiploBacilli_t pDB )
{
r_boolean active =
// diplos are syncronous, so just call the bacilli routine on each segment
Bacilli_Run( &pDB->segments[ BACILLI_SEGMENT_1 ] );
Bacilli_Run( &pDB->segments[ BACILLI_HEAD_SEGMENT ] );
return active;
}
void DiploBacilli_Draw( pDiploBacilli_t pDB )
{
Bacilli_Draw( &pDB->segments[ BACILLI_SEGMENT_1 ] );
Bacilli_Draw( &pDB->segments[ BACILLI_HEAD_SEGMENT ] );
}
// STREPTO BACILLI ////////////////////////////////////////////////////////////////////////////////////////////
void StreptoBacilli_Spawn( pStreptoBacilli_t pSBC , int xPosition , int yPosition )
{
pBacilli_t head = &pSBC->segments[ BACILLI_HEAD_SEGMENT ];
int seperation = 32;//head->ent.w;
// create distance between each segment.
Bacilli_Spawn( &pSBC->segments[ BACILLI_HEAD_SEGMENT ] , xPosition + ( seperation * 0 ) , yPosition ); // seperation == NO_OP
Bacilli_Spawn( &pSBC->segments[ BACILLI_SEGMENT_1 ] , xPosition + ( seperation * 1 ) , yPosition );
Bacilli_Spawn( &pSBC->segments[ BACILLI_SEGMENT_2 ] , xPosition + ( seperation * 2 ) , yPosition );
Bacilli_Spawn( &pSBC->segments[ BACILLI_SEGMENT_3 ] , xPosition + ( seperation * 3 ) , yPosition );
Bacilli_Spawn( &pSBC->segments[ BACILLI_TAIL_SEGMENT ] , xPosition + ( seperation * 4 ) , yPosition );
// reassign this ( changed by Bacilli_Spawn )
head->ent.entityType = ENTITY_TYPE_STREPTOBACILLI;
// head's animation stuff
head->ent.frames = bacilliFrames;
head->ent.animationData.rate = BACILLI_ANIMATION_RATE;
Ent_UpdateAnimationSequence( &head->ent , &bacilliSequences[ BACILLI_HEAD_RUNNING_SEQUENCE ] );
// unify the segments according to the randomized movement data in the head.
for( int segment = 1;segment < BASIC_STREPTOBACILLI_SEGMENTS;segment++ )
{
pSBC->segments[ segment ].amplitude = head->amplitude;
pSBC->segments[ segment ].periodFactor = head->periodFactor;
// create a variance in phase-shift inorder to break syncronicity.
pSBC->segments[ segment ].trigIndex = (segment * 10) / head->periodFactor;
pSBC->segments[ segment ].ent.entityType = ENTITY_TYPE_STREPTOBACILLI;
// animation stuphs
pSBC->segments[ segment ].ent.animationData.rate = BACILLI_ANIMATION_RATE;
pSBC->segments[ segment ].ent.frames = bacilliFrames;
Ent_UpdateAnimationSequence( &pSBC->segments[ segment ].ent , &bacilliSequences[ BACILLI_SEGM_RUNNING_SEQUENCE ] );
}
}
void StreptoBacilli_Spawn( pStreptoBacilli_t pSBC , pSpawnPoint_t pSpawnPoint )
{
StreptoBacilli_Spawn( pSBC , SCREEN_W , pSpawnPoint->mapCoords.y );
}
r_boolean StreptoBacilli_Kill( pStreptoBacilli_t pSBC )
{
return r_true;
}
void StreptoBacilli_Destroy( pStreptoBacilli_t pSBC )
{
}
r_boolean StreptoBacilli_Run( pStreptoBacilli_t pSBC )
{
int speed = pSBC->segments[ BACILLI_HEAD_SEGMENT ].ent.speed;
for( int segment = 0;segment < BASIC_STREPTOBACILLI_SEGMENTS;segment++ )
{
Bacilli_Run( &pSBC->segments[ segment ] );
}
// run until the tail is completely offscreen
return ( pSBC->segments[ BACILLI_TAIL_SEGMENT ].ent.position.x > -10 ) ? ( r_true ) : ( r_false );
}
void StreptoBacilli_Draw( pStreptoBacilli_t pSBC )
{
for( int segment = BASIC_STREPTOBACILLI_SEGMENTS-1;segment>-1;segment-- )
{
Bacilli_Draw( &pSBC->segments[ segment ] );
}
}
r_boolean Bacilli_LoadFrames( void )
{
return Ent_LoadData( bacilliFrames , fileNames , BACILLI_FRAMES );
}