Repository navigation
Expand file tree
/
Copy pathblasto.cpp
More file actions
249 lines (198 loc) · 6.27 KB
/
Copy pathblasto.cpp
File metadata and controls
249 lines (198 loc) · 6.27 KB
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
#include <allegro.h>
#include "game.h"
#include "blasto.h"
#include "player.h"
extern BITMAP* doubleBuffer;
extern float masterScale;
extern Game_t currentGame;
// patterns /////////////////////////////////////////////////////////////////////////////////////
BlastoControls_t testPattern[ TEST_PATTERN_SIZE ] =
{
{ 400 , 0 , 0 , 0 } ,
{ 0 , 0 , 200 , 0 } ,
{ 10 , 0 , 0 , 0 } ,
{ 0 , 0 , 0 , 200 } ,
{ 1000 , 0 , 0 , 0 }
};
// implementation ///////////////////////////////////////////////////////////////////////////////
void Blasto_Spawn( pBlasto_t pB , int xPosition , int yPosition )
{
P_CreateEntity( &pB->ent , 0 , 0 , 32 , 32 , xPosition , yPosition , BLASTO_SPEED , BLASTO_FRAMES , ENTITY_TYPE_BLASTO );
P_CreateEntity( &pB->projectile , 0 , 0 , 20 , 10 , xPosition , yPosition , BLASTO_PROJECTILE_SPEED , BLASTO_PROJECTILE_FRAMES , ENTITY_DUMMY_TYPE );
pB->ent.entityType = ENTITY_TYPE_BLASTO;
// start with a fresh memory.
pB->synapse = 0;
pB->pulse = r_false;
pB->step = 0;
pB->totalSteps = 3;
// init with the default pattern.
pB->currentPattern = &testPattern[ pB->step ];
}
void Blasto_Spawn( pBlasto_t pB , pSpawnPoint_t pSpawnPoint )
{
Blasto_Spawn( pB , SCREEN_W , pSpawnPoint->mapCoords.y );
}
r_boolean Blasto_Destroy( pBlasto_t pB )
{
return r_true;
}
void Blasto_Kill( pBlasto_t pB )
{
}
r_boolean Blasto_Run( pBlasto_t pB , pPlayer_t pP )
{
//pB->ent.position.x -= pB->ent.speed;
// shoot when blasto's memory is full
if( pB->synapse == ( BLASTO_MEMORY_SIZE - 1) )
{
Blasto_Shoot( pB );
pB->synapse = 0;
}
else
// run current pattern while tracking player.
{
if( pB->projectile.active )
// process the old bullet until it's dead
{
Blasto_ProcessBullet( pB , pP );
}
// track position of player
pB->targetMemory[ pB->synapse ] = pP->ent.position;
pB->synapse++;
// update blasto based on it's current position.
if( !Blasto_ExecutePattern( pB ) )
{
// move on to the next step
if( pB->step < 4 )
{
pB->step++;
}
else
{
pB->step = 0;
}
pB->currentPattern = &testPattern[ pB->step ];
}
}
return ( (pB->ent.position.x > -pB->ent.w) || (pB->ent.position.x < -pB->ent.w) )
? ( r_true ) : ( r_false );
}
static Vect2_t Blasto_PredictTarget( pBlasto_t pB , pPlayer_t pP )
{
Vect2_t target = { 0 , 0 };
return target;
}
static void Blasto_Shoot( pBlasto_t pB )
// shoots at the target stored in memory
{
// activate projectile
pB->projectile.active = r_true;
pB->projectile.position = pB->ent.position;
//pB->projectile.position.x = pB->targetMemory[ BLASTO_MEMORY_SIZE - 1 ].x;
}
static r_boolean Blasto_ProcessBullet( pBlasto_t pB , pPlayer_t pP )
{
if( pB->projectile.position.x > -pB->projectile.w )
{
pB->projectile.position.x -= BLASTO_PROJECTILE_SPEED;
if( Ent_TestForCollision( &pP->ent , &pB->projectile ) )
{
pB->projectile.active = r_false; // damage player
}
}
else
{
pB->projectile.active = r_false;
}
return pB->projectile.active;
}
static r_boolean Blasto_ExecutePattern( pBlasto_t pB )
// return false when unable to complete the pattern
{
r_boolean upComplete = r_false,
downComplete = r_false,
leftComplete = r_false,
rightComplete = r_false,
patternIncomplete = r_true;
if( pB->currentControlState.directions[ PATTERN_DIRECTION_LEFT ] < pB->currentPattern->directions[ PATTERN_DIRECTION_LEFT ] )
{
pB->ent.position.x -= pB->ent.speed;
pB->currentControlState.directions[ PATTERN_DIRECTION_LEFT ] += pB->ent.speed;
}
else
{
leftComplete = r_true;
}
if( pB->currentControlState.directions[ PATTERN_DIRECTION_RIGHT ] < pB->currentPattern->directions[ PATTERN_DIRECTION_RIGHT ] )
{
pB->ent.position.x += pB->ent.speed;
pB->currentControlState.directions[ PATTERN_DIRECTION_RIGHT ] += pB->ent.speed;
}
else
{
rightComplete = r_true;
}
if( pB->currentControlState.directions[ PATTERN_DIRECTION_UP ] < pB->currentPattern->directions[ PATTERN_DIRECTION_UP ] )
{
pB->ent.position.y -= pB->ent.speed;
pB->currentControlState.directions[ PATTERN_DIRECTION_UP ] += pB->ent.speed;
}
else
{
upComplete = r_true;
}
if( pB->currentControlState.directions[ PATTERN_DIRECTION_DOWN ] < pB->currentPattern->directions[ PATTERN_DIRECTION_DOWN ] )
{
pB->ent.position.y += pB->ent.speed;
pB->currentControlState.directions[ PATTERN_DIRECTION_DOWN ] += pB->ent.speed;
}
else
{
downComplete = r_true;
}
// determine if the pattern is completely completed.
if( leftComplete && rightComplete && upComplete && downComplete )
{
patternIncomplete = r_false;
}
return patternIncomplete;
}
void Blasto_Draw( pBlasto_t pB )
{
int color = ( pB->ent.collided ) ? makecol( 255 , 255 , 255 ) : makecol( 255 , 187 , 255 );
// draw blasto
rectfill( doubleBuffer ,
pB->ent.position.x ,
pB->ent.position.y ,
pB->ent.position.x + pB->ent.w ,
pB->ent.position.y + pB->ent.h ,
color );
// draw bullet if its activeated.
if( pB->projectile.active )
{
int bulletColor = (pB->pulse) ? (makecol(255,255,255)) : (makecol(255,0,0));
if( pB->projectile.collided )
{
bulletColor = makecol( 0 , 0 , 0 );
}
pB->pulse = (pB->pulse) ? (r_false) : (r_true);
rectfill( doubleBuffer ,
pB->projectile.position.x ,
pB->projectile.position.y ,
pB->projectile.position.x + pB->projectile.w ,
pB->projectile.position.y + pB->projectile.h ,
bulletColor
);
}
// debug : draw blasto tracking
for( int p=0;p<pB->synapse-1;p++ )
{
int lineColor=makecol( 255-pB->synapse,0,0);
line( doubleBuffer , pB->targetMemory[p].x , pB->targetMemory[p].y , pB->targetMemory[p+1].x , pB->targetMemory[p+1].y , makecol( 255 , 200 , 200 ) );
line( doubleBuffer , pB->targetMemory[p].x+1 , pB->targetMemory[p].y+1 , pB->targetMemory[p+1].x+1 , pB->targetMemory[p+1].y+1 , makecol( 255 , 200 , 200 ) );
line( doubleBuffer , pB->targetMemory[p].x-1 , pB->targetMemory[p].y-1 , pB->targetMemory[p+1].x-1 , pB->targetMemory[p+1].y-1 , makecol( 255 , 200 , 200 ) );
}
G_WriteToDebugWindow( pB->ent.onscreenTargetID , "%d" , pB->ent.position.x , pB->ent.position.y );
G_WriteToDebugWindow( pB->ent.virtualPointerLink , "%d" , pB->ent.position.x + (pB->ent.w>>1) , pB->ent.position.y + ( pB->ent.h>>1) );
G_WriteToDebugWindow( pB->step , "%d" , pB->ent.position.x + pB->ent.w, pB->ent.position.y );
}