summaryrefslogtreecommitdiff
path: root/lib/player.c
diff options
context:
space:
mode:
authorJoel Stålnacke <joel@saker.fi>2025-07-26 21:09:26 +0300
committerJoel Stålnacke <joel@saker.fi>2025-07-26 21:09:26 +0300
commit63506e59366acddf4a9e017ad8aebeadcf58c164 (patch)
tree2fa106661b85497fc1d63b7743a78e523ab48fba /lib/player.c
parent53f68bb7b0dce309723675c4b97f726a469031c0 (diff)
Old changesHEADmaster
Diffstat (limited to 'lib/player.c')
-rw-r--r--lib/player.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/player.c b/lib/player.c
new file mode 100644
index 0000000..35c3b80
--- /dev/null
+++ b/lib/player.c
@@ -0,0 +1,36 @@
+#include "snapshot.h"
+
+#include "player.h"
+
+vec2
+dp_player_calculate_acceleration(const struct player *p)
+{
+ vec2 acc, dec;
+ int x = 0, y = 0;
+
+ if (p->input & INPUT_UP)
+ {
+ y -= 1;
+ }
+ if (p->input & INPUT_DOWN)
+ {
+ y += 1;
+ }
+
+ if (p->input & INPUT_LEFT)
+ {
+ x -= 1;
+ }
+ if (p->input & INPUT_RIGHT)
+ {
+ x += 1;
+ }
+
+ acc = dp_vec2_new((float)x, (float)y);
+ acc = dp_vec2_normal(acc);
+ acc = dp_vec2_mul(acc, PLAYER_ACCELERATION);
+
+ dec = dp_vec2_mul(p->vel, -1.0f * PLAYER_DRAG);
+
+ return dp_vec2_add(acc, dec);
+}