From f6635129ef339ffa4c3725b6a04b0dd644f2c7cf Mon Sep 17 00:00:00 2001 From: nathansmith117 Date: Mon, 6 May 2024 12:00:14 -0600 Subject: Weird jumping --- src/shooterScreen.c | 42 +++++++++++++++++++++++++++++++++++++++++- src/shooterScreen.h | 5 +++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/shooterScreen.c b/src/shooterScreen.c index d17fdd6..4feeb9a 100644 --- a/src/shooterScreen.c +++ b/src/shooterScreen.c @@ -15,7 +15,8 @@ void initShooterScreeen(ShooterScreen* shooterScreen, Game* game) .position = (Vector3){0.0, PLAYER_HEIGHT, 0.0}, .direction = (Vector3){0.0, 0.0, 1.0}, .velocity = Vector3Zero(), - .cameraAngle = Vector2Zero() + .cameraAngle = Vector2Zero(), + .jumpStage = 0 }; } @@ -57,15 +58,54 @@ void updateShooterScreenControls(ShooterScreen* shooterScreen, Game* game) player->velocity.x += -sin(player->cameraAngle.x + (PI / 2.0)); } + // Jump + if (IsKeyPressed(KEY_SPACE)) + { + player->jumpStage = 1; + } + player->velocity = Vector3Scale(player->velocity, PLAYER_SPEED); } +void updateShooterScreenJump(ShooterScreen* shooterScreen, Game* game) +{ + ShooterPlayer* player = &shooterScreen->player; + + switch (player->jumpStage) + { + case 0: // No Jumpy + break; + case 1: // Jump up + player->velocity.y = PLAYER_JUMP_SPEED; + + if (player->position.y >= PLAYER_JUMP_HEIGHT + PLAYER_HEIGHT) + { + player->jumpStage = 2; + } + + break; + case 2: // Fall + player->velocity.y = -PLAYER_FALL_SPEED; + + if (player->position.y <= PLAYER_HEIGHT) + { + player->jumpStage = 0; + player->position.y = PLAYER_HEIGHT; + } + + break; + default: + break; + } +} + void updateShooterScreen(ShooterScreen* shooterScreen, Game* game) { ShooterPlayer* player = &shooterScreen->player; ClearBackground(PINK); updateShooterScreenControls(shooterScreen, game); + updateShooterScreenJump(shooterScreen, game); // Apply velocity. player->position = Vector3Add( diff --git a/src/shooterScreen.h b/src/shooterScreen.h index 9bbc188..7c69a54 100644 --- a/src/shooterScreen.h +++ b/src/shooterScreen.h @@ -6,6 +6,9 @@ #define PLAYER_HEIGHT 2.0 #define MOUSE_SPEED 0.01 #define PLAYER_SPEED 10.0 +#define PLAYER_JUMP_SPEED 15.0 +#define PLAYER_FALL_SPEED 18.0 +#define PLAYER_JUMP_HEIGHT 8.0 typedef struct ShooterPlayer { Camera3D camera; @@ -15,6 +18,8 @@ typedef struct ShooterPlayer { Vector3 velocity; Vector2 cameraAngle; + + int jumpStage; } ShooterPlayer; typedef struct ShooterScreen { -- cgit v1.2.3