Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:X-R-G-B/R-Bus into feature/RB-54-col…
Browse files Browse the repository at this point in the history
…lision-system
  • Loading branch information
KitetsuK committed Sep 28, 2023
2 parents 4e3dd9a + 8f5f564 commit 8e92681
Show file tree
Hide file tree
Showing 24 changed files with 1,674 additions and 154 deletions.
11 changes: 9 additions & 2 deletions scripts/install-deps-windows.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/bin/pwsh
# Install deps

winget install --accept-package-agreements --accept-source-agreements LLVM -e
winget install --accept-package-agreements --accept-source-agreements CMake -e
winget list -e LLVM
if ($LASTEXITCODE -ne 0) {
winget install --accept-package-agreements --accept-source-agreements LLVM -e
}

winget list -e CMake
if ($LASTEXITCODE -ne 0) {
winget install --accept-package-agreements --accept-source-agreements CMake -e
}
1 change: 1 addition & 0 deletions src/Client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ target_sources(
)

add_subdirectory(Systems)
add_subdirectory(Raylib)
add_subdirectory(EventManager)
7 changes: 3 additions & 4 deletions src/Client/EventManager/EventManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include "EventManager.hpp"
#include <algorithm>
#include "raylib.h"
#include "Events.hpp"

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
Expand All @@ -23,18 +22,18 @@ void EventManager::updateEvents()
{
_activeEvents.clear();
for (auto event : Events::events) {
if (IsKeyDown(event)) {
if (Raylib::isKeyDown(event)) {
_activeEvents.push_back(event);
}
}
}

bool EventManager::checkEvent(int event)
bool EventManager::checkEvent(Raylib::KeyboardKey event)
{
return std::any_of(
_activeEvents.begin(),
_activeEvents.end(),
[event](int e) {
[event](Raylib::KeyboardKey e) {
return e == event;
});
}
5 changes: 3 additions & 2 deletions src/Client/EventManager/EventManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
#pragma once

#include <vector>
#include "Raylib.hpp"

class EventManager {
public:
static EventManager &getInstance();
void updateEvents();
bool checkEvent(int event);
bool checkEvent(Raylib::KeyboardKey event);

private:
EventManager() = default;

// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
static EventManager instance;
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
std::vector<int> _activeEvents;
std::vector<Raylib::KeyboardKey> _activeEvents;
};
12 changes: 6 additions & 6 deletions src/Client/EventManager/Events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

#include <array>
#include <vector>
#include "raylib.h"
#include "Raylib.hpp"

namespace Events {
static constexpr auto events = {
KEY_LEFT,
KEY_RIGHT,
KEY_UP,
KEY_DOWN,
static const auto events = {
Raylib::KeyboardKey::KB_LEFT,
Raylib::KeyboardKey::KB_RIGHT,
Raylib::KeyboardKey::KB_UP,
Raylib::KeyboardKey::KB_DOWN,
};
}
190 changes: 190 additions & 0 deletions src/Client/Raylib/Audio/Audio.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** Audio
*/

#include "Audio.hpp"

namespace Raylib {

// Audio device management functions

void initAudioDevice()
{
InitAudioDevice();
}

void closeAudioDevice()
{
CloseAudioDevice();
}

bool isAudioDeviceReady()
{
return IsAudioDeviceReady();
}

void setMasterVolume(float volume)
{
SetMasterVolume(volume);
}

// Sounds
Sound::Sound(const std::string& fileName, float volume)
: _sound(LoadSound(fileName.c_str())),
_path(fileName)
{
SetSoundVolume(_sound, volume);
}

void Sound::unload()
{
UnloadSound(_sound);
}

void Sound::play() const
{
PlaySound(_sound);
}

void Sound::stop() const
{
StopSound(_sound);
}

void Sound::pause() const
{
PauseSound(_sound);
}

void Sound::resume() const
{
ResumeSound(_sound);
}

bool Sound::isPlaying() const
{
return IsSoundPlaying(_sound);
}

void Sound::setVolume(float volume) const
{
SetSoundVolume(_sound, volume);
}

void Sound::setPitch(float pitch) const
{
SetSoundPitch(_sound, pitch);
}

void Sound::setPan(float pan) const
{
SetSoundPitch(_sound, pan);
}

bool Sound::NeedToPlay() const
{
return _needToPlay;
}

void Sound::setNeedToPlay(bool needToPlay)
{
_needToPlay = needToPlay;
}

std::string Sound::getPath() const
{
return _path;
}

// Music

Music::Music(const std::string& fileName, float volume)
: _music(LoadMusicStream(fileName.c_str())),
_path(fileName)
{
SetMusicVolume(_music, volume);
}

void Music::unload()
{
UnloadMusicStream(_music);
}

bool Music::isReady() const
{
return IsMusicStreamPlaying(_music);
}

void Music::play() const
{
PlayMusicStream(_music);
}

bool Music::isPlaying() const
{
return IsMusicStreamPlaying(_music);
}

void Music::update() const
{
UpdateMusicStream(_music);
}

void Music::stop() const
{
StopMusicStream(_music);
}

void Music::pause() const
{
PauseMusicStream(_music);
}

void Music::resume() const
{
ResumeMusicStream(_music);
}

void Music::setVolume(float volume) const
{
SetMusicVolume(_music, volume);
}

void Music::setPitch(float pitch) const
{
SetMusicPitch(_music, pitch);
}

void Music::setPan(float pan) const
{
SetMusicPitch(_music, pan);
}

float Music::getTimeLength() const
{
return GetMusicTimeLength(_music);
}

float Music::getTimePlayed() const
{
return GetMusicTimePlayed(_music);
}

bool Music::NeedToPlay() const
{
return _needToPlay;
}

void Music::setNeedToPlay(bool needToPlay)
{
_needToPlay = needToPlay;
}

std::string Music::getPath() const
{
return _path;
}
} // namespace Raylib
68 changes: 68 additions & 0 deletions src/Client/Raylib/Audio/Audio.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** Audio
*/

#pragma once

#include <string>
#include "raylib.h"

namespace Raylib {
// Audio device management functions
void initAudioDevice();
void closeAudioDevice();
bool isAudioDeviceReady();
void setMasterVolume(float volume);

// Sounds
class Sound {
public:
Sound(const std::string& fileName, float volume = 0.5f);
void unload();
void play() const;
void stop() const;
void pause() const;
void resume() const;
bool isPlaying() const;
void setVolume(float volume) const;
void setPitch(float pitch) const;
void setPan(float pan) const;
bool NeedToPlay() const;
void setNeedToPlay(bool needToPlay);
std::string getPath() const;

private:
::Sound _sound;
bool _needToPlay {false};
std::string _path;
};

class Music {
public:
Music(const std::string& fileName, float volume = 0.5f);
void unload();
bool isReady() const;
void play() const;
bool isPlaying() const;
void update() const;
void stop() const;
void pause() const;
void resume() const;
void setVolume(float volume) const;
void setPitch(float pitch) const;
void setPan(float pan) const;
float getTimeLength() const;
float getTimePlayed() const;
bool NeedToPlay() const;
void setNeedToPlay(bool needToPlay);
std::string getPath() const;

private:
::Music _music;
bool _needToPlay {false};
std::string _path;
};
} // namespace Raylib
13 changes: 13 additions & 0 deletions src/Client/Raylib/Audio/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

target_sources(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/Audio.cpp
)
12 changes: 12 additions & 0 deletions src/Client/Raylib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

add_subdirectory(Geometry)
add_subdirectory(Graphics)
add_subdirectory(Audio)
add_subdirectory(Events)
7 changes: 7 additions & 0 deletions src/Client/Raylib/Events/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)

target_include_directories(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
Loading

0 comments on commit 8e92681

Please sign in to comment.