summaryrefslogtreecommitdiff
path: root/player.c
blob: 0110b560c37efc0b9773cf8463055e33a81ae5e8 (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
#include "maths.h"
#include "plat.h"
#include "player.h"
#include "services.h"

void init_player(Player* p) {
	int ip[] = { 0, 0, -(5 << fbits) };
	vec_cpy(p->p, ip, 3);
	p->r[0] = 0;
	p->r[1] = 0;
}

void update_player(Player* p, struct Services* s) {
	App* a = s->a;
	int fb, lr;
	int dir[4];
	int t = (p->r[1] / 10);
	int t2 = (t + 64) & sin_table_mask;
	t &= sin_table_mask;
	fb = !!(a->key_states[key_W] & key_state_pressed);
	fb -= 2 * !!(a->key_states[key_S] & key_state_pressed);
	lr = !!(a->key_states[key_A] & key_state_pressed);
	lr -= 2 * !!(a->key_states[key_D] & key_state_pressed);
	p->r[1] -= a->dmx;
	dir[0] = -sin_table[t];
	dir[1] =  cos_table[t];
	dir[2] = -sin_table[t2];
	dir[3] =  cos_table[t2];
	p->p[0] += (dir[0] * fb + dir[2] * lr) / 3;
	p->p[2] += (dir[1] * fb + dir[3] * lr) / 3;
}

void push_player_cam(const Player* p) {
	int v[3];
	v[0] = -p->p[0];
	v[1] = -p->p[1];
	v[2] = -p->p[2];
	mtx_push_rot_y(p->r[1] / 10);
	mtx_push_rot_x(p->r[0] / 10);
	mtx_push_trans(v);
}

void pop_player_cam(void) {
	mtx_popn(3);
}