Skip to content

Commit

Permalink
Merge branch 'dev' into doc/RB-64-Raylib-encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
TTENSHII committed Oct 2, 2023
2 parents 39df1e4 + 5115a4e commit 95e4fb9
Show file tree
Hide file tree
Showing 14 changed files with 471 additions and 251 deletions.
3 changes: 3 additions & 0 deletions src/Client/Systems/ClientSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/

#include "ClientSystems.hpp"
#include "EventsSystems.hpp"
#include "GraphicSystems.hpp"
#include "Systems.hpp"

namespace Systems {
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 3>
Expand Down
6 changes: 3 additions & 3 deletions src/Client/Systems/ClientSystems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#pragma once

#include <array>
#include "EventsSystems.hpp"
#include "GraphicSystems.hpp"
#include "Systems.hpp"
#include <cstddef>
#include <functional>
#include <vector>

namespace Systems {
std::array<std::vector<std::function<void(std::size_t, std::size_t)>>, 3>
Expand Down
31 changes: 31 additions & 0 deletions src/Client/Systems/CustomTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <string>
#include <vector>
#include "ECSCustomTypes.hpp"

namespace Types {
Expand All @@ -19,4 +20,34 @@ namespace Types {
float height;
};

enum RectListType { DEFAULTRECT, MOVE, ATTACK, DEAD };

struct AnimRect {
public:
AnimRect(
Rect rect,
std::vector<Rect> _moveRects,
std::vector<Rect> _attackRects = {},
std::vector<Rect> _deadRects = {})
: defaultRect(rect),
moveRects(_moveRects),
attackRects(_attackRects),
deadRects(_deadRects),
currentRectInList(0),
currentRectList(Types::RectListType::DEFAULTRECT)
{
}
Rect defaultRect;
std::vector<Rect> moveRects;
std::vector<Rect> attackRects;
std::vector<Rect> deadRects;
RectListType currentRectList;
std::size_t currentRectInList;
void changeRectList(RectListType type = RectListType::DEFAULTRECT)
{
currentRectList = type;
currentRectInList = 0;
}
};

} // namespace Types
17 changes: 17 additions & 0 deletions src/Client/Systems/Events/EventsSystems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@
#include "SceneManager.hpp"

namespace Systems {
static void checkAnimRect(std::size_t id)
{
Registry::components<Types::AnimRect> arrAnimRect =
Registry::getInstance().getComponents<Types::AnimRect>();

if (arrAnimRect.exist(id)) {
Types::AnimRect &anim = arrAnimRect[id];
if (anim.currentRectList != Types::RectListType::MOVE) {
anim.changeRectList(Types::RectListType::MOVE);
}
}
}

void EventsSystems::playerMovement(
std::size_t /*unused*/,
std::size_t /*unused*/)
Expand All @@ -24,15 +37,19 @@ namespace Systems {

for (std::size_t id : playerId) {
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT)) {
checkAnimRect(id);
arrPosition[id].x += 1;
}
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT)) {
checkAnimRect(id);
arrPosition[id].x -= 1;
}
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_UP)) {
checkAnimRect(id);
arrPosition[id].y -= 1;
}
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_DOWN)) {
checkAnimRect(id);
arrPosition[id].y += 1;
}
}
Expand Down
80 changes: 80 additions & 0 deletions src/Client/Systems/Graphic/AudioSystems.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** AudioSystems implementation
*/

#include "AudioSystems.hpp"
#include "CustomTypes.hpp"
#include "Raylib.hpp"

namespace Systems {
void GraphicSystems::soundEffectPlayer(
std::size_t /*unused*/,
std::size_t /*unused*/)
{
Registry::components<Raylib::Sound> arrSoundEffect =
Registry::getInstance().getComponents<Raylib::Sound>();

for (auto &soundEffect : arrSoundEffect) {
if (soundEffect.NeedToPlay()) {
soundEffect.play();
soundEffect.setNeedToPlay(false);
}
}
}

void
GraphicSystems::musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/)
{
Registry::components<Raylib::Music> arrMusics =
Registry::getInstance().getComponents<Raylib::Music>();

for (auto &music : arrMusics) {
if (music.NeedToPlay()) {
music.play();
music.setNeedToPlay(false);
}
if (music.isPlaying()) {
music.update();
}
}
}

const std::string musicPath = "assets/Audio/Musics/Title.mp3";
const std::string soundPath = "assets/Audio/Sounds/fire.ogg";
const std::string playerPath = "assets/R-TypeSheet/r-typesheet14.gif";
const Types::Rect spriteRect = {2, 2, 48, 48};
const Types::CollisionRect collisionRect = {46, 46};
const Raylib::Vector2 textPos = {20, 50};

void GraphicSystems::playSoundWithKey(
std::size_t /*unused*/,
std::size_t /*unused*/)
{
Registry &registry = Registry::getInstance();
Registry::components<Raylib::Music> arrMusics =
registry.getComponents<Raylib::Music>();
Registry::components<Raylib::Sound> arrSounds =
registry.getComponents<Raylib::Sound>();

for (auto &music : arrMusics) {
if (music.getPath() == musicPath
&& Raylib::isKeyPressed(Raylib::KeyboardKey::KB_SPACE)) {
music.setNeedToPlay(true);
}
}
for (auto &sound : arrSounds) {
if (sound.getPath() == soundPath
&& Raylib::isKeyPressed(Raylib::KeyboardKey::KB_ENTER)) {
sound.setNeedToPlay(true);
}
}
}
std::vector<std::function<void(std::size_t, std::size_t)>>
GraphicSystems::getAudioSystems()
{
return {soundEffectPlayer, musicPlayer, playSoundWithKey};
}
} // namespace Systems
22 changes: 22 additions & 0 deletions src/Client/Systems/Graphic/AudioSystems.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
** EPITECH PROJECT, 2023
** R-Bus
** File description:
** AudioSystems
*/

#pragma once

#include <cstddef>
#include <functional>
#include <vector>

namespace Systems {
namespace GraphicSystems {
void soundEffectPlayer(std::size_t /*unused*/, std::size_t /*unused*/);
void musicPlayer(std::size_t /*unused*/, std::size_t /*unused*/);
void playSoundWithKey(std::size_t, std::size_t);
std::vector<std::function<void(std::size_t, std::size_t)>>
getAudioSystems();
} // namespace GraphicSystems
} // namespace Systems
3 changes: 3 additions & 0 deletions src/Client/Systems/Graphic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ target_sources(
${PROJECT_NAME_CLIENT}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/GraphicSystems.cpp
${CMAKE_CURRENT_SOURCE_DIR}/AudioSystems.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SpriteSystems.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TextSystems.cpp
)
Loading

0 comments on commit 95e4fb9

Please sign in to comment.