diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8df2bb2..6334cc9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -110,7 +110,7 @@ jobs: if: runner.os == 'Windows' run: | cd ${{ steps.get-output-dir.outputs.output_dir }} - Compress-Archive -Path .\* -DestinationPath ..\DinoGame-Windows.zip + Compress-Archive -Path .\* -DestinationPath ..\..\DinoGame-Windows.zip shell: powershell - name: List files after zipping @@ -123,7 +123,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: DinoGame-${{ runner.os }} - path: ${{ steps.get-output-dir.outputs.output_dir }}/DinoGame-Windows.zip + path: DinoGame-${{ runner.os }}.zip release: needs: build diff --git a/src/Game.cpp b/src/Game.cpp index d1618e8..cd32056 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1,6 +1,6 @@ #include "Game.hpp" #include "raylib.h" -#include +#include using namespace std; @@ -22,7 +22,7 @@ Game::Game() { gameOver = false; // spawn the first cactus - cacti.push_back(Cactus(cactusTexture, 800, 330 - cactusTexture.height)); + cacti.emplace_back(cactusTexture, 800, 330 - cactusTexture.height); } Game::~Game() { @@ -78,9 +78,8 @@ void Game::Update() { cactus.Update(); } - cacti.erase(remove_if(cacti.begin(), cacti.end(), - [](Cactus &c) { return c.IsOffScreen(); }), - cacti.end()); + erase_if(cacti, + [](Cactus &c) { return c.IsOffScreen(); }); for (auto &cactus : cacti) { if (CheckCollision(*dino, cactus)) { @@ -106,23 +105,23 @@ void Game::Draw() { cactus.Draw(); } if (hintTimer < 4.0f) { - int hintWidth = MeasureText("Press SPACE to Jump!", 20); + const int hintWidth = MeasureText("Press SPACE to Jump!", 20); DrawText("Press SPACE to Jump!", GetScreenWidth()/2 - hintWidth/2, 50, 20, DARKGRAY); } } else { - int gameOverTextWidth = MeasureText("GAME OVER", 30); + const int gameOverTextWidth = MeasureText("GAME OVER", 30); DrawText("GAME OVER", GetScreenWidth()/2 - gameOverTextWidth/2, 150, 30, RED); - int restartTextWidth = MeasureText("Press R to restart!", 20); + const int restartTextWidth = MeasureText("Press R to restart!", 20); DrawText("Press R to restart!", GetScreenWidth()/2 - restartTextWidth/2, 190, 20, BLACK); if (IsKeyPressed(KEY_R)) { Reset(); } - int exitTextWidth = MeasureText("Press ESC to close the game!", 20); + const int exitTextWidth = MeasureText("Press ESC to close the game!", 20); DrawText("Press ESC to close the game!", GetScreenWidth()/2 - exitTextWidth/2, 220, 20, BLACK); - int saveTextWidth = MeasureText("(Your highscore will be saved!)", 20); + const int saveTextWidth = MeasureText("(Your highscore will be saved!)", 20); DrawText("(Your highscore will be saved!)", GetScreenWidth()/2 - saveTextWidth/2, 240, 20, BLACK); Save(); @@ -144,10 +143,10 @@ void Game::Reset() { hintTimer = 0.0f; // spawn the first cactus again - cacti.push_back(Cactus(cactusTexture, 900, 300 - cactusTexture.height)); + cacti.emplace_back(cactusTexture, 900, 300 - cactusTexture.height); } -void Game::Save() { +void Game::Save() const { FILE *file = fopen("save.dat", "wb"); if (file) { fwrite(&highscore, sizeof(highscore), 1, file); diff --git a/src/Game.hpp b/src/Game.hpp index ffad293..06786c1 100644 --- a/src/Game.hpp +++ b/src/Game.hpp @@ -53,7 +53,7 @@ private: /** * @brief Saves the high score to a dat-file. If the file does not exist, it will be created. */ - void Save(); + void Save() const; /** * @brief Loads the high score from a dat-file. If the file does not exist, the high score will be 0. @@ -67,22 +67,22 @@ private: * @return true if the dino and cactus are colliding * @return false if the dino and cactus are not colliding */ - bool CheckCollision(Dino &dino, Cactus &cactus); + static bool CheckCollision(Dino &dino, Cactus &cactus); /** * @brief The texture for the dino (3 frames) */ - Texture2D dinoTexture; + Texture2D dinoTexture{}; /** * @brief The texture for the cactus */ - Texture2D cactusTexture; + Texture2D cactusTexture{}; /** * @brief The texture for the ground */ - Texture2D groundTexture; + Texture2D groundTexture{}; /** * @brief The dino object