aboutsummaryrefslogtreecommitdiff
path: root/wave.c
blob: 93b43f4a9d5dd9940fc95008a5c470be57054fb7 (plain) (blame)
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
#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++;
	}
}