aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-05-06 18:00:14 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-05-06 18:00:14 +0000
commitf6635129ef339ffa4c3725b6a04b0dd644f2c7cf (patch)
tree9870c2d0e755614f46bd4637d3e2d9561e668ef7
parentc475f3de248a25a999dafd4792d0454eb55191c1 (diff)
downloadPenguinYippies-f6635129ef339ffa4c3725b6a04b0dd644f2c7cf.tar.gz
PenguinYippies-f6635129ef339ffa4c3725b6a04b0dd644f2c7cf.tar.bz2
PenguinYippies-f6635129ef339ffa4c3725b6a04b0dd644f2c7cf.zip
Weird jumping
-rw-r--r--src/shooterScreen.c42
-rw-r--r--src/shooterScreen.h5
2 files changed, 46 insertions, 1 deletions
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 {