summaryrefslogtreecommitdiff
path: root/src/player.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2023-04-15 18:27:29 +0300
committerkartofen <mladenovnasko0@gmail.com>2023-04-15 18:27:29 +0300
commitcf631e23e1d0e29edac2e13446bdd42235c111fc (patch)
tree141f85599c7bd47b3fcb0a3088a5ce117d6e18fd /src/player.c
parent02ec17653ee5399eac67871dfd5fb193bb9dce2f (diff)
collision and depth shading
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c15
1 files changed, 10 insertions, 5 deletions
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;
}