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 pathGame.cpp
161 lines (139 loc) · 3.47 KB
/
Game.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
#include "Evade2.h"
UBYTE Game::wave;
UBYTE Game::difficulty;
UBYTE Game::kills;
const BYTE alert_top = 5;
const BYTE getStageSong() {
if (Game::wave % 5 == 0) {
return STAGE_5_SONG;
}
else if (Game::wave % 4 == 0) {
return STAGE_4_SONG;
}
else if (Game::wave % 3 == 0) {
return STAGE_3_SONG;
}
else if (Game::wave % 2 == 0) {
return STAGE_2_SONG;
}
return STAGE_1_SONG;
}
void Game::birth() {
EBullet::genocide();
Bullet::genocide();
ProcessManager::genocide();
ProcessManager::birth(Enemy::entry);
ProcessManager::birth(Enemy::entry);
ProcessManager::birth(Enemy::entry);
if (Game::wave > 3) {
const BYTE num_asteroids = min(max(Game::wave, 3), 1) + 1;
for (BYTE i = 0; i < num_asteroids; i++) {
ProcessManager::birth(Asteroid::entry);
}
}
}
void Game::next_wave(Process *me, Object *o) {
if (--Game::kills <= 0) {
game_mode = MODE_GAME;
Game::kills = 0;
Camera::vz = CAMERA_VZ;
Game::wave++; // <-- Use this with Kills
if (Game::wave % 4 == 0) {
Game::difficulty++;
}
Sound::play_score(getStageSong());
EBullet::genocide();
Bullet::genocide();
ProcessManager::genocide();
// birth enemies, etc.
Game::birth();
me->suicide();
}
else {
Font::scale = 200;
Font::printf(26, alert_top, "START WAVE %d", Game::wave + 1);
Font::scale = 256;
Player::recharge_shield();
Player::recharge_power();
me->sleep(1);
}
}
// Using game::kills as a timer
void Game::spawn_boss(Process *me, Object *o) {
if (--Game::kills <= 0) {
game_mode = MODE_GAME;
Camera::vz = CAMERA_VZ;
ProcessManager::genocide();
ProcessManager::birth(Boss::entry);
me->suicide();
}
else {
Font::scale = 190;
Font::printf(35, alert_top, "WARP TO ACE!");
Player::recharge_shield();
Player::recharge_power();
Font::scale = 256;
me->sleep(1);
}
}
// TOOD: Make subroutine to map out wave to kills
void Game::run() {
// if (Game::kills > 0) { // <<-- use this one to debug quickly
// Faster increase
// if (Game::kills > (4 * Game::wave) * Game::difficulty) {
// Slower increase
if (Game::kills > ((10 + Game::wave) * Game::difficulty)) {
game_mode = MODE_NEXT_WAVE;
// next wave
Game::kills = 120;
Camera::vz = 30;
Bullet::genocide();
ProcessManager::birth(spawn_boss);
Sound::play_score(GET_READY_SONG);
}
}
struct game_data {
FXP_ANGLE theta;
WORD timer;
};
// Game process uses an Object that isn't displayed!
// The object structure provides some variable space we
// can use, saving precious global variable space.
void Game::start_game(Process *me) {
// end wave after 180 seconds (3 minutes)
Game::difficulty = 1;
Game::kills = 0;
Game::wave = 1;
game_mode = MODE_GAME;
Sound::stfu();
Sound::play_score(getStageSong());
Player::init();
Game::birth();
me->suicide();
}
/**
* Display "Get Ready" for o->state frames
*/
void Game::get_ready(Process *me, Object *o) {
game_data *d = (game_data *)&o->x;
#ifdef ENABLE_ROTATING_TEXT
Font::print_string_rotatedx(30, 35, d->theta, F("GET READY!"));
d->theta += FXP_RADIANS(12);
#else
Font::printf(30, 35, "GET READY!");
#endif
BYTE timer = d->timer;
if (timer <= 1) {
Game::start_game(me);
return;
}
d->timer--;
me->sleep(1);
}
void Game::entry(Process *me, Object *o) {
game_data *d = (game_data *)&o->x;
d->timer = 65;
d->theta = FXP_RADIANS(90);
Sound::play_score(NEXT_WAVE_SONG);
me->sleep(1, get_ready);
}