Skip to content
Permalink
Newer
Older
100644 1137 lines (992 sloc) 36 KB
May 6, 2018
1
#include <genesis.h>
Apr 29, 2018
2
#include "defs.h"
3
#include "gamelogic.h"
4
#include "menu.h"
5
#include "map.h"
6
#include "collision.h"
7
#include "sprite.h"
8
#include "resmap.h"
9
#include "map_editor.h"
10
#include "game.h"
11
#include "gameover.h"
12
#include "resources.h"
13
#include "mutator.h"
14
15
#define TANK_SPEED_1 1
16
#define TANK_SPEED_2 3
17
#define TANK_SPEED_3 0xaa
18
19
#define BULLET_SPEED_1 1
20
#define BULLET_SPEED_2 2
21
#define BULLET_DESTROY_DELAY 8
Apr 29, 2018
22
23
#define MAX_BONUS 8
Apr 29, 2018
24
#define ARMOR_STAFF_TIME 1024
25
26
#define START_LIVES 3
27
#define START_ENEMIES 20
28
#define BIRTH_TIME_ENEMY 56 // 64
29
#define BIRTH_TIME_PLAYER (37 + 32) // Birth + delay after destroy
30
#define LVL1_RESPAWN_TIME 187
31
#define LVL35_RESPAWN_TIME 51
Apr 29, 2018
32
33
#define VDP_setTile(plan, tile, x, y) (VDP_setTileMapXY(plan, tile, x, y))
34
35
void GLog_updateMove();
36
void GLog_updateBullets();
Apr 29, 2018
37
void GLog_updateControl(u8 gamer_idx, u16 joy, u16 speed);
38
void GLog_updateAI();
39
void GLog_initEnemy();
40
void GLog_shot(_tank *tank);
41
void GLog_initGamer(u8 pl);
42
void GLog_makeExplode(u16 type, s16 x, s16 y);
43
void updateGameMenu();
44
void drawStage();
45
void generateBonus(u8 bns);
46
void updateArmorStaff();
47
48
u8 enemy_num;
49
u16 birth_timer;
50
51
u8 gameover;
52
u8 victory;
53
54
const s8 speed_x[] = { 0, -1, 0, 1 };
55
const s8 speed_y[] = { -1, 0, 1, 0 };
Apr 29, 2018
56
57
//_bullet bullets[config.max_bullets];
58
//_explode explodes[config.max_bullets];
59
//_tank game_player[config.units_on_map];
60
61
_bullet bullets[28];
62
_explode explodes[28];
63
_tank game_player[14];
64
65
_tank enemy_types[4];
66
_bonus bonus;
67
68
const u16 enemy_pos_x[3] = {START_X_EN_A * 8, START_X_EN_B * 8, START_X_EN_C * 8,};
69
u8 speed_counter;
70
u16 victory_timer;
71
s16 old_enemy_num;
72
s16 old_lives1;
73
s16 old_lives2;
74
75
s16 freeze;
76
s16 freeze_players;
77
s16 armor_staff;
78
u16 current_birth_time;
79
u16 pause;
80
_scor scor;
81
82
_bullet* last_killed_bullet = NULL;
83
Apr 29, 2018
84
void GLog_updateMove() {
85
86
u16 i;
87
u16 speed;
88
for (i = 0; i < config.units_on_map; i++) {
89
if (!game_player[i].hitpoint)
90
continue;
Apr 29, 2018
91
if (game_player[i].birth) {
92
game_player[i].birth--;
93
continue;
94
}
95
96
if (game_player[i].god) {
97
game_player[i].god--;
98
}
99
if (game_player[i].ice) {
100
game_player[i].ice--;
Apr 29, 2018
102
103
speed = speed_counter & game_player[i].speed;
104
if (!game_player[i].speed && game_player[i].ice && i < 2) {
105
speed = speed_counter & TANK_SPEED_2; // TODO: if mods.pl_speed_dec
Apr 29, 2018
106
}
107
if (speed) {
108
if (moveAvailableInWalls(&game_player[i]) && moveAvailableInUnits(&game_player[i])) {
109
game_player[i].posx += speed_x[game_player[i].rotate];
110
game_player[i].posy += speed_y[game_player[i].rotate];
Apr 29, 2018
111
}
112
else {
Apr 29, 2018
113
game_player[i].collision++;
114
}
115
}
116
}
117
}
118
119
void GLog_updateBullets() {
Apr 29, 2018
120
121
u16 i;
122
_bullet *bull_buff;
123
124
for (i = 0; i < config.max_bullets; i++) {
125
bull_buff = &bullets[i];
126
127
if (bull_buff->destroy_timer > 0) {
128
bull_buff->destroy_timer--;
129
if (bull_buff->destroy_timer == 0) {
130
bull_buff->maker->bullets_count--;
131
if (bull_buff->maker->bullets_count < 0) {
132
bull_buff->maker->bullets_count = 0;
133
}
134
}
135
continue;
136
}
137
138
if (bull_buff->speed == 0) continue;
139
bull_buff->posx += speed_x[bull_buff->rotate] * (1 << bull_buff->speed); // -1 << 1 -- Undefined Behavior
140
bull_buff->posy += speed_y[bull_buff->rotate] * (1 << bull_buff->speed);
Apr 29, 2018
141
detectBulletToWallCollision(bull_buff);
142
if (bull_buff->speed == 0) continue;
Apr 29, 2018
143
detectBulletToUnitsCollision(bull_buff);
144
if (bull_buff->speed == 0) continue;
Apr 29, 2018
145
detectBulletToStaffCollision(bull_buff);
146
if (bull_buff->speed == 0) continue;
Apr 29, 2018
147
detectBulletToBulletCollision(bull_buff);
148
}
149
}
150
151
void GLog_updateAI() {
152
153
u8 max_enemies = config.max_enemies_on_map;
154
// if (mods.en_on_map_inc) max_enemies = config.max_enemies_on_map + 4;
Apr 29, 2018
155
156
if (config.game_mode == MODE_BC && menuGetSelectedItem() == ITEM_ONE_PLAYER) {
157
max_enemies -= 2;
Apr 29, 2018
158
}
159
160
u8 enemies_on_map = 0;
Apr 29, 2018
161
u16 i;
162
u16 rotate;
163
164
for (i = 2; i < config.units_on_map; i++) {
165
if (game_player[i].hitpoint)
166
enemies_on_map++;
Apr 29, 2018
167
}
168
169
if (enemies_on_map == 0 && enemy_num == 0) {
Apr 29, 2018
170
victory_timer++;
171
if (victory_timer > 256)
172
victory = TRUE;
Apr 29, 2018
173
return;
174
}
175
if (enemies_on_map < max_enemies && enemy_num && !birth_timer)
176
GLog_initEnemy();
Apr 29, 2018
177
178
if (birth_timer)
179
birth_timer--;
Apr 29, 2018
180
181
if (freeze_players) {
182
freeze_players--;
183
for (i = 0; i < 2; i++) {
184
game_player[i].freeze = 1;
185
}
186
}
187
188
for (i = 2; i < config.units_on_map; i++) {
189
if (game_player[i].freeze || freeze) {
190
if (game_player[i].freeze)
191
game_player[i].freeze--;
192
if (freeze && (i == 2))
193
freeze--;
Apr 29, 2018
194
game_player[i].speed = 0;
195
game_player[i].fire = 0;
196
continue;
197
}
198
else {
199
game_player[i].speed = enemy_types[game_player[i].tank_type].speed;
200
if (mods.en_speed && game_player[i].speed == TANK_SPEED_1) {
201
game_player[i].speed = TANK_SPEED_2;
202
}
Apr 29, 2018
203
}
204
205
if (game_player[i].collision == 1)
206
game_player[i].fire_timer >>= 1;
Apr 29, 2018
207
if (game_player[i].collision > 5 || random() < 300 || (game_player[i].collision && random() < 2000)) {
208
game_player[i].collision = 0;
209
rotate = 1 << (random() & 3);
210
GLog_updateControl(i, rotate, game_player[i].speed);
211
}
212
if (game_player[i].fire_timer) {
213
game_player[i].fire_timer--;
214
} else {
215
game_player[i].fire = 1;
216
game_player[i].fire_timer = (64 - BULLET_DESTROY_DELAY) + (random() & 63);
Apr 29, 2018
217
}
218
}
219
}
220
221
void GLog_updateBonus() {
222
if (mods.en_invul) {
223
if (getTimer(1, FALSE) > 1536000) { // 20 s * 76800
224
generateBonus(BONUS_GRENADE);
Apr 29, 2018
225
startTimer(1);
226
}
227
}
228
if (bonus.type) {
229
if (game_player[0].hitpoint) {
230
if (detectBonusCollision(0)) {
231
setBonus(0);
232
}
Apr 29, 2018
233
}
234
if (game_player[1].hitpoint) {
235
if (detectBonusCollision(1)) {
236
setBonus(1);
237
}
Apr 29, 2018
238
}
239
240
if (config.en_bonus_collector) {
241
u16 i;
242
for (i = 2; i < config.units_on_map; i++) {
243
if (game_player[i].hitpoint) {
244
if (detectBonusCollision(i)) {
245
setBonus(i);
246
break;
247
}
Apr 29, 2018
248
}
249
}
Apr 29, 2018
251
}
252
}
253
254
void GLog_killBullet(_bullet *bull, u8 explode) {
255
256
u16 x = bull->posx;
Apr 30, 2018
257
u16 y = bull->posy;
258
u16 r = bull->rotate;
259
if (r & 1) {
Apr 29, 2018
260
x -= 8;
Apr 30, 2018
261
} else {
262
y -= 8;
Apr 29, 2018
263
}
264
265
bull->speed = 0;
266
if (explode)
267
GLog_makeExplode(EXPLODE_SMALL, x, y);
268
269
bull->destroy_timer = BULLET_DESTROY_DELAY;
270
271
last_killed_bullet = bull;
Apr 29, 2018
272
}
273
274
void GLog_killPlayer(_tank *victim, _tank *killer) {
Apr 29, 2018
275
276
if (victim->god) {
277
return;
278
}
279
if ((victim == &game_player[0] || victim == &game_player[1]) && (killer == &game_player[0] || killer == &game_player[1]) && (!mods.pvp_kills)) {
280
switch (config.pl_friend_fire) {
281
case BLOCK:
282
victim->freeze = 256;
283
soundPlay(snd_armor_hit, sizeof(snd_armor_hit), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
284
break;
285
case BULLETS_STOP:
286
soundPlay(snd_bull_stop, sizeof(snd_bull_stop), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
287
break;
288
}
289
}
290
else {
291
if (victim->bonus) {
292
generateBonus(0);
293
victim->bonus = 0;
294
}
295
if ((victim != &game_player[0] && victim != &game_player[1]) && (killer != &game_player[0] && killer != &game_player[1]) && (config.en_friend_fire != KILL)) {
296
switch (config.en_friend_fire) {
297
case BULLETS_STOP:
298
// startPlaySample(snd_bull_stop, sizeof(snd_bull_stop), 11000, AUDIO_PAN_CENTER, 6);
299
soundPlay(snd_bull_stop, sizeof(snd_bull_stop), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
300
break;
301
}
302
}
304
if (victim->ship == 1) {
305
victim->ship = 0;
306
s16 x1 = victim->posx >> 3;
307
s16 y1 = victim->posy >> 3;
308
s16 x2 = (victim->posx + 15) >> 3;
309
s16 y2 = (victim->posy + 15) >> 3;
310
// If you can't swim, then die
311
if (mapGetTile(x1, y1) == RES_TILE_RIVER
312
|| mapGetTile(x2, y1) == RES_TILE_RIVER
313
|| mapGetTile(x1, y2) == RES_TILE_RIVER
314
|| mapGetTile(x2, y2) == RES_TILE_RIVER) {
315
victim->hitpoint = 0;
317
}
318
else if ((!mods.pl_asskiller && !mods.en_invul) || (killer != &game_player[0] && killer != &game_player[1]) ) {
319
if (victim->hp == 1) {
Apr 29, 2018
320
victim->type = 0;
321
victim->hitpoint = 1;
322
//victim->speed = TANK_SPEED_1;
Apr 29, 2018
323
victim->bullet_limit = 1;
324
victim->bullet_speed = BULLET_SPEED_1;
325
victim->uranium_bullets = 0;
326
victim->hp = 0;
Apr 29, 2018
327
}
328
else {//if (victim->hp != 1) && victim->ship != 1)
Apr 29, 2018
329
victim->hitpoint--;
Apr 29, 2018
331
}
May 6, 2018
332
else { // if (killer == &game_player[0] || killer == &game_player[1]) {
333
if (mods.en_invul) {
May 6, 2018
334
victim->freeze = 256;
335
}
336
else { // if (mods.pl_asskiller) {
337
if (last_killed_bullet != NULL && last_killed_bullet->rotate == victim->rotate) {
May 6, 2018
338
victim->hitpoint--;
339
}
Apr 29, 2018
340
else {
341
victim->freeze = 256;
342
}
343
}
344
}
345
346
if (victim->hitpoint)
347
soundPlay(snd_armor_hit, sizeof(snd_armor_hit), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
349
}
350
if (!victim->hitpoint) {
351
if (victim != &game_player[0] && victim != &game_player[1]) {
352
s16 v_type = victim->type;
353
if (!mods.en_pl_skin) {
354
v_type -= 4;
355
}
356
if (killer == &game_player[0]) {
357
kills_1[v_type]++;
358
showScoreQuad(v_type, victim->posx, victim->posy);
359
} else if (killer == &game_player[1]) {
360
kills_2[v_type]++;
361
showScoreQuad(v_type, victim->posx, victim->posy);
362
}
Apr 29, 2018
363
}
364
365
GLog_makeExplode(EXPLODE_BIG, victim->posx, victim->posy);
366
367
if (victim == &game_player[0] || victim == &game_player[1]) {
368
// startPlaySample(snd_explode, sizeof(snd_explode), 11000, AUDIO_PAN_CENTER, 7);
369
soundPlay(snd_pl_explode, sizeof(snd_pl_explode), SOUND_PCM_CH3, FALSE);
370
} else {
371
soundPlay(snd_en_explode, sizeof(snd_en_explode), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
372
}
373
374
victim->lives--;
375
}
376
}
377
378
void GLog_shot(_tank *tank) {
379
380
u16 i;
381
_bullet *bull_buff;
382
383
if (tank->bullets_count >= tank->bullet_limit || !tank->hitpoint || tank->birth)
384
return;
Apr 29, 2018
385
386
for (i = 0; i < config.max_bullets; i++) {
387
bull_buff = &bullets[i];
388
if (bull_buff->speed || bull_buff->destroy_timer)
389
continue;
390
bull_buff->speed = tank->bullet_speed;
Apr 29, 2018
391
bull_buff->rotate = tank->rotate;
392
bull_buff->posx = tank->posx;
393
bull_buff->posy = tank->posy;
394
if (bull_buff->rotate & 1) {
395
bull_buff->posx += 8;
396
} else {
397
bull_buff->posy += 8;
398
}
Apr 29, 2018
399
bull_buff->ricocheted = FALSE;
400
if ((bull_buff->posx & 3) == 0 && (tank->rotate & 1)) bull_buff->posx += 1;
401
if ((bull_buff->posy & 3) == 0 && !(tank->rotate & 1)) bull_buff->posy += 1;
Apr 29, 2018
402
bull_buff->maker = tank;
403
tank->bullets_count++;
404
if (tank == &game_player[0] || tank == &game_player[1])
405
soundPlay(snd_shot, sizeof(snd_shot), SOUND_PCM_CH2, FALSE);
Apr 29, 2018
406
return;
407
}
408
}
409
410
void GLog_updateControl(u8 gamer_idx, u16 joy, u16 speed) {
411
412
u16 temp;
413
if (game_player[gamer_idx].birth || !game_player[gamer_idx].hitpoint)
414
return;
416
// Player only
417
if (config.turbo_b) {
418
if (joy & BUTTON_B) {
419
game_player[gamer_idx].fire = 1;
420
}
421
}
422
423
game_player[gamer_idx].speed = 0;
Apr 29, 2018
425
if (game_player[gamer_idx].freeze) {
426
game_player[gamer_idx].freeze--;
427
return;
428
}
429
430
431
if (joy & BUTTON_UP) {
432
game_player[gamer_idx].speed = speed;
433
game_player[gamer_idx].rotate = 0;
434
temp = game_player[gamer_idx].posx;
435
if (temp & 4)//(temp & 7) >= 4)
436
game_player[gamer_idx].posx = (temp >> 3 << 3) + 8;
437
else
438
game_player[gamer_idx].posx -= (temp & 7);
439
//if (game_player[gamer_idx].posx >> 3 > MAP_W - 2)
440
// game_player[gamer_idx].posx = (MAP_W - 2) << 3;
441
442
} else if (joy & BUTTON_LEFT) {
Apr 29, 2018
443
game_player[gamer_idx].speed = speed;
444
game_player[gamer_idx].rotate = 1;
445
temp = game_player[gamer_idx].posy;
446
if (temp & 4)//(temp & 7) >= 4)
447
game_player[gamer_idx].posy = (temp >> 3 << 3) + 8;
448
else
449
game_player[gamer_idx].posy -= (temp & 7);
450
//if (game_player[gamer_idx].posy >> 3 > MAP_H - 2)
451
// game_player[gamer_idx].posy = (MAP_H - 2) << 3;
452
} else if (joy & BUTTON_DOWN) {
Apr 29, 2018
453
game_player[gamer_idx].speed = speed;
454
game_player[gamer_idx].rotate = 2;
455
temp = game_player[gamer_idx].posx;
456
if (temp & 4)//(temp & 7) >= 4)
457
game_player[gamer_idx].posx = (temp >> 3 << 3) + 8;
458
else
459
game_player[gamer_idx].posx -= (temp & 7);
460
//if (game_player[gamer_idx].posx >> 3 > MAP_W - 2)
461
// game_player[gamer_idx].posx = (MAP_W - 2) << 3;
462
} else if (joy & BUTTON_RIGHT) {
Apr 29, 2018
463
game_player[gamer_idx].speed = speed;
464
game_player[gamer_idx].rotate = 3;
465
temp = game_player[gamer_idx].posy;
466
if (temp & 4)//(temp & 7) >= 4)
467
game_player[gamer_idx].posy = (temp >> 3 << 3) + 8;
468
else
469
game_player[gamer_idx].posy -= (temp & 7);
470
//if (game_player[gamer_idx].posy >> 3 > MAP_H - 2)
471
// game_player[gamer_idx].posy = (MAP_H - 2) << 3;
Apr 29, 2018
472
}
473
}
474
475
void GLog_updateGame() {
476
477
if (pause)
478
return;
Apr 29, 2018
479
u16 i;
480
speed_counter++;
481
speed_counter |= 128;
482
u16 joy1 = JOY_readJoypad(JOY_1);
483
u16 joy2 = JOY_readJoypad(JOY_2);
484
485
486
if (game_player[0].hitpoint == 0) {
487
GLog_initGamer(0);
488
}
489
if (game_player[1].hitpoint == 0) {
490
GLog_initGamer(1);
491
}
492
493
if (game_player[0].hitpoint == 0 && game_player[1].hitpoint == 0) {
494
gameover = TRUE;
Apr 29, 2018
495
}
496
497
for (i = 0; i < config.units_on_map; i++) {
498
if (game_player[i].fire) {
499
game_player[i].fire = 0;
500
GLog_shot(&game_player[i]);
501
}
502
}
503
504
505
if (gameover) {
506
GLog_updateControl(0, 0, 0);
507
GLog_updateControl(1, 0, 0);
508
} else {
509
if (mods.pl_speed_dec) {
510
GLog_updateControl(0, joy1, TANK_SPEED_1);
511
GLog_updateControl(1, joy2, TANK_SPEED_1);
512
}
513
else {
514
GLog_updateControl(0, joy1, TANK_SPEED_2);
515
GLog_updateControl(1, joy2, TANK_SPEED_2);
516
}
517
}
518
519
GLog_updateAI();
520
GLog_updateBullets();
Apr 29, 2018
521
GLog_updateMove();
522
GLog_updateBonus();
523
524
updateGameMenu();
525
updateArmorStaff();
526
}
527
528
void GLog_initGamer(u8 player_idx) {
529
530
if (!game_player[player_idx].lives)
531
return;
Apr 29, 2018
532
533
if (game_player[player_idx].hitpoint == 0) {
534
game_player[player_idx].bullet_limit = 1;
535
game_player[player_idx].bullet_speed = BULLET_SPEED_1;
536
game_player[player_idx].uranium_bullets = 0;
537
game_player[player_idx].type = 0;
538
game_player[player_idx].ship = 0;
539
game_player[player_idx].woods_trim = 0;
Apr 29, 2018
540
}
541
freeze_players = 0;
542
game_player[player_idx].hitpoint = 1;
543
game_player[player_idx].god = 2 * 64; // 2 s
Apr 29, 2018
544
if (mods.pl_shieldless) game_player[player_idx].god = 0;
545
game_player[player_idx].rotate = 0;
546
547
game_player[player_idx].speed = 0;
548
game_player[player_idx].birth = BIRTH_TIME_PLAYER;
Apr 29, 2018
549
game_player[player_idx].bullets_count = 0;
550
game_player[player_idx].freeze = 0;
551
game_player[player_idx].hp = 0;
552
game_player[player_idx].bonus = 0;
553
554
game_player[player_idx].ice = 0;
555
game_player[player_idx].on_ice = FALSE;
556
Apr 29, 2018
557
if (player_idx == 0) {
558
game_player[player_idx].color = TANK_COLOR_YELLOW;
559
game_player[player_idx].posx = START_X_PL_A << 3;
560
game_player[player_idx].posy = START_Y_PL_A << 3;
561
game_player[player_idx].player = 1;
562
} else {
563
game_player[player_idx].color = TANK_COLOR_GREEN;
564
game_player[player_idx].posx = START_X_PL_B << 3;
565
game_player[player_idx].posy = START_Y_PL_B << 3;
566
game_player[player_idx].player = 2;
567
}
568
569
if (mods.pl_en_tank && game_player[player_idx].type < 4) {
570
game_player[player_idx].type += 4;
571
// Reset upgrades
572
game_player[player_idx].bullet_speed = BULLET_SPEED_1;
573
game_player[player_idx].bullet_limit = 1;
574
game_player[player_idx].uranium_bullets = 0;
575
// Set enemy's upgrades
576
if (game_player[player_idx].type == 6) {
577
game_player[player_idx].bullet_limit = 2;
578
game_player[player_idx].bullet_speed = BULLET_SPEED_2;
579
}
580
else if (game_player[player_idx].type == 7) {
581
game_player[player_idx].hitpoint = 4;
582
}
583
}
584
else if (!mods.pl_en_tank && game_player[player_idx].type >= 4) {
585
game_player[player_idx].type -= 4;
586
// Reset upgrades
587
game_player[player_idx].bullet_speed = BULLET_SPEED_1;
588
game_player[player_idx].bullet_limit = 1;
589
game_player[player_idx].uranium_bullets = 0;
590
// Set player's upgrades
591
if (game_player[player_idx].type >= 1) {
592
game_player[player_idx].bullet_speed = BULLET_SPEED_2;
593
}
594
if (game_player[player_idx].type >= 2) {
595
game_player[player_idx].bullet_limit = 2;
596
}
597
if (game_player[player_idx].type == 3) {
598
game_player[player_idx].uranium_bullets = 1;
599
}
600
}
Apr 29, 2018
601
victory_timer = 0;
602
}
603
604
void GLog_makeExplode(u16 type, s16 x, s16 y) {
605
606
u16 i = config.max_explode;
607
608
while (i--) {
609
if (explodes[i].type)
610
continue;
Apr 29, 2018
611
explodes[i].posx = x;
612
explodes[i].posy = y;
613
explodes[i].strobe = 0;
614
explodes[i].type = type;
615
explodes[i].ani_counter = 0;
616
return;
617
}
618
}
619
620
621
void GLog_initGameLogic() {
622
623
u16 i;
624
pause = FALSE;
Apr 29, 2018
625
speed_counter = 128;
626
gameover = FALSE;
Apr 29, 2018
627
628
enemy_types[0].type = 4;
629
enemy_types[0].hitpoint = 1;
630
enemy_types[0].speed = TANK_SPEED_1;
631
enemy_types[0].bullet_limit = 1;
632
enemy_types[0].bullet_speed = BULLET_SPEED_1;
633
634
enemy_types[1].type = 5;
635
enemy_types[1].hitpoint = 1;
636
enemy_types[1].speed = TANK_SPEED_3;
637
enemy_types[1].bullet_limit = 1;
638
enemy_types[1].bullet_speed = BULLET_SPEED_1;
639
640
enemy_types[2].type = 6;
641
enemy_types[2].hitpoint = 1;
642
enemy_types[2].speed = TANK_SPEED_1;
643
enemy_types[2].bullet_limit = 2;
644
enemy_types[2].bullet_speed = BULLET_SPEED_2;
645
646
enemy_types[3].type = 7;
647
enemy_types[3].hitpoint = 4;
648
enemy_types[3].speed = TANK_SPEED_1;
649
enemy_types[3].bullet_limit = 1;
650
enemy_types[3].bullet_speed = BULLET_SPEED_1;
651
652
653
for (i = 0; i < config.units_on_map; i++) {
654
game_player[i].scor = 0;
655
game_player[i].lives = 0;
656
game_player[i].hitpoint = 0;
657
game_player[i].uranium_bullets = 0;
658
}
659
660
game_player[0].lives = config.start_lives;
661
if (menuGetSelectedItem() == ITEM_TWO_PLAYER) {
662
game_player[1].lives = config.start_lives;
663
}
664
}
665
666
void GLog_initEnemy() {
667
668
u16 i;
669
_tank *buff = NULL;
Apr 29, 2018
670
u8 tank_type = 2;
671
672
if (selected_stage == 0) {
673
tank_type = 0;
674
} else if (selected_stage == 1) {
Apr 29, 2018
675
tank_type = random() % 3;
676
} else if (selected_stage == 2) {
Apr 29, 2018
677
tank_type = random() % 4;
678
} else if (selected_stage < 10) {
Apr 29, 2018
679
tank_type = random() % 4;
680
if (tank_type == 0)tank_type = random() % 4;
681
} else if (selected_stage < 20) {
Apr 29, 2018
682
tank_type = random() % 4;
683
if (tank_type == 0 || tank_type == 1)
684
tank_type = random() % 4;
685
if (tank_type == 0 || tank_type == 1)
686
tank_type = random() % 4;
Apr 29, 2018
687
} else {
688
tank_type = 1 + random() % 3;
689
if (tank_type != 2)
690
tank_type = 1 + random() % 3;
Apr 29, 2018
691
}
692
693
//tank_type = enemy_num & 3;
694
for (i = 2; i < config.units_on_map; i++) {
695
buff = &game_player[i];
696
if (buff->hitpoint == 0) {
697
break;
Apr 29, 2018
698
}
699
}
700
if (i == config.units_on_map)
701
return;
Apr 29, 2018
702
703
enemy_num--;
704
buff->bullet_limit = enemy_types[tank_type].bullet_limit;
705
buff->bullet_speed = enemy_types[tank_type].bullet_speed;
706
buff->hitpoint = enemy_types[tank_type].hitpoint;
707
708
buff->speed = enemy_types[tank_type].speed;
709
710
buff->type = enemy_types[tank_type].type;
711
buff->tank_type = tank_type;
712
713
if (mods.en_pl_skin) buff->type = 0;
714
715
buff->posy = 0;
716
buff->posx = enemy_pos_x[enemy_num % 3];
717
buff->rotate = 2;
Apr 29, 2018
718
buff->bullets_count = 0;
719
buff->birth = BIRTH_TIME_ENEMY;
Apr 29, 2018
720
buff->color = TANK_COLOR_GREY;
721
buff->bonus = (enemy_num & 3) ? 0 : 1;
722
723
if (mods.no_bonuses) buff->bonus = 0;
724
725
birth_timer = current_birth_time;
726
727
buff->uranium_bullets = 0;
728
buff->woods_trim = 0;
Apr 29, 2018
729
buff->god = 0;
730
buff->player = 0;
731
732
//if (mods.en_speed) buff->speed = TANK_SPEED_3;
Apr 29, 2018
733
if (mods.en_armor) buff->hitpoint = 4;
734
if (mods.en_uranium) buff->uranium_bullets = 1;
735
if (mods.en_bull_speed) buff->bullet_speed = BULLET_SPEED_2;
736
if (mods.en_shielded) buff->god = 256;
737
}
738
May 6, 2018
739
void GLog_initLevel(u16 level) {
Apr 29, 2018
740
741
u16 i = 0;
742
s16 t = level;
743
if (t > MAP_AVAILABLE - 1) {
744
t = MAP_AVAILABLE - 1;
745
}
746
current_birth_time = LVL1_RESPAWN_TIME + (LVL35_RESPAWN_TIME - LVL1_RESPAWN_TIME) * t / (MAP_AVAILABLE-1);
Apr 29, 2018
747
if (mods.en_spawn_speed) {
748
current_birth_time = LVL35_RESPAWN_TIME;
Apr 29, 2018
749
}
750
birth_timer = 0;
751
victory = FALSE;
752
enemy_num = START_ENEMIES;
753
if (mods.en_doubles)
754
enemy_num = START_ENEMIES*2;
Apr 29, 2018
755
for (i = 0; i < config.units_on_map; i++) {
756
game_player[i].bullets_count = 0;
757
game_player[i].freeze = 0;
758
game_player[i].fire = 0;
759
}
760
GLog_initGamer(0);
761
GLog_initGamer(1);
762
763
if (map_editor_map_ready) {
764
setMap(PLAN_B, editor_map, MAP_GAMEMODE_UNCOMPRESSED);
765
map_editor_map_ready = FALSE;
766
} else {
767
setMapLevel(level);
Apr 29, 2018
768
}
769
770
771
old_enemy_num = -1;
772
old_lives1 = -1;
773
old_lives2 = -1;
774
armor_staff = 0;
775
drawStage();
776
bonus.type = 0;
777
scor.timer = 0;
Apr 29, 2018
778
freeze = 0;
779
VDP_setPalette(0, pal_red);
780
VDP_setPalette(1, pal_yellow);
781
VDP_setPalette(2, pal_green);
782
VDP_setPalette(3, pal_grey);
783
}
784
785
u8 GLog_gameover() {
786
return gameover;
787
}
788
789
u8 GLog_victory() {
790
return victory;
791
}
792
793
void GLog_setVictory() {
794
GLog_removeEnemy();
795
victory = TRUE;
Apr 29, 2018
796
}
797
798
u8 GLog_victoryTimer() {
799
return victory_timer;
800
}
801
Apr 29, 2018
802
void GLog_removeEnemy() {
803
u16 i;
804
enemy_num = 0;
805
806
for (i = 2; i < config.units_on_map; i++) {
807
game_player[i].hitpoint = 0;
808
game_player[i].posx = -30;
809
}
810
}
811
812
void GLog_killStaff() {
813
814
GLog_makeExplode(EXPLODE_BIG, START_X_ST << 3, START_Y_ST << 3);
815
mapSetTile(RES_TILE_DEATH_STAFF + 0, START_X_ST + 0, START_Y_ST + 0);
816
mapSetTile(RES_TILE_DEATH_STAFF + 1, START_X_ST + 0, START_Y_ST + 1);
817
mapSetTile(RES_TILE_DEATH_STAFF + 2, START_X_ST + 1, START_Y_ST + 0);
818
mapSetTile(RES_TILE_DEATH_STAFF + 3, START_X_ST + 1, START_Y_ST + 1);
819
gameover = TRUE;
820
//startPlaySample(snd_explode, sizeof(snd_explode), 11000, AUDIO_PAN_CENTER, 8);
821
soundPlay(snd_pl_explode, sizeof(snd_pl_explode), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
822
}
823
824
void updateGameMenu() {
825
826
u16 i;
827
u16 x = MAP_X + MAP_W + 1;
828
u16 y = MAP_Y + 1;
829
u16 tile = 0;
830
u16 lives;
831
832
if (enemy_num != old_enemy_num) {
833
for (i = 0; i < START_ENEMIES; i++) {
Apr 29, 2018
834
tile = i < enemy_num ? RES_TILE_TANK_ICON_BLACK : RES_TILE_GREY;
835
VDP_setTile(PLAN_B, tile, x + (i & 1), y + (i >> 1));
Apr 29, 2018
836
}
837
old_enemy_num = enemy_num;
838
}
839
840
y = 16;
Apr 29, 2018
841
lives = game_player[0].lives;
842
if (old_lives1 != lives) {
843
if (lives > 10) lives = 10;
844
else if (lives < 1) lives = 1;
Apr 29, 2018
845
if (old_lives1 == -1) {
846
VDP_setTile(PLAN_B, RES_TILE_P1, x, y);
847
VDP_setTile(PLAN_B, RES_TILE_P, x + 1, y);
848
VDP_setTile(PLAN_B, RES_TILE_TANK_ICON_OGANGE, x, y + 1);
Apr 29, 2018
849
}
850
VDP_setTile(PLAN_B, RES_TILE_STAGE_NUM + lives - 1, x + 1, y + 1);
Apr 29, 2018
851
old_lives1 = lives;
852
}
853
854
y = 19;
Apr 29, 2018
855
lives = game_player[1].lives;
856
if (old_lives2 != lives && menuGetSelectedItem() == ITEM_TWO_PLAYER) {
857
if (lives > 10) lives = 10;
858
else if (lives < 1) lives = 1;
Apr 29, 2018
859
if (old_lives2 == -1) {
860
VDP_setTile(PLAN_B, RES_TILE_P2, x, y);
861
VDP_setTile(PLAN_B, RES_TILE_P, x + 1, y);
862
VDP_setTile(PLAN_B, RES_TILE_TANK_ICON_OGANGE, x, y + 1);
Apr 29, 2018
863
}
864
VDP_setTile(PLAN_B, RES_TILE_STAGE_NUM + lives - 1, x + 1, y + 1);
Apr 29, 2018
865
old_lives2 = lives;
866
}
867
}
868
869
void drawStage() {
870
871
u16 num;
872
u16 x = MAP_X + MAP_W + 1;
873
u16 y = MAP_Y + 21;
May 8, 2018
874
VDP_setTile(PLAN_B, RES_TILE_FLAG, x, y);
875
VDP_setTile(PLAN_B, RES_TILE_FLAG+1, x, y + 1);
876
VDP_setTile(PLAN_B, RES_TILE_FLAG+2, x + 1, y);
877
VDP_setTile(PLAN_B, RES_TILE_FLAG+3, x + 1, y + 1);
Apr 29, 2018
878
879
num = (selected_stage + 1) / 10;
880
if (num != 0)
881
VDP_setTile(PLAN_B, RES_TILE_STAGE_NUM + num, x, y + 2);
Apr 29, 2018
882
num = (selected_stage + 1) % 10;
883
VDP_setTile(PLAN_B, RES_TILE_STAGE_NUM + num, x + 1, y + 2);
Apr 29, 2018
884
}
885
886
void generateBonus(u8 bns) {
887
888
bonus.posx = random() % (MAP_W - 4) << 3;
889
bonus.posy = random() % (MAP_H - 5) << 3;
890
891
soundPlay(snd_bonus_appears, sizeof(snd_bonus_appears), SOUND_PCM_CH1, FALSE);
Apr 29, 2018
892
893
if (bns) {
894
bonus.type = bns;
895
}
896
else {
897
bonus.type = (random() % MAX_BONUS);
898
// + 2 bonus
899
switch (config.addition_bonus) {
900
case OFF:
901
bonus.type %= 6;
902
break;
903
case GUN_BONUS:
904
bonus.type %= 7;
905
break;
906
case SHIP_BONUS:
907
bonus.type %= 7;
908
break;
909
case BOTH_BONUS:
910
bonus.type %= 8;
911
break;
912
}
913
914
bonus.type++;
915
916
switch (bonus.type) {
917
case 1:
918
bonus.type = 4;
919
break;
920
case 2:
921
bonus.type = 5;
922
break;
923
case 5:
924
bonus.type = 2;
925
break;
926
case 4:
927
bonus.type = 1;
928
break;
929
case 7:
930
if (config.addition_bonus == SHIP_BONUS)
931
bonus.type = 8;
Apr 29, 2018
932
break;
933
}
934
}
935
}
936
937
void setBonus(u8 player) {
938
939
u16 i;
940
switch (bonus.type) {
941
case BONUS_HELMET:
942
game_player[player].god = 10 * 64; // 10 s
Apr 29, 2018
943
break;
944
case BONUS_CLOCK:
945
if (player == 0 || player == 1)
946
freeze = 10 * 64; // 10 s
948
freeze_players = 10 * 64; // 10 s
Apr 29, 2018
949
break;
950
case BONUS_SCOOP:
951
if (player == 0 || player == 1)
952
armor_staff = ARMOR_STAFF_TIME;
953
else
954
armor_staff = ARMOR_STAFF_TIME + 1;
Apr 29, 2018
955
break;
956
case BONUS_STAR:
957
if ((player < 2 && !mods.pl_en_tank) || (player >= 2 && mods.en_pl_skin)) {
958
game_player[player].type++;
959
if (game_player[player].type > 3) {
960
game_player[player].type = 3;
961
}
962
else if (game_player[player].type == 1) {
963
game_player[player].bullet_speed = BULLET_SPEED_2;
964
}
965
else if (game_player[player].type == 2) {
966
game_player[player].bullet_limit = 2;
967
}
968
else if (game_player[player].type == 3) {
969
game_player[player].uranium_bullets = 1;
970
}
Apr 29, 2018
971
}
972
else {//if ((player >= 2 && !mods.en_pl_skin) || (player < 2 && mods.pl_en_tank)) {
973
game_player[player].type++;
974
if (game_player[player].type > 7) {
975
game_player[player].type = 7;
976
977
game_player[player].hitpoint += 2;
978
//if (game_player[player].speed == TANK_SPEED_1)
979
// game_player[player].speed = TANK_SPEED_2;
980
//else if (game_player[player].speed == TANK_SPEED_2)
981
// game_player[player].speed = TANK_SPEED_3;
982
if (game_player[player].bullet_limit == 1)
983
game_player[player].bullet_limit = 2;
984
if (game_player[player].bullet_speed == BULLET_SPEED_1)
985
game_player[player].bullet_speed = BULLET_SPEED_2;
986
}
987
else if (game_player[player].type == 5) {
988
game_player[player].hitpoint = 1;
989
//game_player[player].speed = TANK_SPEED_3;
990
game_player[player].bullet_limit = 1;
991
game_player[player].bullet_speed = BULLET_SPEED_1;
992
}
993
else if (game_player[player].type == 6) {
994
game_player[player].hitpoint = 1;
995
//game_player[player].speed = TANK_SPEED_1;
996
game_player[player].bullet_limit = 2;
997
game_player[player].bullet_speed = BULLET_SPEED_2;
998
}
999
else if (game_player[player].type == 7) {
Apr 29, 2018
1000
game_player[player].hitpoint = 4;
1001
//game_player[player].speed = TANK_SPEED_1;
Apr 29, 2018
1002
game_player[player].bullet_limit = 1;
1003
game_player[player].bullet_speed = BULLET_SPEED_1;
1005
game_player[player].tank_type = game_player[player].type - 4;
Apr 29, 2018
1007
break;
1008
case BONUS_GRENADE:
1009
if (player == 0 || player == 1) {
1010
for (i = 2; i < config.units_on_map; i++) {
1011
if (game_player[i].hitpoint) {
1012
GLog_makeExplode(EXPLODE_BIG, game_player[i].posx, game_player[i].posy);
1013
game_player[i].hitpoint = 0;
1014
//startPlaySample(snd_enemy_explode, sizeof(snd_enemy_explode), 11000, AUDIO_PAN_CENTER, 10);
1015
soundPlay(snd_en_explode, sizeof(snd_en_explode), SOUND_PCM_CH3, FALSE);
1016
}
Apr 29, 2018
1017
}
1018
}
1019
else {
1020
for (i = 0; i < 2; i++) {
Apr 29, 2018
1021
if (game_player[i].hitpoint) {
1022
GLog_makeExplode(EXPLODE_BIG, game_player[i].posx, game_player[i].posy);
1023
game_player[i].hitpoint = 0;
1024
game_player[player].lives--;
1025
//startPlaySample(snd_explode, sizeof(snd_explode), 11000, AUDIO_PAN_CENTER, 10);
1026
soundPlay(snd_pl_explode, sizeof(snd_pl_explode), SOUND_PCM_CH3, FALSE);
Apr 29, 2018
1027
}
1028
}
Apr 29, 2018
1030
break;
1031
case BONUS_TANK:
1032
if (player == 0 || player == 1) {
Apr 29, 2018
1033
game_player[player].lives++;
1034
soundPlay(snd_live_got, sizeof(snd_live_got), SOUND_PCM_CH1, FALSE);
1035
}
1036
else {
1037
enemy_num += 3;
May 6, 2018
1038
soundPlay(snd_bonus_got, sizeof(snd_bonus_got), SOUND_PCM_CH1, FALSE);
Apr 29, 2018
1039
}
1040
break;
1041
case BONUS_GUN:
1042
if ((player < 2 && !mods.pl_en_tank) || (player >= 2 && mods.en_pl_skin)) {
1043
game_player[player].type = 3;
1044
game_player[player].bullet_limit = 2;
1045
game_player[player].bullet_speed = BULLET_SPEED_2;
Apr 29, 2018
1046
game_player[player].uranium_bullets = 1;
1047
game_player[player].woods_trim = 1;
1048
1049
if (player < 2)
1050
game_player[player].hp = 1;
1051
}
1052
else {
1053
game_player[player].type = 7;
1054
game_player[player].bullet_limit = 2;
1055
game_player[player].bullet_speed = BULLET_SPEED_2;
1056
game_player[player].uranium_bullets = 1;
1057
game_player[player].woods_trim = 1;
1058
1059
game_player[player].hitpoint = 4;
1060
//game_player[player].speed = TANK_SPEED_2;
1061
if (player >= 2)
1062
game_player[player].tank_type = game_player[player].type - 4;
1063
}
1064
break;
1065
case BONUS_SHIP:
1066
game_player[player].ship = 1;
Apr 29, 2018
1067
break;
1068
}
1069
//startPlaySample(snd_bonus_take, sizeof(snd_bonus_take), 10000, AUDIO_PAN_CENTER, 9);
1070
if (bonus.type != BONUS_TANK) {
1071
soundPlay(snd_bonus_got, sizeof(snd_bonus_got), SOUND_PCM_CH1, FALSE);
Apr 29, 2018
1072
}
1073
showScoreQuad(4, bonus.posx, bonus.posy);
1074
bonus.type = 0;
May 6, 2018
1075
1076
if (player == 0) {
1077
kills_1[4]++;
1078
} else if (player == 1) {
1079
kills_2[4]++;
1080
}
Apr 29, 2018
1081
}
1082
1083
void updateArmorStaff() {
1084
1085
if (!armor_staff)
1086
return;
Apr 29, 2018
1087
1088
if (armor_staff == ARMOR_STAFF_TIME + 1) {
Apr 29, 2018
1089
armor_staff = 0;
1090
mapSetTile(0, START_X_ST-1, START_Y_ST+1);
1091
mapSetTile(0, START_X_ST-1, START_Y_ST+0);
1092
mapSetTile(0, START_X_ST-1, START_Y_ST-1);
1093
mapSetTile(0, START_X_ST+0, START_Y_ST-1);
1094
mapSetTile(0, START_X_ST+1, START_Y_ST-1);
1095
mapSetTile(0, START_X_ST+2, START_Y_ST-1);
1096
mapSetTile(0, START_X_ST+2, START_Y_ST+0);
1097
mapSetTile(0, START_X_ST+2, START_Y_ST+1);
1098
return;
1099
}
Apr 29, 2018
1100
1101
armor_staff--;
1102
if (armor_staff == ARMOR_STAFF_TIME - 1 || armor_staff < 256) {
1103
u8 armor_tile = RES_TILE_STEEL;
1104
if ((armor_staff & 31) > 16 && armor_staff < ARMOR_STAFF_TIME - 20)
1105
armor_tile = RES_TILE_BRICK;
1106
if (!armor_staff)
1107
armor_tile = RES_TILE_BRICK;
Apr 29, 2018
1108
1109
mapSetTile(armor_tile, START_X_ST-1, START_Y_ST+1);
1110
mapSetTile(armor_tile, START_X_ST-1, START_Y_ST+0);
1111
mapSetTile(armor_tile, START_X_ST-1, START_Y_ST-1);
1112
mapSetTile(armor_tile, START_X_ST+0, START_Y_ST-1);
1113
mapSetTile(armor_tile, START_X_ST+1, START_Y_ST-1);
1114
mapSetTile(armor_tile, START_X_ST+2, START_Y_ST-1);
1115
mapSetTile(armor_tile, START_X_ST+2, START_Y_ST+0);
1116
mapSetTile(armor_tile, START_X_ST+2, START_Y_ST+1);
Apr 29, 2018
1117
}
1118
}
1119
1120
void showScoreQuad(u16 val, u16 posx, u16 posy) {
1121
1122
scor.timer = 40;
1123
scor.val = val;
Apr 29, 2018
1124
scor.posx = posx;
1125
scor.posy = posy;
1126
}
1127
1128
void soundPlay(const u8 *sample, const u32 len, const u16 channel, const u8 loop) {
1129
if (getTimer(0, FALSE) > 330000) {
1130
SND_startPlay_4PCM(sample, len, channel, loop);
1131
}
1132
1133
if ((sample == snd_bonus_appears) || (sample == snd_bonus_got) || (sample == snd_live_got)) {
1134
soundStopEngine();
1135
}
1136
}
1137