diff options
author | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-05-07 00:49:50 +0000 |
---|---|---|
committer | nathansmith117 <thenathansmithsmith@gmail.com> | 2024-05-07 00:49:50 +0000 |
commit | 529bec904716fc91ecd937a06bf81ea150cf3c72 (patch) | |
tree | ebe586375dd2fc710f32d12a4b163ad320313b7c /src | |
parent | 1aec85f04d08665ca386c58c982094acc67dd118 (diff) | |
download | PenguinYippies-529bec904716fc91ecd937a06bf81ea150cf3c72.tar.gz PenguinYippies-529bec904716fc91ecd937a06bf81ea150cf3c72.tar.bz2 PenguinYippies-529bec904716fc91ecd937a06bf81ea150cf3c72.zip |
As end of level thing for the shooter
Diffstat (limited to 'src')
-rw-r--r-- | src/shooterScreen.c | 65 | ||||
-rw-r--r-- | src/shooterScreen.h | 9 |
2 files changed, 70 insertions, 4 deletions
diff --git a/src/shooterScreen.c b/src/shooterScreen.c index 513d37e..d9daaa8 100644 --- a/src/shooterScreen.c +++ b/src/shooterScreen.c @@ -20,6 +20,8 @@ void initShooterScreeen(ShooterScreen* shooterScreen, Game* game) .jumpStage = 0 }; + shooterScreen->bestPNPS = 0.0; + resetShooterScreen(shooterScreen); } @@ -46,6 +48,11 @@ void shootBulletShooterScreen(ShooterScreen* shooterScreen, Game* game) { ShooterPenguin* penguin = &shooterScreen->penguins[i]; + if (penguin->isDead) + { + continue; + } + // Get the box at the penguins position. BoundingBox currentBox = (BoundingBox){ .min = Vector3Add(penguin->position, penguinBox.min), @@ -220,8 +227,8 @@ void updateShooterScreenPenguins(ShooterScreen* shooterScreen, Game* game) void drawCrosshairShooterScreen(int size, int thickness) { - int halfWidth = GetScreenWidth() / 2; - int halfHeight = GetScreenHeight() / 2; + int halfWidth = WINDOW_WIDTH / 2; + int halfHeight = WINDOW_HEIGHT / 2; // Left to right. DrawLineEx((Vector2){halfWidth - size, halfHeight}, @@ -246,13 +253,36 @@ void drawUIShooterScreen(ShooterScreen* shooterScreen, Game* game) DrawText(buf, 0, 0, 20, BLACK); } +void drawShooterScreenEndLevel(ShooterScreen* shooterScreen, Game* game) +{ + // Set pnps. + if (FloatEquals(shooterScreen->pnps, 0.0)) + { + shooterScreen->pnps = (float)SHOOTER_PENGUIN_COUNT / (GetTime() - shooterScreen->startTime); + + // Find best pnps. + if (shooterScreen->pnps > shooterScreen->bestPNPS) + { + shooterScreen->bestPNPS = shooterScreen->pnps; + } + } + + // Format message. + size_t bufSize = 100; + char buf[bufSize]; + + snprintf(buf, bufSize, "Level done with a penguin naps per seconds (pnps) of: %f\n\tBest npns this game: %f", + shooterScreen->pnps, shooterScreen->bestPNPS); + + // Draw it. + DrawText(buf, WINDOW_WIDTH / 4.0, WINDOW_HEIGHT / 2.0, 25, BLACK); +} + void updateShooterScreen(ShooterScreen* shooterScreen, Game* game) { ShooterPlayer* player = &shooterScreen->player; ClearBackground(PINK); - drawUIShooterScreen(shooterScreen, game); - updateShooterScreenControls(shooterScreen, game); updateShooterScreenJump(shooterScreen, game); @@ -273,6 +303,28 @@ void updateShooterScreen(ShooterScreen* shooterScreen, Game* game) updateShooterScreenPenguins(shooterScreen, game); EndMode3D(); + + drawUIShooterScreen(shooterScreen, game); + + // End of level. + if (shooterScreen->killCount == SHOOTER_PENGUIN_COUNT) + { + // Start timer. + if (!shooterScreen->atEndLevel) + { + shooterScreen->endLevelStartTime = GetTime(); + shooterScreen->atEndLevel = true; + } + + // Back to main game. + if (GetTime() - shooterScreen->endLevelStartTime >= SHOOTER_END_LEVEL_TIME || IsKeyPressed(KEY_SPACE)) + { + leaveShooterScreen(game); + game->currentScreen = GAME_SCREEN; + } + + drawShooterScreenEndLevel(shooterScreen, game); + } } void closeShooterScreen(ShooterScreen* shooterScreen) @@ -308,8 +360,13 @@ void resetShooterScreen(ShooterScreen* shooterScreen) shooterScreen->penguins[i].isDead = false; } + shooterScreen->pnps = 0.0; + shooterScreen->killCount = 0; + // Time. shooterScreen->startTime = GetTime(); + + shooterScreen->atEndLevel = false; } void enterShooterScreen(Game* game) diff --git a/src/shooterScreen.h b/src/shooterScreen.h index 2499413..1c22814 100644 --- a/src/shooterScreen.h +++ b/src/shooterScreen.h @@ -19,6 +19,8 @@ #define SHOOTER_PENGUIN_CHANGE_DELAY_MAX 7 #define SHOOTER_PENGUIN_SPEED 8.0 +#define SHOOTER_END_LEVEL_TIME 7.0 + typedef struct ShooterPlayer { Camera3D camera; @@ -47,6 +49,13 @@ typedef struct ShooterScreen { ShooterPenguin penguins[SHOOTER_PENGUIN_COUNT]; double startTime; int killCount; // "Sleep" count. + + // Penguin naps per second. + float pnps; + float bestPNPS; + + bool atEndLevel; + double endLevelStartTime; } ShooterScreen; void initShooterScreeen(ShooterScreen* shooterScreen, Game* game); |