aboutsummaryrefslogtreecommitdiff
path: root/projectile.c
blob: ce68e8f7024b3b66ae7c6d9bf3a6a700607010c9 (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
57
58
59
#include "animation.h"
#include "asset.h"
#include "maths.h"
#include "obj.h"
#include "physics.h"
#include "render.h"
#include "world.h"

void init_projectile(
	Projectile* p,
	int x,
	int y,
	const Rect* r,
	int anim
) {
	p->r = *r;
	p->frame = 0;
	p->anim = anim;
	p->x = x;
	p->y = y;
	p->vx = 0;
	p->vy = 0;
	p->s.x = 0;
	p->s.y = 0;
	p->s.w = 0;
	p->s.h = 0;
}

int update_projectile(
	Projectile* p,
	const World* w
) {
	Rect r = p->r;
	int grounded = 1, headbutted = 1, on_ramp = 0;
	const Animation* a = get_animation(p->anim);
	r.x <<= fbits;
	r.y <<= fbits;
	r.w <<= fbits;
	r.h <<= fbits;
	update_body(
		&w->map,
		&p->x,
		&p->y,
		&p->vx,
		&p->vy,
		&grounded,
		&headbutted,
		&on_ramp,
		&r
	);
	update_anim(a, &p->frame, &p->s);
	return !grounded;
}

void ren_projectile(const Projectile* p, Renderer* r) {
	const Bitmap* bm = get_bitmap(asset_id_arms_img);
	ren_map(r, p->x >> fbits, p->y >> fbits, &p->s, bm);
}