aboutsummaryrefslogtreecommitdiff
path: root/wave.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-07 09:37:45 +1000
committerquou <quou@disroot.org>2023-05-07 09:37:45 +1000
commit40eb179043b77f011fb1048c386ee187f64569d0 (patch)
treeebae794ec0b3b8851b8c29119ada06555f49d4b6 /wave.c
parent47e7976922f5c17505c7c5a3377c3735649e3dcc (diff)
Add waves and some more polish.
Diffstat (limited to 'wave.c')
-rw-r--r--wave.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/wave.c b/wave.c
new file mode 100644
index 0000000..93b43f4
--- /dev/null
+++ b/wave.c
@@ -0,0 +1,56 @@
+#include "enemy.h"
+#include "standard.h"
+#include "wave.h"
+#include "world.h"
+
+static const Wave waves[] = {
+ {
+ {
+ {
+ 20,
+ 2,
+ {
+ { 3, 5 },
+ { 15, 15 },
+ }
+ },
+ },
+ 1
+ }
+};
+
+void init_waver(Waver* waver) {
+ waver->idx = 0;
+ waver->sidx = 0;
+ waver->timer = 0;
+}
+
+void next_wave(Waver* waver) {
+ waver->idx++;
+}
+
+void update_waver(Waver* waver, World* world) {
+ const Wave* wave;
+ const Subwave* subwave;
+ const Wave_Spawn* spawn;
+ int i;
+
+ wave = &waves[waver->idx];
+ subwave = &wave->subwaves[waver->sidx];
+
+ if (waver->sidx >= wave->subwave_count) { return; }
+
+ waver->timer++;
+
+ if (waver->timer >= subwave->frame) {
+ for (i = 0; i < subwave->count; i++) {
+ spawn = &subwave->spawns[i];
+ new_skull(
+ world,
+ (spawn->x * map_tile_size) << fbits,
+ (spawn->y * map_tile_size) << fbits
+ );
+ }
+ waver->sidx++;
+ }
+}