blob: 35c3b8034df7f114d20bd4d5e9ea7a1ec8ddfd01 (
plain)
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
|
#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);
}
|