mirror of
https://github.com/theoleuthardt/DinoGame.git
synced 2026-06-13 09:27:57 +00:00
fix: dependency for file interaction and windows compression
This commit is contained in:
parent
2402e59659
commit
41e7843889
3 changed files with 18 additions and 19 deletions
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
|
|
@ -110,7 +110,7 @@ jobs:
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
run: |
|
run: |
|
||||||
cd ${{ steps.get-output-dir.outputs.output_dir }}
|
cd ${{ steps.get-output-dir.outputs.output_dir }}
|
||||||
Compress-Archive -Path .\* -DestinationPath ..\DinoGame-Windows.zip
|
Compress-Archive -Path .\* -DestinationPath ..\..\DinoGame-Windows.zip
|
||||||
shell: powershell
|
shell: powershell
|
||||||
|
|
||||||
- name: List files after zipping
|
- name: List files after zipping
|
||||||
|
|
@ -123,7 +123,7 @@ jobs:
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: DinoGame-${{ runner.os }}
|
name: DinoGame-${{ runner.os }}
|
||||||
path: ${{ steps.get-output-dir.outputs.output_dir }}/DinoGame-Windows.zip
|
path: DinoGame-${{ runner.os }}.zip
|
||||||
|
|
||||||
release:
|
release:
|
||||||
needs: build
|
needs: build
|
||||||
|
|
|
||||||
23
src/Game.cpp
23
src/Game.cpp
|
|
@ -1,6 +1,6 @@
|
||||||
#include "Game.hpp"
|
#include "Game.hpp"
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <algorithm>
|
#include <cstdio>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ Game::Game() {
|
||||||
gameOver = false;
|
gameOver = false;
|
||||||
|
|
||||||
// spawn the first cactus
|
// spawn the first cactus
|
||||||
cacti.push_back(Cactus(cactusTexture, 800, 330 - cactusTexture.height));
|
cacti.emplace_back(cactusTexture, 800, 330 - cactusTexture.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game() {
|
Game::~Game() {
|
||||||
|
|
@ -78,9 +78,8 @@ void Game::Update() {
|
||||||
cactus.Update();
|
cactus.Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
cacti.erase(remove_if(cacti.begin(), cacti.end(),
|
erase_if(cacti,
|
||||||
[](Cactus &c) { return c.IsOffScreen(); }),
|
[](Cactus &c) { return c.IsOffScreen(); });
|
||||||
cacti.end());
|
|
||||||
|
|
||||||
for (auto &cactus : cacti) {
|
for (auto &cactus : cacti) {
|
||||||
if (CheckCollision(*dino, cactus)) {
|
if (CheckCollision(*dino, cactus)) {
|
||||||
|
|
@ -106,23 +105,23 @@ void Game::Draw() {
|
||||||
cactus.Draw();
|
cactus.Draw();
|
||||||
}
|
}
|
||||||
if (hintTimer < 4.0f) {
|
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);
|
DrawText("Press SPACE to Jump!", GetScreenWidth()/2 - hintWidth/2, 50, 20, DARKGRAY);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int gameOverTextWidth = MeasureText("GAME OVER", 30);
|
const int gameOverTextWidth = MeasureText("GAME OVER", 30);
|
||||||
DrawText("GAME OVER", GetScreenWidth()/2 - gameOverTextWidth/2, 150, 30, RED);
|
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);
|
DrawText("Press R to restart!", GetScreenWidth()/2 - restartTextWidth/2, 190, 20, BLACK);
|
||||||
if (IsKeyPressed(KEY_R)) {
|
if (IsKeyPressed(KEY_R)) {
|
||||||
Reset();
|
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);
|
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);
|
DrawText("(Your highscore will be saved!)", GetScreenWidth()/2 - saveTextWidth/2, 240, 20, BLACK);
|
||||||
|
|
||||||
Save();
|
Save();
|
||||||
|
|
@ -144,10 +143,10 @@ void Game::Reset() {
|
||||||
hintTimer = 0.0f;
|
hintTimer = 0.0f;
|
||||||
|
|
||||||
// spawn the first cactus again
|
// 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");
|
FILE *file = fopen("save.dat", "wb");
|
||||||
if (file) {
|
if (file) {
|
||||||
fwrite(&highscore, sizeof(highscore), 1, file);
|
fwrite(&highscore, sizeof(highscore), 1, file);
|
||||||
|
|
|
||||||
10
src/Game.hpp
10
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.
|
* @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.
|
* @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 true if the dino and cactus are colliding
|
||||||
* @return false if the dino and cactus are not 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)
|
* @brief The texture for the dino (3 frames)
|
||||||
*/
|
*/
|
||||||
Texture2D dinoTexture;
|
Texture2D dinoTexture{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The texture for the cactus
|
* @brief The texture for the cactus
|
||||||
*/
|
*/
|
||||||
Texture2D cactusTexture;
|
Texture2D cactusTexture{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The texture for the ground
|
* @brief The texture for the ground
|
||||||
*/
|
*/
|
||||||
Texture2D groundTexture;
|
Texture2D groundTexture{};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The dino object
|
* @brief The dino object
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue