summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-20 09:55:26 +1000
committerquou <quou@disroot.org>2024-07-20 09:55:26 +1000
commitfc9353838ff8f29c56593b89123ea2d5ebaa604a (patch)
tree9418f02f8ef7e902cb9c99f7b9ee50212f846263
parent2bdea40c02e69f4b5f3a0e68413ed1ac06600616 (diff)
Simple first person movement.
-rw-r--r--player.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/player.c b/player.c
index 2ba3885..0110b56 100644
--- a/player.c
+++ b/player.c
@@ -12,10 +12,22 @@ void init_player(Player* p) {
void update_player(Player* p, struct Services* s) {
App* a = s->a;
-/* p->r[0] -= a->dmy;*/
+ 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;
-/* p->p[0] -= sin_table[p->r[1] & sin_table_mask] / 3;
- p->p[2] += cos_table[p->r[1] & sin_table_mask] / 3;*/
+ 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) {