This repository was archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathBoss.cpp
344 lines (294 loc) · 7.07 KB
/
Boss.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
#define DEBUG_ME
#include "Enemy.h"
#include "Evade2.h"
#include "img/boss_1_img.h"
#include "img/boss_2_img.h"
#include "img/boss_3_img.h"
static const FXP_WORLD_COORD z_dist = 256;
uint16_t Boss::hit_points = 0;
UBYTE Boss::boss_type;
static BOOL hit(Object *o) {
if (o->flags & OFLAG_COLLISION) {
Boss::hit_points--;
o->flags &= ~OFLAG_COLLISION;
return TRUE;
}
return FALSE;
}
const BYTE *getBossLines() {
switch (Boss::boss_type) {
case 3:
return boss_3_img;
break;
case 2:
return boss_2_img;
break;
default:
return boss_1_img;
}
}
#if 0
// Shoot from a specific X/Y space within the Boss's space.
static void fire_one(FLOAT x, FLOAT y, FLOAT z) {
Object *o = ObjectManager::alloc();
if (!o) {
return;
}
o->set_type(OTYPE_ENEMY_BULLET);
o->x = x;
o->y = y;
o->z = z;
o->vx = ((Camera::x + 15 - random(0, 30)) - x) / frames;
o->vy = ((Camera::y + 15 - random(0, 30)) - y) / frames;
o->state = 384; // timeout
o->lines = EBullet::bomb_img();
o->vz = Camera::vz - (z - Camera::z) / 20;
}
#endif
/**
Ideas:
instead of randomizing vx, vy, you can set y to sin(theta)*64 or something like that (edited)
[18:43] and change theta over time
[18:43] it'll make it a sinusoidal pattern
*/
static void engage_player_random_xy(Object *o) {
o->z = Camera::z + z_dist - 10;
// Debugging stuff
// Font::scale = .7 * 256;
// Font::printf(5, 5, "%f", o->x - Camera::x);
// Font::printf(5, 15, "%f", o->y - Camera::y);
if (o->state == 1) {
o->theta += FXP_RADIANS(5 + Game::difficulty);
}
else {
o->theta -= FXP_RADIANS(5 + Game::difficulty);
}
// Debug
// o->x = Camera::x;
// o->y = Camera::y;
if (--o->timer > 0) {
return;
}
EBullet::fire(o, EBULLET_BOMB);
o->timer = Game::wave > 20 ? 10 : (40 - Game::difficulty);
// Keep within bounds of the screen
if (o->x - Camera::x < -300) {
o->vx = random(3, 10 + Game::difficulty);
}
else if (o->x - Camera::x > 300) {
o->vx = random(-3, -10 + Game::difficulty * -1);
}
else {
o->vx = random(-10 + (Game::difficulty * -1), 10 + Game::difficulty);
}
if (o->y - Camera::y < -300) {
o->vy = random(3, 10 + Game::difficulty);
}
else if (o->y - Camera::y > 300) {
o->vy = random(-3, -10 + Game::difficulty * -1);
}
else {
o->vy = random(-10 + (Game::difficulty * -1), 10 + Game::difficulty);
}
}
static void randomize_flee(Object *o) {
o->y = Camera::y + random(-150, 150);
o->vy = random(-7, 7);
o->vx = random(-7, 7);
o->z = Camera::z - 50;
o->vz = Camera::vz + (random(1, 7) * Game::difficulty);
o->theta = FXP_RADIANS(180) - FXP_RADIANS(random(0, 360));
}
static void engage_player_flee(Object *o) {
if (o->flags & ORBIT_LEFT) {
o->state -= Game::difficulty;
if (o->state < 0) {
o->state = 0;
randomize_flee(o);
o->flags &= ~ORBIT_LEFT;
}
}
else {
o->state += Game::difficulty;
if (o->state > 90) {
o->state = 90;
randomize_flee(o);
o->flags |= ORBIT_LEFT;
}
}
if (--o->timer > 0) {
return;
}
EBullet::fire(o, EBULLET_BOMB);
o->timer = Game::wave > 20 ? 20 : (50 - Game::difficulty);
// o->x = Camera::x;
// o->y = Camera::y;
o->vx += random(-7, 7);
o->vy += random(-7, 7);
}
// Copy of init_assault
static void init_orbit(Object *o, BOOL left) {
float angle = left ? 0 : (2 * PI);
o->x = cos(angle) * 256;
o->z = Camera::z + sin(angle) * 256;
o->y = Camera::y + random(30, 90);
o->vy = random(-6 + (Game::difficulty * -1), 6 + (Game::difficulty));
o->vx = 0;
o->vz = -50 - (Game::difficulty * 2);
o->state = left ? 0 : 180;
}
static void engage_player_orbit(Object *o) {
if (o->flags & ORBIT_LEFT) {
o->state -= Game::difficulty;
if (o->state < 0) {
o->y = Camera::y + random(-150, 150);
// o->vy = random(-7,7);
o->state = 0;
o->flags &= ~ORBIT_LEFT;
}
else {
o->theta -= FXP_RADIANS(12);
}
}
else {
o->state += Game::difficulty;
if (o->state > 180) {
o->y = Camera::y + random(-150, 150);
o->state = 180;
o->flags |= ORBIT_LEFT;
}
else {
o->theta += FXP_RADIANS(12);
}
}
float rad = RADIANS(o->state);
o->x = cos(rad) * 512;
o->z = Camera::z + sin(rad) * 512;
if (--o->timer <= 0) {
o->timer = Game::wave > 20 ? 20 : (50 - Game::difficulty);
EBullet::fire(o, EBULLET_BOMB);
}
}
/**
* Boss is exploding state.
*/
void Boss::explode(Process *me, Object *o) {
const WORD NUM_FRAMES = 58;
o->flags |= OFLAG_EXPLODE;
o->state++;
EBullet::genocide(); // Kill all enemy bullets
// Done exploding, move forward to the next wave
if (o->state > NUM_FRAMES) {
game_mode = MODE_NEXT_WAVE;
Game::kills = 65;
Camera::vz = CAMERA_VZ;
Sound::play_score(NEXT_WAVE_SONG);
ProcessManager::birth(Game::next_wave);
me->suicide();
}
else {
me->sleep(1, explode);
}
}
void Boss::action(Process *me, Object *o) {
if (hit(o)) {
if (Boss::hit_points <= 2) {
o->flags &= OFLAG_EXPLODE;
o->state = 0;
o->vz = Camera::vz - 3;
me->sleep(1, explode);
return;
}
o->lines = NULL;
if (Boss::boss_type == 1) {
// o->y = random(-5, 5);
o->state = (o->state == 1) ? 0 : 1;
}
// else if (Boss::boss_type == 2) {
// init_orbit(o, random() & 1);
// }
// else {
// randomize_flee(o);
// }
}
else {
o->lines = getBossLines();
if (Boss::boss_type == 1) {
engage_player_random_xy(o);
}
else if (Boss::boss_type == 2) {
engage_player_orbit(o);
}
else {
engage_player_flee(o);
}
}
me->sleep(1);
}
void Boss::start_action(Process *me, Object *o) {
if (Boss::boss_type == 2) {
if (--o->timer > 0) {
game_mode = MODE_GAME;
me->sleep(1, action);
}
else {
me->sleep(1);
}
}
else {
o->y = Camera::y;
o->z = Camera::z + z_dist;
if (Boss::boss_type == 1) {
if (o->x <= Camera::x) {
game_mode = MODE_GAME;
me->sleep(1, action);
}
else {
me->sleep(1);
}
}
else {
if (o->x > Camera::x) {
game_mode = MODE_GAME;
me->sleep(1, action);
}
else {
me->sleep(1);
}
}
}
}
void Boss::entry(Process *me, Object *o) {
// production
game_mode = MODE_NEXT_WAVE;
Game::kills = 0;
Camera::vz = -20;
o->set_type(OTYPE_ENEMY);
o->z = Camera::z + z_dist;
o->state = 0;
o->vz = Camera::vz;
if (Game::wave % 3 == 0) {
Boss::boss_type = 3;
o->x = Camera::x - 512;
o->vx = +10;
o->vy = random(-3, 3);
Sound::play_score(STAGE_3_BOSS_SONG);
}
else if (Game::wave % 2 == 0) {
Boss::boss_type = 2;
init_orbit(o, random() & 1);
Sound::play_score(STAGE_2_BOSS_SONG);
}
else {
Boss::boss_type = 1;
o->x = Camera::x + 512;
o->vx = -10;
o->y = Camera::y;
Sound::play_score(STAGE_1_BOSS_SONG);
}
o->lines = getBossLines();
// PRODUCTION
Boss::hit_points = 20 + (Game::difficulty * Boss::boss_type);
// Boss::hit_points = 1;
me->sleep(1, Boss::start_action);
}