Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rt 74 sound library plugin #83

Merged
merged 13 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ if(MSVC)
endif()

file(COPY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${CMAKE_BINARY_DIR}/bin)
file(COPY ${CMAKE_SOURCE_DIR}/config DESTINATION ${CMAKE_BINARY_DIR}/bin)

# set the startup project for the "play" button in MSVC
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT server)
Expand Down Expand Up @@ -94,5 +95,6 @@ else()
endif()

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets" DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/config" DESTINATION ${CMAKE_INSTALL_BINDIR})

include(CPack)
Binary file added assets/sounds/bot_explosion.mp3
Binary file not shown.
Binary file added assets/sounds/enemy_explosion.mp3
Binary file not shown.
Binary file added assets/sounds/pew.mp3
Binary file not shown.
Binary file added assets/sounds/pew.ogg
Binary file not shown.
Binary file added assets/sounds/rtype.mp3
Binary file not shown.
Binary file added assets/sounds/shot.mp3
Binary file not shown.
9 changes: 6 additions & 3 deletions src/client/main.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#include <SFML/Graphics/Rect.hpp>
#include <iostream>
#include "AddEntity.hpp"
#include "ClientGameEvent.hpp"
#include "Components.hpp"
#include "EwECS/Asset/AssetManager.hpp"
#include "EwECS/Event/EventManager.hpp"
#include "EwECS/EwECS.hpp"
#include "EwECS/Logger.hpp"
#include "EwECS/Music/MusicPlugin.hpp"
#include "EwECS/Network/ClientHandler.hpp"
#include "EwECS/Network/Packet.hpp"
#include "EwECS/Physic/PhysicPlugin.hpp"
#include "EwECS/SFMLDisplayClass/RenderPlugin.hpp"
#include "EwECS/Sound/SoundPlugin.hpp"
#include "EwECS/Utils.hpp"
#include "EwECS/World.hpp"
#include "IsAlive.hpp"
Expand Down Expand Up @@ -54,6 +53,8 @@ int main(int ac, char **av)
ECS::Render::RenderPlugin renderPlugin;
ECS::Asset::AssetManager &assetManager = ECS::Asset::AssetManager::getInstance();
ECS::Physic::PhysicPlugin physicPlugin;
ECS::SoundPlugin soundPlugin;
ECS::MusicPlugin musicPlugin;

// Graphic systems plug

Expand All @@ -66,6 +67,8 @@ int main(int ac, char **av)
ECS::Render::RenderPluginConfig::getInstance().load("config/r-type.json");
physicPlugin.plug(world, assetManager);
renderPlugin.plug(world, assetManager);
soundPlugin.plug(world, assetManager);
musicPlugin.plug(world, assetManager);

// Background systems
world.addSystem(ECS::System::createBackground);
Expand Down
1 change: 1 addition & 0 deletions src/client/systems/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Components.hpp"
#include "EwECS/Event/KeyboardEvent.hpp"
#include "EwECS/Event/WindowEvent.hpp"
#include "EwECS/Music/MusicComponent.hpp"
#include "EwECS/Physic/HitBox.hpp"
#include "EwECS/SFMLDisplayClass/LoadedSprite.hpp"
#include "EwECS/SparseArray.hpp"
Expand Down
10 changes: 6 additions & 4 deletions src/client/systems/background/System+CreateBackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ namespace ECS {
if (payload.isReceiver) {
world.killEntity(0);
try {
AddEntity::addEntity(ECS::Utils::Vector2f {0, 0}, Component::Speed {BACKGROUND_SPEED},
Component::TypeEntity {false, false, false, false, false, false, true},
Component::LoadedSprite {"config/background.json"}, Component::HitBox {},
Component::IsAlive {false, 0});
auto idx =
AddEntity::addEntity(ECS::Utils::Vector2f {0, 0}, Component::Speed {BACKGROUND_SPEED},
Component::TypeEntity {false, false, false, false, false, false, true},
Component::LoadedSprite {"config/background.json"}, Component::HitBox {},
Component::IsAlive {false, 0});
AddEntity::addEntity(ECS::Utils::Vector2f {SCREEN_WIDTH, 0}, Component::Speed {BACKGROUND_SPEED},
Component::TypeEntity {false, false, false, false, false, false, true},
Component::LoadedSprite {"config/background2.json"}, Component::HitBox {},
Component::IsAlive {false, 0});
world.emplaceEntityComponent<Component::MusicComponent>(idx, "assets/sounds/rtype.mp3", 100, true);
} catch (const std::exception &e) {
ECS::Logger::error("[RType client exception] " + std::string(e.what()));
}
Expand Down
1 change: 0 additions & 1 deletion src/client/systems/bot/System+TriggerBotDeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace ECS {
Core::SparseArray<Component::LoadedSprite> &aSprites)
{
auto &world = Core::World::getInstance();
auto &display = SFMLDisplayClass::getInstance();
Event::EventManager *eventManager = Event::EventManager::getInstance();
auto &events = eventManager->getEventsByType<RType::ClientGameEvent>();
std::vector<size_t> toRemove;
Expand Down
6 changes: 5 additions & 1 deletion src/client/systems/bot/System+TriggerBotShoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "EwECS/Event/EventManager.hpp"
#include "EwECS/Logger.hpp"
#include "EwECS/SFMLDisplayClass/SFMLDisplayClass.hpp"
#include "EwECS/Sound/Sound.hpp"
#include "EwECS/Sound/SoundComponent.hpp"
#include "EwECS/SparseArray.hpp"
#include "EwECS/World.hpp"
#include "IsAlive.hpp"
Expand All @@ -18,6 +20,7 @@ namespace ECS {
auto &events = eventManager->getEventsByType<RType::ClientGameEvent>();
std::vector<size_t> toRemove;
const auto size = events.size();
auto &world = Core::World::getInstance();

for (size_t i = 0; i < size; i++) {
auto &gameEvent = events[i];
Expand All @@ -29,11 +32,12 @@ namespace ECS {
const auto &payload = gameEvent.getPayload<RType::Server::PlayerShotPayload>();

try {
AddEntity::addEntity(
auto entity_id = AddEntity::addEntity(
ECS::Utils::Vector2f {payload.posX, payload.posY}, Component::Speed {BULLET_SPEED},
Component::TypeEntity {false, false, false, true, false, false, false, payload.bulletId, false},
Component::LoadedSprite {"config/missiles.json"},
Component::HitBox {BULLET_TEX_WIDTH, BULLET_TEX_HEIGHT}, Component::IsAlive {false, 0});
world.emplaceEntityComponent<Component::SoundComponent>(entity_id, "assets/sounds/pew.mp3", 40, false);
} catch (const std::exception &e) {
ECS::Logger::error("[RType client exception] " + std::string(e.what()));
}
Expand Down
5 changes: 4 additions & 1 deletion src/client/systems/enemy/System+TriggerEnemyDeath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "EwECS/Event/EventManager.hpp"
#include "EwECS/Logger.hpp"
#include "EwECS/SFMLDisplayClass/SFMLDisplayClass.hpp"
#include "EwECS/Sound/SoundComponent.hpp"
#include "EwECS/World.hpp"
#include "IsAlive.hpp"
#include "SFML/Graphics/Rect.hpp"
Expand Down Expand Up @@ -44,12 +45,14 @@ namespace ECS {

if (aPos[localEnemyId].has_value()) {
try {
AddEntity::addEntity(
auto idx = AddEntity::addEntity(
ECS::Utils::Vector2f {aPos[localEnemyId].value().x, aPos[localEnemyId].value().y},
Component::Speed {BONUS_SPEED},
Component::TypeEntity {false, false, false, false, false, true, false, payload.bonusId, false},
Component::LoadedSprite {"config/bonus.json"},
Component::HitBox {BONUS_TEX_WIDTH, BONUS_TEX_HEIGHT}, Component::IsAlive {false, 0});
world.emplaceEntityComponent<Component::SoundComponent>(idx, "assets/sounds/enemy_explosion.mp3",
20, false);
} catch (const std::exception &e) {
ECS::Logger::error("[RType client exception] " + std::string(e.what()));
}
Expand Down
6 changes: 4 additions & 2 deletions src/client/systems/enemy/System+TriggerEnemyShoot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "EwECS/Event/EventManager.hpp"
#include "EwECS/Logger.hpp"
#include "EwECS/SFMLDisplayClass/SFMLDisplayClass.hpp"
#include "EwECS/SparseArray.hpp"
#include "EwECS/Sound/SoundComponent.hpp"
#include "EwECS/World.hpp"
#include "IsAlive.hpp"
#include "ServerPackets.hpp"
Expand All @@ -18,6 +18,7 @@ namespace ECS {
auto &events = eventManager->getEventsByType<RType::ClientGameEvent>();
const auto size = events.size();
std::vector<size_t> toRemove;
auto &world = Core::World::getInstance();

for (size_t i = 0; i < size; i++) {
auto &gameEvent = events[i];
Expand All @@ -28,11 +29,12 @@ namespace ECS {
const auto &payload = gameEvent.getPayload<RType::Server::EnemyShotPayload>();

try {
AddEntity::addEntity(
auto idx = AddEntity::addEntity(
ECS::Utils::Vector2f {payload.posX, payload.posY}, Component::Speed {MISSILES_SPEED},
Component::TypeEntity {false, false, false, false, false, false, false, payload.bulletId, true},
Component::LoadedSprite {"config/bullet.json"},
Component::HitBox {MISSILES_TEX_WIDTH, MISSILES_TEX_HEIGHT}, Component::IsAlive {false, 0});
world.emplaceEntityComponent<Component::SoundComponent>(idx, "assets/sounds/shot.mp3", 20, false);
} catch (const std::exception &e) {
ECS::Logger::error("[RType client exception] " + std::string(e.what()));
}
Expand Down
2 changes: 0 additions & 2 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ int main(int ac, char **av)
ECS::Asset::AssetManager &assetManager = ECS::Asset::AssetManager::getInstance();

// Components
world.registerComponent<ECS::Utils::Vector2f>();
world.registerComponent<Component::Speed>();
world.registerComponent<Component::TypeEntity>();
world.registerComponent<Component::IsAlive>();
world.registerComponent<Component::Connection>();

ECS::Physic::PhysicPlugin physicPlugin;

Expand Down