diff options
Diffstat (limited to 'src/player.c')
-rw-r--r-- | src/player.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/player.c b/src/player.c index b94290d..2231b9e 100644 --- a/src/player.c +++ b/src/player.c @@ -1,10 +1,48 @@ #include <math.h> #include "player.h" -int player_update(player_t *player) +#define DEFAULT_STAND_HEIGHT 6.0f +#define DEFAULT_DUCK_HEIGHT 2.5f +#define DEFAULT_HEAD_MARGIN 1.0f + +void player_default(player_t *player) +{ + player->pos = (struct xyz){0.0f, 0.0f, 0.0f}; + player->velocity = (struct xyz){0.0f, 0.0f, 0.0f}; + + player->angle = 0.0f; player->anglesin = 0.0f; player->anglecos = 1.0f; + player->sector = 0; + + player->stand_height = DEFAULT_STAND_HEIGHT; + player->duck_height = DEFAULT_DUCK_HEIGHT; + player->head_margin = DEFAULT_HEAD_MARGIN; + + player->ground = false; player->falling = true; + player->moving = false; player->ducking = false; +} +void player_input(player_t *player, bool *input, int rmouse_x, int rmouse_y) { + (void)rmouse_y; + player->angle += rmouse_x * 0.03f; + + float move_vec[2] = {0.f, 0.f}; + if(input[0]) { move_vec[0] += player->anglecos*0.2f; move_vec[1] += player->anglesin*0.2f; } + if(input[2]) { move_vec[0] -= player->anglecos*0.2f; move_vec[1] -= player->anglesin*0.2f; } + if(input[1]) { move_vec[0] += player->anglesin*0.2f; move_vec[1] -= player->anglecos*0.2f; } + if(input[3]) { move_vec[0] -= player->anglesin*0.2f; move_vec[1] += player->anglecos*0.2f; } + player->moving = input[0] || input[1] || input[2] || input[3]; + float acceleration = player->moving ? 0.4f : 0.2f; + + player->velocity.x = player->velocity.x * (1-acceleration) + move_vec[0] * acceleration; + player->velocity.y = player->velocity.y * (1-acceleration) + move_vec[1] * acceleration; + player->anglesin = sinf(player->angle); player->anglecos = cosf(player->angle); +} - return 0; +void player_update(player_t *player) +{ + player->pos.x += player->velocity.x; + player->pos.y += player->velocity.y; + player->pos.z = player->stand_height; // temp } |