diff options
Diffstat (limited to '')
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/gameplay.cpp | 7 | ||||
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | src/weapon.cpp | 15 | ||||
| -rw-r--r-- | src/weapon.hpp | 18 | ||||
| -rw-r--r-- | src/window.cpp | 1 | 
6 files changed, 38 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a600f0..8f2d3cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ add_executable(${PROJECT_NAME}      src/main.cpp      src/window.cpp      src/gameplay.cpp +    src/weapon.cpp      src/entity.cpp)  target_link_libraries(${PROJECT_NAME} raylib m pthread dl) diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 59ef73a..de8dd88 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -11,6 +11,8 @@  #include "raymath.h"  #include <fstream> +#include "weapon.hpp" +  Game::Game(std::string const & path)  {      std::ifstream ifs(path); @@ -47,6 +49,9 @@ Game::Game(std::string const & path)      player->direction.y = 100;      player->radius = 10;      player->victims = 0; +    player->wp = new Weapon(10, 10, +            "../meta/media/mp3/shotty_shoot.mp3", +            "../meta/media/mp3/shotty_reload.mp3");  }  Game::~Game() @@ -167,6 +172,8 @@ Game::shoot() const          auto add1 = Vector2Add((Vector2){player->posX, player->posY}, rot1);          auto add2 = Vector2Add((Vector2){player->posX, player->posY}, rot2); + +        player->wp->bang();          for (auto en = enemies->begin(); en != enemies->end(); en++)          {              if (CheckCollisionPointLine((Vector2){en->posX, en->posY}, (Vector2){player->posX, player->posY}, add1, (en->radius * 2)) || diff --git a/src/main.cpp b/src/main.cpp index 3136318..d30878a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,7 @@ int main(void) {                  next += game->getNext();                  delete game; +                CloseAudioDevice();                  if (next != "0") {                      game = new Game(next);                  } @@ -79,15 +80,16 @@ int main(void) {          {              if (auto code = game->getKeys()) {                  if (code == 1) -                    gs = ENDING; +                {gs = ENDING;}                  else if (code == 2) -                    gs = NEXT; +                {gs = NEXT;}              }              game->draw();              break ;          }          case (NEXT):          { +            ClearBackground(RAYWHITE);              break ;          }          case (ENDING): diff --git a/src/weapon.cpp b/src/weapon.cpp index c876481..a774676 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -8,8 +8,19 @@  #include "weapon.hpp" -Weapon::Weapon(float const & rg, unsigned int const & dmg) : +Weapon::Weapon(float const & rg, unsigned int const & dmg, const char *s, const char *r) :      range(rg), damage(dmg) -{} +{ +    InitAudioDevice(); +    shot = LoadSound(s); +    reload = LoadSound(r); +    SetSoundVolume(shot, 0.3f); +    SetSoundVolume(reload, 0.3f); +}  Weapon::~Weapon() {} + +void Weapon::bang() const +{ +    PlaySound(shot); +} diff --git a/src/weapon.hpp b/src/weapon.hpp index 9a3f875..1b6b57a 100644 --- a/src/weapon.hpp +++ b/src/weapon.hpp @@ -9,12 +9,20 @@  #ifndef WEAPON_H_  #define WEAPON_H_ +#include "raylib.h" +  class Weapon { -    public: -        float const & range; -        unsigned int const & damage; -        Weapon(float const & rg, unsigned int const & dmg); -        ~Weapon(); +  Sound shot; +  Sound reload; + +  float const ⦥ +  unsigned int const &damage; + +public: +  Weapon(float const &rg, unsigned int const &dmg, const char *s, const char *r); +  ~Weapon(); + +  void bang() const ;  };  #endif // WEAPON_H_ diff --git a/src/window.cpp b/src/window.cpp index 0a51470..b3b8a8e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -12,7 +12,6 @@ int  initWindow(void) {      // Initialization      InitWindow(SCREENWIDTH, SCREENHEIGHT, "WIP -- coolspace"); -    InitAudioDevice();      SetTargetFPS(60);      return (0);  | 
