From de958b02e60f41c4582985ed82fbfc52bcee2c1e Mon Sep 17 00:00:00 2001 From: Ninjaws Date: Sun, 15 Dec 2024 00:12:16 +0100 Subject: [PATCH] [Added] Crates, Hud for bullets and health --- .devcontainer/devcontainer.json | 3 +- .vscode/launch.json | 23 ++++ .vscode/tasks.json | 20 +++ Dockerfile | 2 +- include/entities/Bullet.h | 11 +- include/entities/Crate.h | 48 +++++++ include/entities/Game.h | 71 +++++++++- include/entities/Map.h | 7 +- include/entities/PBullet.h | 26 +++- include/entities/Player.h | 39 ++++-- include/enums/ESound.h | 17 +++ include/services/AssetService.h | 7 +- include/services/CollectableService.h | 184 ++++++++++++++++++++++++++ include/services/GameService.h | 5 + scripts/build_and_run_project.sh | 6 +- src/services/AssetService.cpp | 7 + src/services/StateService.cpp | 10 +- 17 files changed, 448 insertions(+), 38 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 include/entities/Crate.h create mode 100644 include/enums/ESound.h create mode 100644 include/services/CollectableService.h diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 0e4d1b2..462a8c6 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -28,7 +28,8 @@ "settings": {}, "extensions": [ "esbenp.prettier-vscode", - "ms-vscode.cpptools-extension-pack" + "ms-vscode.cpptools-extension-pack", + "vadimcn.vscode-lldb" ] } }, diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..e6964e4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Debug with LLDB", + "type": "lldb", + "request": "launch", + "program": "${workspaceFolder}/dist/jelly_rescue", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "miDebuggerPath": "/usr/bin/lldb-mi", + "preLaunchTask": "build jelly_rescue", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..403f3c9 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build jelly_rescue", + "type": "shell", + "command": "bash", + "args": [ + "-c", + "g++ -std=c++20 -g -O0 $(find src/ -name \"*.cpp\") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": ["$gcc"], + "detail": "Compiling the jelly_rescue project" + } + ] +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 25c0935..1eab433 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ RUN apt-get update \ cmake \ libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev \ libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev \ - sudo \ + sudo lldb \ alsa-utils \ && rm -rf /var/cache/apt/* diff --git a/include/entities/Bullet.h b/include/entities/Bullet.h index b623fb7..d65ff65 100644 --- a/include/entities/Bullet.h +++ b/include/entities/Bullet.h @@ -16,7 +16,6 @@ public: { this->position = pos; this->direction = direction; - std::cout << direction << std::endl; } // ~Bullet() {} @@ -25,8 +24,8 @@ public: { move(); hasCollided = false; - envCollision(); objCollision(); + envCollision(); // // detectCollision(); } @@ -42,14 +41,14 @@ public: protected: Color color = RED; + Vector2 position; + int size = 7; + bool hasCollided = false; private: // TextureWrapper object; - Vector2 position; float direction; float velocity = 15.0f; - int size = 7; - bool hasCollided = false; void move() { @@ -59,7 +58,7 @@ private: } void envCollision() { - if (position.y < 0 || position.y > GetScreenHeight()) + if (position.x < 0 || position.y < 0 || position.y > GetScreenHeight()) { hasCollided = true; return; diff --git a/include/entities/Crate.h b/include/entities/Crate.h new file mode 100644 index 0000000..3f31bce --- /dev/null +++ b/include/entities/Crate.h @@ -0,0 +1,48 @@ +#ifndef CRATE_H +#define CRATE_H + +#include "services/AssetService.h" +#include "entities/TextureWrapper.h" +#include "entities/PBullet.h" + +class Crate { +public: + Crate() { + this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CRATE),{32,32}); + } + + Crate(Vector2 pos) { + this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CRATE),{32,32}, pos); + } + + void logic() { + + } + + bool hasBeenHit() { + return this->hit; + } + + void setHit(bool hit) { + this->hit = hit; + } + + void draw() { + DrawTexture(this->texture.getTexture(), this->texture.getPosition().x, this->texture.getPosition().y, WHITE); + } + + TextureWrapper& getObject() { + return this->texture; + } + +private: + TextureWrapper texture; + bool hit; // Whether a PBullet has hit the create +}; + + + + + + +#endif \ No newline at end of file diff --git a/include/entities/Game.h b/include/entities/Game.h index 2639fe0..3c797ab 100644 --- a/include/entities/Game.h +++ b/include/entities/Game.h @@ -8,6 +8,7 @@ #include "services/MapService.h" #include "services/InputService.h" #include "services/GameService.h" +#include "services/CollectableService.h" #include "entities/Player.h" #include "entities/Text.h" #include "entities/Bullet.h" @@ -47,6 +48,8 @@ public: this->player.setPosition({200, 350}); this->crosshair = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CROSSHAIR), {15, 15}, {0, 0}, {0, 0, 15, 15}); + CollectableService::getInstance().initCollectables(); + initPauseScreen(); initGameOverScreen(); @@ -80,8 +83,9 @@ public: AudioService::getInstance().pauseMusic(); return; } - + GameService::getInstance().bulletLogic(); + CollectableService::getInstance().collectableLogic(); this->player.logic(); if (this->player.getTexture().getPosition().x > (StateService::getInstance().getScreenSize().x / 2.0f)) @@ -104,6 +108,7 @@ public: // } GameService::getInstance().drawBullets(); this->map.draw(); + CollectableService::getInstance().drawCollectables(); this->player.draw(); EndMode2D(); @@ -116,6 +121,7 @@ public: { drawGameOver(); } + drawHud(); drawCrosshair(); EndDrawing(); } @@ -250,10 +256,6 @@ private: } } - void shootLogic() - { - } - void drawPaused() { // 100, 100, 255, 60 @@ -290,6 +292,65 @@ private: // 0, // WHITE); } + + void drawHud() + { + drawHudHealth(); + drawHudBullets(); + } + + void drawHudBullets() + { + Vector2i pixel_pos = Vector2i(5, 40); + Texture2D ammoSprite = AssetService::getInstance().getSprite(ESprite::HUD_AMMO); + Vector2i display_pos; + for (int i = 0; i < this->player.getAmmo(); i++) + { + if (i <= 49) + { + display_pos = Vector2i(pixel_pos.x + ammoSprite.width * i, pixel_pos.y); + } + if (i > 49 && i <= 99) + { + display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (50)), pixel_pos.y + ammoSprite.height); + } + else if (i > 99 && i <= 149) + { + display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (100)), pixel_pos.y + ammoSprite.height * 2); + } + else if (i > 149 && i <= 199) + { + display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (150)), pixel_pos.y + ammoSprite.height * 3); + } + else if (i > 199 && i <= 249) + { + display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (200)), pixel_pos.y + ammoSprite.height * 4); + } + DrawTexture(ammoSprite, display_pos.x, display_pos.y, WHITE); + } + } + + void drawHudHealth() + { + Vector2i pixel_pos = Vector2i(5, 5); + Texture2D noHealthSprite = AssetService::getInstance().getSprite(ESprite::HUD_HEART_EMPTY); + Texture2D healthSprite = AssetService::getInstance().getSprite(ESprite::HUD_HEART); + // sVector2f coord_pos = GetWindow().mapPixelToCoords(pixel_pos); + for (int i = 0; i < this->player.getMaxHealth(); i++) + { + Vector2i pos = Vector2i(pixel_pos.x + noHealthSprite.width * i, pixel_pos.y); + // noHealthSprite[i].setPosition(coord_pos.x + noHealthTexture.getSize().x * i, coord_pos.y); + DrawTexture(noHealthSprite, pos.x, pos.y, WHITE); + } + for (int i = 0; i < this->player.getHealth(); i++) + { + // healthSprite[i].setPosition(coord_pos.x + healthTexture.getSize().x * i, coord_pos.y); + // DrawTexture(ammoSprite, display_pos.x, display_pos.y, WHITE); + Vector2i pos = Vector2i(pixel_pos.x + healthSprite.width * i, pixel_pos.y); + // noHealthSprite[i].setPosition(coord_pos.x + noHealthTexture.getSize().x * i, coord_pos.y); + DrawTexture(healthSprite, pos.x, pos.y, WHITE); + } + } }; #endif \ No newline at end of file diff --git a/include/entities/Map.h b/include/entities/Map.h index f93bf97..acdbf7b 100644 --- a/include/entities/Map.h +++ b/include/entities/Map.h @@ -1,9 +1,10 @@ #ifndef MAP_H #define MAP_H -#include #include "raylib.h" #include "entities/TextureWrapper.h" +#include "entities/Vector2i.h" +#include #include /** @@ -28,6 +29,10 @@ public: return this->colMap; } + void updateColmapTile(Vector2i tile, bool collision) { + this->colMap[tile.y][tile.x] = collision ? 1 : 0; + } + private: /** Holds the number for every single tile, which refers to a certain sprite in the tileset */ std::vector> map; diff --git a/include/entities/PBullet.h b/include/entities/PBullet.h index f440ba7..4febe31 100644 --- a/include/entities/PBullet.h +++ b/include/entities/PBullet.h @@ -1,23 +1,35 @@ #ifndef PBULLET_H #define PBULLET_H +#include "services/CollectableService.h" +#include "services/AssetService.h" #include "entities/Bullet.h" #include -class PBullet : public Bullet { +class PBullet : public Bullet +{ public: - PBullet() {} - PBullet(Vector2 pos, float angle) : Bullet(pos, angle) { + PBullet(Vector2 pos, float angle) : Bullet(pos, angle) + { this->color = YELLOW; } - private: - void objCollision() override { - + void objCollision() override + { + /** Check for collisions with creates */ + for (auto &crate : CollectableService::getInstance().getCrates()) + { + if(this->position.x + this->size > crate.getObject().getPosition().x && this->position.x - this->size < crate.getObject().getPosition().x && + this->position.y + this->size > crate.getObject().getPosition().y && this->position.y - this->size < crate.getObject().getPosition().y ) { + crate.setHit(true); + AssetService::getInstance().playSound(ESound::CRATE_BREAK); + // AssetService::getInstance().playSound(ESound::JELLY_FREED); + this->hasCollided = true; + } } - + } }; #endif \ No newline at end of file diff --git a/include/entities/Player.h b/include/entities/Player.h index c260ce1..9840767 100644 --- a/include/entities/Player.h +++ b/include/entities/Player.h @@ -9,6 +9,7 @@ #include "services/GameService.h" #include "entities/TextureWrapper.h" #include "enums/ECorner.h" +#include "enums/ESound.h" #include "entities/Vector2i.h" #include "entities/PBullet.h" @@ -20,11 +21,12 @@ public: this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER), {32, 32}, {200, 200}); prevFrame = GetTime(); - spriteAnimation = {0, 0}; + spriteAnimation = {0, Right}; this->gunRight = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_RIGHT), {58, 29}, {0, 0}); this->gunLeft = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_LEFT), {58, 29}, {0, 0}); this->ammo = max_ammo; this->prevShot = GetTime(); + this->health = max_health; } ~Player() { @@ -54,6 +56,18 @@ public: this->texture.setPosition(pos); } + int getAmmo() { + return this->ammo; + } + + uint8_t getHealth() { + return this->health; + } + + uint8_t getMaxHealth() { + return this->max_health; + } + protected: private: TextureWrapper texture; @@ -63,9 +77,9 @@ private: float jumpPower = 7.2f; float moveSpeed = 5.0f; float gravity = 0.6f; - float animationDelay = 0.2f; // In seconds + float animationDelay = 0.2f; // In seconds double prevFrame; - Vector2 spriteAnimation; // Keeps track of (1) Sprite cycling and (2) Player direction + Vector2i spriteAnimation; // Keeps track of (1) Sprite cycling and (2) Player direction enum Direction { Down, @@ -79,10 +93,12 @@ private: bool groundCollision; // Keeps track of whether or not the player has collided with the ground bool crateTopCollision; // Whether the player is standing on top of a crate - int ammo; - int max_ammo = 100; - float firingRate= 0.2f; // Delay in seconds + uint8_t ammo; // Current ammo of the player + uint8_t max_ammo = 100; // Max ammo of the player + float firingRate= 0.2f; // Delay in seconds double prevShot; // The last time the player fired a bullet + uint8_t health; // Current health of the player + uint8_t max_health = 10; // Max health of the player void applyGravity() { @@ -278,6 +294,7 @@ private: { if (this->texture.getPosition().y > StateService::getInstance().getScreenSize().y) { + this->health = 0; GameService::getInstance().setGameOver(true); AudioService::getInstance().setMusic(EMusic::GAME_OVER); AudioService::getInstance().playMusic(); @@ -335,14 +352,18 @@ private: if (InputService::getInstance().isMouseButtonDown(MOUSE_BUTTON_LEFT) && GetTime() - prevShot > firingRate && groundCollision) { prevShot = GetTime(); - if (ammo == 0) { + if (ammo == 0 || (GameService::getInstance().getMouseWorldPos().x > (this->texture.getPosition().x - this->gunLeft.getSize().x/2.0f) && spriteAnimation.y == Left) || + (GameService::getInstance().getMouseWorldPos().x < (this->texture.getPosition().x + this->texture.getSize().x + gunLeft.getSize().x/2.0f) && spriteAnimation.y == Right)) + { // Play empty gun sound + AssetService::getInstance().playSound(ESound::NO_AMMO); return; } // Play shooting sound + AssetService::getInstance().playSound(ESound::SHOOT); ammo--; - Vector2 bulletStartLocation = {this->texture.getPosition().x + 10, this->texture.getPosition().y + 10}; + Vector2 bulletStartLocation = {this->texture.getPosition().x + 10, this->texture.getPosition().y + 10}; Vector2 mouseWorldPos = GameService::getInstance().getMouseWorldPos(); if (spriteAnimation.y == Left) @@ -353,7 +374,7 @@ private: if (spriteAnimation.y == Right) { bulletStartLocation.y = this->texture.getPosition().y + 10; - bulletStartLocation.x = this->texture.getPosition().x + 37; + bulletStartLocation.x = this->texture.getPosition().x + 22; } if (mouseWorldPos.x > this->texture.getPosition().x + (this->gunLeft.getSize().x) && spriteAnimation.y == Right || diff --git a/include/enums/ESound.h b/include/enums/ESound.h new file mode 100644 index 0000000..0f0aa6a --- /dev/null +++ b/include/enums/ESound.h @@ -0,0 +1,17 @@ +#ifndef ESOUND_H +#define ESOUND_H + +enum class ESound { + SHOOT, + NO_AMMO, + CRATE_BREAK, + JELLY_FREED, + HEAL_PICKUP, + AMMO_PICKUP, + POWERUP, + PLAYER_DAMAGE, + ENEMY_DEFEATED, + VICTORY +}; + +#endif \ No newline at end of file diff --git a/include/services/AssetService.h b/include/services/AssetService.h index 5eec69e..42080cf 100644 --- a/include/services/AssetService.h +++ b/include/services/AssetService.h @@ -10,6 +10,7 @@ #include "enums/EBackground.h" #include "enums/EMap.h" #include "enums/ESprite.h" +#include "enums/ESound.h" #include "services/Service.h" class AssetService: public Service @@ -32,6 +33,10 @@ public: return this->sprites[sprite]; } + void playSound(ESound sound) { + PlaySound(sounds[sound]); + } + protected: AssetService(); @@ -41,7 +46,7 @@ private: std::string assetDir; std::unordered_map fonts; - std::vector sounds; + std::unordered_map sounds; std::unordered_map music; std::unordered_map backgrounds; std::unordered_map maps; diff --git a/include/services/CollectableService.h b/include/services/CollectableService.h new file mode 100644 index 0000000..b391848 --- /dev/null +++ b/include/services/CollectableService.h @@ -0,0 +1,184 @@ +#ifndef COLLECTABLE_SERVICE_H +#define COLLECTABLE_SERVICE_H + +#include "raylib.h" +#include "services/Service.h" +#include "services/MapService.h" +#include "entities/Vector2i.h" +#include "entities/Crate.h" +#include "entities/PBullet.h" +#include + +class CollectableService : public Service +{ +public: + void initCollectables() + { + initCrates(); + } + + void collectableLogic() + { + crateLogic(); + } + + void drawCollectables() + { + drawCrates(); + } + + // void checkCratesForCollision(PBullet bullet) + // { + // for (auto it = crates.begin(); it != crates.end();) + // { + // auto &crate = *it; + // // if (*it % 2 == 0) { + // if (crate.bulletCollision(bullet)) + // { + // Vector2 pos = crate.getObject().getPosition(); + // Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize()); + // MapService::getInstance().getMap().updateColmapTile(tilePos, false); + // it = crates.erase(it); // erase returns the next iterator + // } + // else + // { + // ++it; + // } + // } + // } + + std::vector& getCrates() { + return this->crates; + } + +private: + void initCrates() + { + crates.clear(); + Vector2 location; + int tileSize = MapService::getInstance().getMap().getTileSize(); + for (int i = 0; i < 3; i++) + { + crates.push_back(Crate()); + // crateLocation.push_back(location); + } + crates[0].getObject().setPosition({38.0f * tileSize, 9.0f * tileSize}); + crates[1].getObject().setPosition({41.0f * tileSize, 5.0f * tileSize}); + crates[2].getObject().setPosition({68.0f * tileSize, 4.0f * tileSize}); + + for (int i = 0; i < crates.size(); i++) + { + Vector2i crateTilePos = Vector2i(crates[i].getObject().getPosition().x / tileSize, crates[i].getObject().getPosition().y / tileSize); + MapService::getInstance().getMap().updateColmapTile(crateTilePos, true); + } + // crates[0].y = 9 * tileSize; + + // crateLocation[1].x = 41 * tileSize; + // crateLocation[1].y = 5 * tileSize; + + // crateLocation[2].x = 68 * tileSize; + // crateLocation[2].y = 4 * tileSize; + } + + void initJellies() + { + } + + void crateLogic() + { + for (auto it = crates.begin(); it != crates.end();) + { + auto &crate = *it; + /** + * If the crate has been hit: + * 1. Remove the collision tile from the collision map + * + */ + if (crate.hasBeenHit()) + { + Vector2 pos = crate.getObject().getPosition(); + Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize()); + MapService::getInstance().getMap().updateColmapTile(tilePos, false); + it = crates.erase(it); + } + else + { + ++it; + } + } + } + + // void destroyCrate(int index) { + // Vector2 pos = crates[index].getObject().getPosition(); + // Vector2i tilePos = Vector2i(pos.x/MapService::getInstance().getMap().getTileSize(), pos.y/MapService::getInstance().getMap().getTileSize()); + // MapService::getInstance().getMap().updateColmapTile(tilePos, false); + // crates.erase(crates.begin() + index); + // } + + // void checkCratesForCollision(PBullet bullet) + // { + // for (auto it = crates.begin(); it != crates.end();) + // { + // auto &crate = *it; + // // if (*it % 2 == 0) { + // if (crate.bulletCollision(bullet)) + // { + // Vector2 pos = crate.getObject().getPosition(); + // Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize()); + // MapService::getInstance().getMap().updateColmapTile(tilePos, false); + // it = crates.erase(it); // erase returns the next iterator + // } + // else + // { + // ++it; + // } + // } + // } + + void jellyLogic() + { + } + + void drawCrates() + { + for (int i = 0; i < crates.size(); i++) + { + crates[i].draw(); + } + } + + void drawJellies() + { + } + + void drawHudJellies() + { + } + + void drawAmmoPacks() + { + } + + void drawHealthpacks() + { + } + + // sf::Text jelliesFreed; // Holds the text that shows how many jellies are freed + // sf::Font jelliesFreedFont; // Holds the font used for the text of the display + + // sf::Sprite jelliesFreedSprite; // Holds the sprite of the jelly in the top right corner + + // Vector2i jellyDisplayLocation; // Holds the location where the amount of jellies freed are displayed + std::vector crates; + // std::vector crateSprite; // Holds the sprites of the crates + // std::vector jellySprite; // Holds the sprites of the jellies inside the crates + // std::vector crateLocation; // Holds the locations of the crates/jellies + // std::vector velocity; // Makes sure the jellies jump when the crate is destroyed + // std::vector collision; // Keeps track of whether or not the player has collided with a crate + // std::vector crateDestroyed; // Keeps track of whether or not a crate has been destroyed + + // unsigned int totalAmntCrates; // Holds the total amount of crates + // unsigned int amntCratesDestroyed; // Holds the amount of crates that have been destroyed +}; + +#endif \ No newline at end of file diff --git a/include/services/GameService.h b/include/services/GameService.h index dcf1ebd..75e3190 100644 --- a/include/services/GameService.h +++ b/include/services/GameService.h @@ -47,6 +47,11 @@ public: Vector2 mouseWorldPos = {GetMousePosition().x + camera.target.x - camera.offset.x, GetMousePosition().y}; return mouseWorldPos; } + + Vector2 toWorldPos(Vector2i pixelPos) { + Vector2 worldPos = {(float)pixelPos.x + camera.target.x - camera.offset.x, (float)pixelPos.y}; + return worldPos; + } // void setGame(Game game) { // this->game = game; // } diff --git a/scripts/build_and_run_project.sh b/scripts/build_and_run_project.sh index 96d0c67..4a2e7ed 100755 --- a/scripts/build_and_run_project.sh +++ b/scripts/build_and_run_project.sh @@ -1,6 +1,8 @@ #!/bin/bash clear # g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -g++ $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 +# g++ -std=c++20 $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 +g++ -std=c++20 -g -O0 $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + # g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -./dist/jelly_rescue +gdb dist/jelly_rescue diff --git a/src/services/AssetService.cpp b/src/services/AssetService.cpp index 7a75245..80e75d6 100644 --- a/src/services/AssetService.cpp +++ b/src/services/AssetService.cpp @@ -20,6 +20,13 @@ void AssetService::setAssets() music[EMusic::GAME_OVER] = loadMusic("Audio/Music/gameOverTheme_2.ogg", false); /** Todo: set volume */ + sounds[ESound::SHOOT] = loadSound("Audio/Sounds/gunShot.wav"); + SetSoundVolume(sounds[ESound::SHOOT], 0.4f); + sounds[ESound::NO_AMMO] = loadSound("Audio/Sounds/outOfAmmo.wav"); + sounds[ESound::CRATE_BREAK] = loadSound("Audio/Sounds/crateBreak.wav"); + SetSoundVolume(sounds[ESound::CRATE_BREAK], 1.0f); + sounds[ESound::JELLY_FREED] = loadSound("Audio/Sounds/jellyFreed.wav"); + backgrounds[EBackground::TUTORIAL] = loadTexture("Textures/TutorialBackground2.png"); backgrounds[EBackground::GAME1] = loadTexture("Textures/GameBackground_1.png"); backgrounds[EBackground::GAME2] = loadTexture("Textures/GameBackground_2.jpg"); diff --git a/src/services/StateService.cpp b/src/services/StateService.cpp index 8115e18..40e3ead 100644 --- a/src/services/StateService.cpp +++ b/src/services/StateService.cpp @@ -1,13 +1,13 @@ -#include "services/StateService.h" #include "raylib.h" +#include "services/StateService.h" +#include "services/AudioService.h" +#include "services/InputService.h" #include "screens/TitleScreen.h" #include "screens/MainScreen.h" #include "screens/TutorialScreen.h" #include "screens/GameScreen.h" #include "screens/GameOverScreen.h" #include -#include "services/AudioService.h" -#include "services/InputService.h" void StateService::setScreen(EScreen state) { @@ -45,7 +45,7 @@ void StateService::startGame() { // if(!instance) // return; - // InitAudioDevice(); + InitAudioDevice(); // InitWindow(640,544, "Jelly Rescue"); InitWindow(screenSize.x, screenSize.y, "Jelly Rescue"); SetTargetFPS(45); @@ -75,7 +75,7 @@ void StateService::startGame() #endif CloseWindow(); - // CloseAudioDevice(); + CloseAudioDevice(); } void StateService::handleMusic()