aboutsummaryrefslogtreecommitdiff
path: root/world.c
blob: e7777fdc1ae8ead9ea43d43cf6dfe5c6bf316abd (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
#include "plat.h"
#include "world.h"

void init_world(World* w) {
	w->particle_count = 0;
	init_player(&w->player);
}

Particle* inst_particle(
	World* w,
	int x,
	int y,
	int anim,
	int bmp
) {
	Particle* p;
	assert(w->particle_count < max_particles);
	p = &w->particles[w->particle_count++];
	init_particle(p, x, y, anim, bmp);
	return p;
}

void update_world(World* w, const App* a) {
	int i;
	update_player(&w->player, w, a, &w->map);
	for (i = w->particle_count - 1; i >= 0; i--)
		if (update_particle(&w->particles[i]))
			w->particles[i] = w->particles[--w->particle_count];
}

void ren_world(const World* w, struct Renderer* r) {
	int i;
	ren_player(&w->player, r);
	render_map(&w->map, r);
	for (i = 0; i < w->particle_count; i++)
		ren_particle(&w->particles[i], r);
}