From cf631e23e1d0e29edac2e13446bdd42235c111fc Mon Sep 17 00:00:00 2001 From: kartofen Date: Sat, 15 Apr 2023 18:27:29 +0300 Subject: collision and depth shading --- src/player.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/player.c') diff --git a/src/player.c b/src/player.c index 2231b9e..6ea618b 100644 --- a/src/player.c +++ b/src/player.c @@ -3,7 +3,9 @@ #define DEFAULT_STAND_HEIGHT 6.0f #define DEFAULT_DUCK_HEIGHT 2.5f + #define DEFAULT_HEAD_MARGIN 1.0f +#define DEFAULT_KNEE_HEIGHT 2.0f void player_default(player_t *player) { @@ -17,8 +19,7 @@ void player_default(player_t *player) player->duck_height = DEFAULT_DUCK_HEIGHT; player->head_margin = DEFAULT_HEAD_MARGIN; - player->ground = false; player->falling = true; - player->moving = false; player->ducking = false; + player->ducking = false; } void player_input(player_t *player, bool *input, int rmouse_x, int rmouse_y) { @@ -30,8 +31,12 @@ void player_input(player_t *player, bool *input, int rmouse_x, int rmouse_y) 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; + if(input[4]) { if(player->velocity.z == 0.0f) player->velocity.z += 0.5f; } + + player->ducking = input[5]; + + bool pressing = input[0] || input[1] || input[2] || input[3] || input[4]; + float acceleration = pressing ? 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; @@ -44,5 +49,5 @@ 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 + player->pos.z += player->velocity.z; } -- cgit v1.2.3