fix: dependency for file interaction and windows compression

This commit is contained in:
theoleuthardt 2025-03-13 14:57:06 +01:00
parent 2402e59659
commit 41e7843889
3 changed files with 18 additions and 19 deletions

View file

@ -1,6 +1,6 @@
#include "Game.hpp"
#include "raylib.h"
#include <algorithm>
#include <cstdio>
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);

View file

@ -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