aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathansmith117 <thenathansmithsmith@gmail.com>2024-05-06 19:38:44 +0000
committernathansmith117 <thenathansmithsmith@gmail.com>2024-05-06 19:38:44 +0000
commite9787dccd1cc1f0ef096ecde381f9f817a86260a (patch)
tree99ee0a07ae29d8dbdb8c33f44cb66b60f8848f09 /src
parentfcd2d57b2a28c0e342ba8bf668a4501f845a6df0 (diff)
downloadPenguinYippies-e9787dccd1cc1f0ef096ecde381f9f817a86260a.tar.gz
PenguinYippies-e9787dccd1cc1f0ef096ecde381f9f817a86260a.tar.bz2
PenguinYippies-e9787dccd1cc1f0ef096ecde381f9f817a86260a.zip
Penguins moving in shooter
Diffstat (limited to 'src')
-rw-r--r--src/shooterScreen.c45
-rw-r--r--src/shooterScreen.h8
2 files changed, 52 insertions, 1 deletions
diff --git a/src/shooterScreen.c b/src/shooterScreen.c
index 437f0e0..6b1322d 100644
--- a/src/shooterScreen.c
+++ b/src/shooterScreen.c
@@ -105,11 +105,53 @@ void updateShooterScreenJump(ShooterScreen* shooterScreen, Game* game)
void updateShooterScreenPenguins(ShooterScreen* shooterScreen, Game* game)
{
+ double currentTime = GetTime();
+ double frameTime = GetFrameTime();
Texture texture = game->assets.textures[PENGUIN_BILLBOARD_TEXTURE];
ShooterPenguin* penguins = shooterScreen->penguins;
for (int i = 0; i < SHOOTER_PENGUIN_COUNT; ++i)
{
+ // Change velocity.
+ if ((int)(penguins[i].changeSpeedDelay) == 0) // Goes at you.
+ {
+ penguins[i].velocity = Vector3Subtract(shooterScreen->player.position, penguins[i].position);
+ penguins[i].velocity = Vector3Scale(Vector3Normalize(penguins[i].velocity), SHOOTER_PENGUIN_SPEED);
+ penguins[i].velocity.y = 0.0;
+ }
+ else if (currentTime - penguins[i].lastVelocityChange >= penguins[i].changeSpeedDelay)
+ {
+ if (Vector3Length(penguins[i].position) >= SHOOTER_MAP_SIZE) // Too far away.
+ {
+ // Make it come closer.
+ penguins[i].velocity = Vector3Negate(penguins[i].position);
+ penguins[i].velocity.y = 0.0;
+ penguins[i].velocity = Vector3Scale(Vector3Normalize(penguins[i].velocity), SHOOTER_PENGUIN_SPEED);
+ }
+ else
+ {
+ // Get random velocity.
+ SetRandomSeed(time(NULL));
+
+ penguins[i].velocity = (Vector3){
+ (float)GetRandomValue(-1000, 1000) / 1000.0,
+ 0.0,
+ (float)GetRandomValue(-1000, 1000) / 1000.0
+ };
+
+ penguins[i].velocity = Vector3Scale(Vector3Normalize(penguins[i].velocity), SHOOTER_PENGUIN_SPEED);
+ }
+
+ penguins[i].lastVelocityChange = currentTime;
+ }
+
+ // Apply velocity.
+ penguins[i].position = Vector3Add(
+ penguins[i].position,
+ Vector3Scale(penguins[i].velocity, frameTime)
+ );
+
+ // Draw them.
DrawBillboard(shooterScreen->player.camera, texture, penguins[i].position, 2.0, WHITE);
}
}
@@ -171,6 +213,9 @@ void resetShooterScreen(ShooterScreen* shooterScreen)
shooterScreen->penguins[i].position = randomPosition;
shooterScreen->penguins[i].velocity = Vector3Zero();
shooterScreen->penguins[i].sleepyness = 0.0;
+ shooterScreen->penguins[i].changeSpeedDelay = GetRandomValue(SHOOTER_PENGUIN_CHANGE_DELAY_MIN,
+ SHOOTER_PENGUIN_CHANGE_DELAY_MAX);
+ shooterScreen->penguins[i].lastVelocityChange = 0.0;
}
}
diff --git a/src/shooterScreen.h b/src/shooterScreen.h
index 2d9d533..720b961 100644
--- a/src/shooterScreen.h
+++ b/src/shooterScreen.h
@@ -13,8 +13,11 @@
#define MOUSE_SPEED 0.01
-#define SHOOTER_PENGUIN_COUNT 5
+#define SHOOTER_PENGUIN_COUNT 10
#define SHOOTER_PENGUIN_HEIGHT 1.0
+#define SHOOTER_PENGUIN_CHANGE_DELAY_MIN 0 // Goes at you at 0
+#define SHOOTER_PENGUIN_CHANGE_DELAY_MAX 7
+#define SHOOTER_PENGUIN_SPEED 8.0
typedef struct ShooterPlayer {
Camera3D camera;
@@ -34,6 +37,9 @@ typedef struct ShooterPenguin {
Vector3 position;
Vector3 velocity;
float sleepyness;
+
+ double changeSpeedDelay;
+ double lastVelocityChange;
} ShooterPenguin;
typedef struct ShooterScreen {