fix merge + convert audio ressources + add sounds/music to scenes

This commit is contained in:
arthur.jamet
2021-06-09 15:21:00 +02:00
39 changed files with 900 additions and 268 deletions
+19 -9
View File
@@ -84,6 +84,16 @@ set(SOURCES
sources/Component/Animator/AnimatorComponent.hpp
sources/System/Animator/AnimatorSystem.cpp
sources/System/Animator/AnimatorSystem.hpp
sources/Component/Music/MusicComponent.cpp
sources/Component/Music/MusicComponent.hpp
sources/Component/Sound/SoundComponent.hpp
sources/Component/Sound/SoundComponent.cpp
sources/System/Sound/MenuSoundManagerSystem.cpp
sources/System/Sound/MenuSoundManagerSystem.hpp
sources/System/Sound/PlayerSoundManagerSystem.cpp
sources/System/Sound/PlayerSoundManagerSystem.hpp
sources/System/Music/MusicSystem.hpp
sources/System/Music/MusicSystem.cpp
)
add_executable(bomberman
sources/main.cpp
@@ -94,15 +104,15 @@ target_link_libraries(bomberman PUBLIC wal ray)
add_executable(unit_tests EXCLUDE_FROM_ALL
${SOURCES}
tests/EntityTests.cpp
tests/MainTest.cpp
tests/EngineTests.cpp
tests/CallbackTest.cpp
tests/MoveTests.cpp
tests/ViewTest.cpp
tests/CollisionTest.cpp
)
${SOURCES}
tests/EntityTests.cpp
tests/MainTest.cpp
tests/EngineTests.cpp
tests/CallbackTest.cpp
tests/MoveTests.cpp
tests/ViewTest.cpp
tests/CollisionTest.cpp
)
target_include_directories(unit_tests PUBLIC sources)
target_link_libraries(unit_tests PUBLIC wal ray)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
View File
@@ -55,3 +55,9 @@ RAY::Audio::Music &RAY::Audio::Music::setPitch(float pitch)
SetMusicPitch(*_music, pitch);
return *this;
}
RAY::Audio::Music &RAY::Audio::Music::updateMusicStream(void)
{
UpdateMusicStream(*_music);
return *this;
}
+2
View File
@@ -51,6 +51,8 @@ namespace RAY::Audio
// Set pitch for a Music (1.0 is base level)
Music &setPitch(float pitch) override;
Music &updateMusicStream(void);
private:
std::shared_ptr<::Music> _music;
+5
View File
@@ -42,3 +42,8 @@ void RAY::Controller::GamePad::setID(int id)
{
this->_id = id;
}
float RAY::Controller::GamePad::getAxisValue(int index)
{
return GetGamepadAxisMovement(this->_id, index);
}
+4
View File
@@ -17,6 +17,7 @@ namespace RAY::Controller {
class GamePad {
public:
typedef ::GamepadButton Button;
typedef ::GamepadAxis Axis;
//! @brief A default constructor
//! @param The id of the controller
@@ -44,6 +45,9 @@ namespace RAY::Controller {
//! @param Button The keycode of the button
bool isReleased(Button);
//! @brief Get the value of an axis
float getAxisValue(int index);
//! @brief Returns true if Button is up on the gamepad
//! @param Button The keycode of the button
bool isUp(Button);
+2
View File
@@ -50,6 +50,7 @@ bool RAY::Window::open(void)
InitWindow(this->_dimensions.x, this->_dimensions.y, this->_title.c_str());
this->_isOpen = true;
this->setExitKey(Controller::Keyboard::Key::KEY_DELETE);
InitAudioDevice();
return true;
}
@@ -61,6 +62,7 @@ bool RAY::Window::shouldClose(void) const
void RAY::Window::close(void)
{
CloseWindow();
CloseAudioDevice();
}
bool RAY::Window::isFocused(void) const
@@ -4,31 +4,54 @@
#include "Component/Collision/CollisionComponent.hpp"
namespace BBM
namespace BBM
{
CollisionComponent::CollisionComponent(WAL::Entity &entity)
: WAL::Component(entity)
{ }
: WAL::Component(entity)
{}
WAL::Component *CollisionComponent::clone(WAL::Entity &entity) const
{
return new CollisionComponent(entity);
}
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, Vector3f bound)
: WAL::Component(entity), onCollide(onCollide), onCollided(onCollided), bound(bound)
{ }
CollisionComponent::CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
Vector3f positionOffset,
Vector3f bound)
: WAL::Component(entity),
onCollide(onCollide),
onCollided(onCollided),
bound(bound),
positionOffset(positionOffset)
{}
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, float boundSize)
: WAL::Component(entity), onCollide(onCollide), onCollided(onCollided), bound({boundSize, boundSize, boundSize})
{ }
CollisionComponent::CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
float positionOffset,
float boundSize)
: WAL::Component(entity),
onCollide(onCollide),
onCollided(onCollided),
bound({boundSize, boundSize, boundSize}),
positionOffset({positionOffset, positionOffset, positionOffset})
{}
CollisionComponent::CollisionComponent(WAL::Entity &entity, Vector3f bound)
: WAL::Component(entity), onCollide(), onCollided(), bound(bound)
{ }
CollisionComponent::CollisionComponent(WAL::Entity &entity, Vector3f positionOffset, Vector3f bound)
: WAL::Component(entity),
onCollide(),
onCollided(),
bound(bound),
positionOffset(positionOffset)
{}
CollisionComponent::CollisionComponent(WAL::Entity &entity, float boundSize)
: WAL::Component(entity), onCollide(), onCollided(), bound({boundSize, boundSize, boundSize})
{ }
CollisionComponent::CollisionComponent(WAL::Entity &entity, float positionOffset, float boundSize)
: WAL::Component(entity),
onCollide(),
onCollided(),
bound({boundSize, boundSize, boundSize}),
positionOffset({positionOffset, positionOffset, positionOffset})
{}
}
@@ -9,43 +9,61 @@
#include "Component/Component.hpp"
#include "Entity/Entity.hpp"
namespace BBM
namespace BBM
{
class CollisionComponent : public WAL::Component
{
private:
public:
//! @brief onCollide functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide;
//! @brief onCollided functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided;
//! @brief Bound size on all axis
Vector3f bound;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
public:
//! @brief Used to tell the collided axis
//! @note Usage: (collidedAxis (int given by callback)) & CollidedAxis::X
enum CollidedAxis {
X = 1,
Y = 2,
Z = 4
};
//! @brief A component can't be instantiated, it should be derived.
explicit CollisionComponent(WAL::Entity &entity);
//! @brief onCollide functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollide;
//! @brief onCollided functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollided;
//! @brief Bound size on all axis
Vector3f bound;
//! @brief Offset from the position component
Vector3f positionOffset;
//! @brief Constructor with a WAL::Callback
CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided,Vector3f bound);
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
//! @brief Constructor with a WAL::Callback, same boundSize for all axis
CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, float boundSize = 0);
//! @brief A component can't be instantiated, it should be derived.
explicit CollisionComponent(WAL::Entity &entity);
//! @brief Constructor of collider with no callback
CollisionComponent(WAL::Entity &entity, Vector3f bound);
//! @brief Constructor with a WAL::Callback
CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
Vector3f positionOffset,
Vector3f bound);
//! @brief Constructor no callback, same boundSize for all axis
CollisionComponent(WAL::Entity &entity, float boundSize);
//! @brief Constructor with a WAL::Callback, same boundSize for all axis
CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
float positionOffset,
float boundSize);
//! @brief Default copy constructor
CollisionComponent(const CollisionComponent &) = default;
//! @brief Constructor of collider with no callback
CollisionComponent(WAL::Entity &entity, Vector3f positionOffset, Vector3f bound);
//! @brief default destructor
~CollisionComponent() override = default;
//! @brief Constructor no callback, same boundSize & positionOffset for all axis
CollisionComponent(WAL::Entity &entity, float positionOffset, float boundSize);
//! @brief A component can't be assigned
CollisionComponent &operator=(const CollisionComponent &) = delete;
//! @brief Default copy constructor
CollisionComponent(const CollisionComponent &) = default;
//! @brief default destructor
~CollisionComponent() override = default;
//! @brief A component can't be assigned
CollisionComponent &operator=(const CollisionComponent &) = delete;
};
}
@@ -10,6 +10,7 @@
#include "Entity/Entity.hpp"
using Button = RAY::Controller::GamePad::Button;
using Axis = RAY::Controller::GamePad::Axis;
using Gamepad = RAY::Controller::GamePad;
namespace BBM
@@ -35,6 +36,11 @@ namespace BBM
//! @brief move down key
Button keyDown = GAMEPAD_BUTTON_LEFT_FACE_DOWN;
Axis LeftStickX = GAMEPAD_AXIS_LEFT_X;
Axis LeftStickY = GAMEPAD_AXIS_LEFT_Y;
Axis RightStickX = GAMEPAD_AXIS_RIGHT_X;
Axis RightStickY = GAMEPAD_AXIS_RIGHT_Y;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
@@ -23,9 +23,9 @@ namespace BBM
//! @brief pause key
Key keyPause = RAY::Controller::Keyboard::Key::KEY_ESCAPE;
//! @brief move right key
Key keyRight = KEY_A;
Key keyRight = KEY_D;
//! @brief move left key
Key keyLeft = KEY_D;
Key keyLeft = KEY_A;
//! @brief move up key
Key keyUp = KEY_W;
//! @brief move down key
@@ -0,0 +1,65 @@
//
// Created by Tom Augier on 05/06/2021
//
#include <iostream>
#include "MusicComponent.hpp"
namespace BBM
{
float MusicComponent::volume = 0.75;
MusicComponent::MusicComponent(WAL::Entity &entity, const std::string &musicPath)
: WAL::Component(entity),
_musicPath(musicPath),
_music(RAY::Audio::Music(musicPath))
{
}
WAL::Component *MusicComponent::clone(WAL::Entity &entity) const
{
return new MusicComponent(entity, this->_musicPath);
}
void MusicComponent::playMusic(void)
{
if (!this->_music.isPlaying()) {
this->_music.play();
}
}
void MusicComponent::stopMusic(void)
{
if (this->_music.isPlaying())
this->_music.stop();
}
void MusicComponent::pauseMusic(void)
{
this->_music.pause();
}
void MusicComponent::setVolume(float &volumeUpdate)
{
if (volumeUpdate >= 0) {
this->volume = volumeUpdate;
this->_music.setVolume(this->volume);
}
}
void MusicComponent::setPitch(float &pitch)
{
this->_music.setPitch(pitch);
}
bool MusicComponent::isPlaying(void)
{
return (this->_music.isPlaying());
}
void MusicComponent::updateMusicStream(void)
{
this->_music.updateMusicStream();
}
} // namespace WAL
@@ -0,0 +1,55 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "Component/Component.hpp"
#include <map>
#include "Audio/Music.hpp"
namespace BBM
{
//! @brief A basic Music component
class MusicComponent : public WAL::Component
{
public:
//! @brief start music
void playMusic();
//! @brief stop music
void stopMusic();
//! @brief put music on hold
void pauseMusic();
//! @brief set music volume
void setVolume(float &);
//! @brief set pitch volume
void setPitch(float &);
//! @brief is music playing
bool isPlaying(void);
//! @brief update music stream
void updateMusicStream(void);
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
//! @brief Create a new MusicComponent at a certain Music
explicit MusicComponent(WAL::Entity &entity, const std::string &musicPath);
//! @brief A Music component is copy constructable
MusicComponent(const MusicComponent &) = default;
//! @brief A default destructor
~MusicComponent() override = default;
//! @brief A Music component is not assignable
MusicComponent &operator=(const MusicComponent &) = delete;
//! @brief Volume of the muisc
static float volume;
private:
//! @brief music of this entity
RAY::Audio::Music _music;
//! @brief patht to the music assets
const std::string _musicPath;
};
} // namespace BBM
@@ -0,0 +1,91 @@
//
// Created by Tom Augier on 05/06/2021
//
#include <iostream>
#include <memory>
#include "SoundComponent.hpp"
namespace BBM
{
float SoundComponent::volume = 0.75;
SoundComponent::SoundComponent(WAL::Entity &entity,
const std::map<SoundComponent::SoundIndex, std::string> &soundPath)
: WAL::Component(entity),
_soundIndex(IDLE),
_soundPath(soundPath)
{
for (int i = 0; i <= DEATH; i++) {
this->_isSoundLoad[static_cast<SoundIndex>(i)] = false;
}
for (auto &soundPath : soundPath)
{
this->_isSoundLoad[soundPath.first] = true;
this->_soundList[soundPath.first] = std::make_unique<RAY::Audio::Sound>(soundPath.second);
}
}
WAL::Component *SoundComponent::clone(WAL::Entity &entity) const
{
return new SoundComponent(entity, this->_soundPath);
}
void SoundComponent::playSound()
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return;
if (!this->_soundList[this->_soundIndex].get()->isPlaying())
this->_soundList[this->_soundIndex].get()->play();
}
void SoundComponent::stopSound()
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return;
if (this->_soundList[this->_soundIndex].get()->isPlaying())
this->_soundList[this->_soundIndex].get()->stop();
}
void SoundComponent::pauseSound()
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return;
this->_soundList[this->_soundIndex].get()->pause();
}
void SoundComponent::setVolume(float &volumeUpdate)
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return;
if (volumeUpdate >= 0) {
this->volume = volumeUpdate;
this->_soundList[this->_soundIndex].get()->setVolume(this->volume);
}
}
void SoundComponent::setPitch(float &pitch)
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return;
this->_soundList[this->_soundIndex].get()->setPitch(pitch);
}
bool SoundComponent::isPlaying()
{
if (!this->_isSoundLoad.at(this->_soundIndex))
return (false);
return (this->_soundList[this->_soundIndex].get()->isPlaying());
}
void SoundComponent::setIndex(SoundIndex index)
{
this->_soundIndex = index;
}
SoundComponent::SoundIndex SoundComponent::getIndex()
{
return (this->_soundIndex);
}
} // namespace WAL
@@ -0,0 +1,78 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "Component/Component.hpp"
#include <map>
#include "Audio/Sound.hpp"
namespace BBM
{
//! @brief A basic Sound component
class SoundComponent : public WAL::Component
{
public:
//! @brief All sounds of the player
enum SoundIndex {
IDLE,
JUMP,
BOMB,
MOVE,
HURT,
THROW,
DEATH
};
//! @brief to set what sound should be played
void setIndex(SoundIndex index);
//! @brief to know which sound is selected
SoundIndex getIndex();
//! @brief start sound
void playSound();
//! @brief stop sound
void stopSound();
//! @brief put Sound on hold
void pauseSound();
//! @brief set Sound volume
void setVolume(float &);
//! @brief set pitch volume
void setPitch(float &);
//! @brief is Sound playing
bool isPlaying();
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
//! @brief Create a new SoundComponent at a certain Sound
explicit SoundComponent(WAL::Entity &entity, const std::map<SoundIndex, std::string> &);
//! @brief A Sound component is copy constructable
SoundComponent(const SoundComponent &) = default;
//! @brief A default destructor
~SoundComponent() override = default;
//! @brief A Sound component is not assignable
SoundComponent &operator=(const SoundComponent &) = delete;
//! @brief Volume of the sounds
static float volume;
private:
//! @brief Sounds of this entity
std::map<SoundIndex, std::shared_ptr<RAY::Audio::Sound>> _soundList;
//! @brief map to know if sound is loaded
std::map<SoundIndex, bool> _isSoundLoad;
//! @brief All sounds path
const std::map<SoundIndex, std::string> _soundPath;
//! SoundIndex
SoundIndex _soundIndex;
};
} // namespace BBM
+39 -25
View File
@@ -3,7 +3,8 @@
// Edited by Benjamin Henry on 5/26/21.
//
#include <Component/Collision/CollisionComponent.hpp>
#include "Component/Collision/CollisionComponent.hpp"
#include "System/Collision/CollisionSystem.hpp"
#include "Map.hpp"
#include <iostream>
@@ -11,23 +12,20 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
void MapGenerator::wallCollide(WAL::Entity &entity, const WAL::Entity &wall)
void MapGenerator::wallCollide(WAL::Entity &entity,
const WAL::Entity &wall,
CollisionComponent::CollidedAxis collidedAxis)
{
auto *mov = entity.tryGetComponent<MovableComponent>();
if (!mov)
return;
auto &pos = entity.getComponent<PositionComponent>();
const auto &wallPos = wall.getComponent<PositionComponent>();
auto diff = pos.position + mov->getVelocity() - wallPos.position;
// mov->_velocity = Vector3f();
// if (diff.x <= 0 && mov->_velocity.x < 0)
// mov->_velocity.x = 0;
// if (diff.x >= 0 && mov->_velocity.x > 0)
// mov->_velocity.x = 0;
// if (diff.z <= 0 && mov->_velocity.z < 0)
// mov->_velocity.z = 0;
// if (diff.z >= 0 && mov->_velocity.z > 0)
// mov->_velocity.z = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::X)
mov->_velocity.x = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::Y)
mov->_velocity.x = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::Z)
mov->_velocity.z = 0;
}
void MapGenerator::wallDestroyed(WAL::Entity &entity)
@@ -58,8 +56,11 @@ namespace BBM
if (!(i % 2) && !(j % 2)) {
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(i, 0, j)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePng));
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePng));
}
}
}
@@ -72,25 +73,33 @@ namespace BBM
scene->addEntity("Bottom Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Upper Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Left Wall")
.addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(1, 1, height + 1));
scene->addEntity("Right Wall")
.addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(1, 1, height + 1));
@@ -106,7 +115,7 @@ namespace BBM
if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER)
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(Vector3f(i, -1, j))
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
std::make_pair(MAP_DIFFUSE, floorPng));
}
}
@@ -140,7 +149,9 @@ namespace BBM
scene->addEntity("Breakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng));
}
@@ -173,7 +184,9 @@ namespace BBM
scene->addEntity("Unbreakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(UnbreakableObj,
std::make_pair(MAP_DIFFUSE, UnbreakablePng));
}
@@ -192,7 +205,8 @@ namespace BBM
if (coords.y == 0)
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
else
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(secondFloorObj, std::make_pair(MAP_DIFFUSE, secondFloorPng));
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(secondFloorObj,
std::make_pair(MAP_DIFFUSE, secondFloorPng));
/*.addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
if (other.hasComponent<HealthComponent>()) {
auto &health = other.getComponent<HealthComponent>();
@@ -337,7 +351,7 @@ namespace BBM
return (map);
}
void MapGenerator::loadMap(int width, int height, MapBlock map, std::shared_ptr<WAL::Scene> scene)
void MapGenerator::loadMap(int width, int height, MapBlock map, const std::shared_ptr<WAL::Scene> &scene)
{
generateWall(width, height, scene);
generateFloor(map, width, height, scene);
+129 -124
View File
@@ -27,150 +27,155 @@ namespace BBM
class MapGenerator
{
private:
//! @brief Enum of the block available.
enum BlockType {
NOTHING,
BREAKABLE,
HOLE,
UPPERFLOOR,
FLOOR,
BUMPER,
STAIRS,
SPAWNER,
UNBREAKABLE
};
private:
//! @brief Enum of the block available.
enum BlockType
{
NOTHING,
BREAKABLE,
HOLE,
UPPERFLOOR,
FLOOR,
BUMPER,
STAIRS,
SPAWNER,
UNBREAKABLE
};
using MapElem = std::function<void (Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
using MapElem = std::function<void(Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
//! @brief Generate random block type
static BlockType getRandomBlockType();
//! @brief Generate random block type
static BlockType getRandomBlockType();
//! @param map ASCII map
//! @param x x index on the block
//! @param z z index on the block
//! @param blockType blockType to compare with position
static bool isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType);
//! @param map ASCII map
//! @param x x index on the block
//! @param z z index on the block
//! @param blockType blockType to compare with position
static bool isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map,
int x, int y, int z,
BlockType blockType);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the unbreakable block of the map
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the unbreakable block of the map
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the wall of the map
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the wall of the map
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the floor of the map
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the floor of the map
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create element of the map
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create element of the map
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create breakable of the map
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create breakable of the map
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create unbreakable of the map
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create unbreakable of the map
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create hole of the map
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create hole of the map
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create bumper of the map
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create bumper of the map
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create floor of the map
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create floor of the map
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create upper floor of the map
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create upper floor of the map
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create stair of the map
static void createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate map of block to be loaded
static MapBlock createSpawner(MapBlock map, int width, int height);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create stair of the map
static void createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate height for the map
static MapBlock createHeight(MapBlock map, int width, int height);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate map of block to be loaded
static MapBlock createSpawner(MapBlock map, int width, int height);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Clean breakable on stairs, bumpers, etc..
static MapBlock cleanBreakable(MapBlock map, int width, int height);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate height for the map
static MapBlock createHeight(MapBlock map, int width, int height);
static const std::string assetsPath;
static const std::string wallAssetsPath;
static const std::string imageExtension;
static const std::string objExtension;
static const std::string unbreakableWallPath;
static const std::string breakableWallPath;
static const std::string floorPath;
static const std::string stairsPath;
static const std::string bumperPath;
static const std::string secondFloorPath;
static const std::string holePath;
static const std::string secondFloorHolePath;
public:
static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall);
static void wallDestroyed(WAL::Entity &entity);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Clean breakable on stairs, bumpers, etc..
static MapBlock cleanBreakable(MapBlock map, int width, int height);
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate map of block to be loaded
static MapBlock createMap(int width, int height);
static const std::string assetsPath;
static const std::string wallAssetsPath;
static const std::string imageExtension;
static const std::string objExtension;
static const std::string unbreakableWallPath;
static const std::string breakableWallPath;
static const std::string floorPath;
static const std::string stairsPath;
static const std::string bumperPath;
static const std::string secondFloorPath;
static const std::string holePath;
static const std::string secondFloorHolePath;
public:
static void wallCollide(WAL::Entity &entity,
const WAL::Entity &wall,
CollisionComponent::CollidedAxis collidedAxis);
static void wallDestroyed(WAL::Entity &entity);
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate map of block to be loaded
static MapBlock createMap(int width, int height);
//! @param width Width of the map
//! @param height Height of the map
//! @param map Map to load with block declared inside
//! @param scene Scene where the map is instanced
//! @brief Generate the map
static void loadMap(int width, int height, MapBlock map, const std::shared_ptr<WAL::Scene> &scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param map Map to load with block declared inside
//! @param scene Scene where the map is instanced
//! @brief Generate the map
static void loadMap(int width, int height, MapBlock map, std::shared_ptr<WAL::Scene> scene);
};
} // namespace BBM
+50 -24
View File
@@ -38,6 +38,11 @@
#include "Map/Map.hpp"
#include "System/MenuControllable/MenuControllableSystem.hpp"
#include <Drawables/Texture.hpp>
#include "Component/Music/MusicComponent.hpp"
#include "Component/Sound/SoundComponent.hpp"
#include "System/Sound/PlayerSoundManagerSystem.hpp"
#include "System/Sound/MenuSoundManagerSystem.hpp"
#include "System/Music/MusicSystem.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace RAY2D = RAY::Drawables::Drawables2D;
@@ -81,7 +86,10 @@ namespace BBM
.addSystem<EventSystem>()
.addSystem<HealthSystem>()
.addSystem<CollisionSystem>()
.addSystem<MovableSystem>();
.addSystem<MovableSystem>()
.addSystem<PlayerSoundManagerSystem>()
.addSystem<MenuSoundManagerSystem>()
.addSystem<MusicSystem>();
}
void Runner::enableRaylib(WAL::Wal &wal)
@@ -95,10 +103,15 @@ namespace BBM
std::shared_ptr<WAL::Scene> Runner::loadTitleScreenScene()
{
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
.addComponent<KeyboardComponent>()
.addComponent<SoundComponent>(sounds)
.addComponent<MusicComponent>("assets/musics/music_title.ogg");
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
@@ -114,20 +127,21 @@ namespace BBM
{
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
});
//needed material
//music
//sound
return scene;
}
std::shared_ptr<WAL::Scene> Runner::loadMainMenuScene()
{
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds);
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
@@ -214,19 +228,21 @@ namespace BBM
settings.getComponent<OnClickComponent>().setButtonLinks(&play, &exit);
exit.getComponent<OnClickComponent>().setButtonLinks(&settings, &credits, nullptr, &credits);
credits.getComponent<OnClickComponent>().setButtonLinks(&exit, nullptr, &exit);
//needed material
//music
//sound
return scene;
}
std::shared_ptr<WAL::Scene> Runner::loadPauseMenuScene()
{
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_player_select.ogg")
.addComponent<SoundComponent>(sounds);
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
@@ -292,7 +308,6 @@ namespace BBM
});
//needed material
//music
//sound
play.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, nullptr, &settings);
settings.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, &play, &exit);
exit.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, &settings, nullptr);
@@ -302,11 +317,15 @@ namespace BBM
std::shared_ptr<WAL::Scene> Runner::loadSettingsMenuScene()
{
auto scene = std::make_shared<WAL::Scene>();
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds);
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
@@ -450,8 +469,6 @@ namespace BBM
texture->use("assets/buttons/button_back_hovered.png");
});
//needed material
// back button
// back button asset
//music
//sound
@@ -472,6 +489,12 @@ namespace BBM
scene->addEntity("control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
std::map<SoundComponent::SoundIndex, std::string> soundPath ={
{SoundComponent::JUMP, "assets/sounds/jump.wav"},
{SoundComponent::MOVE, "assets/sounds/move.ogg"},
{SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"},
{SoundComponent::DEATH, "assets/sounds/death.ogg"}
};
scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
@@ -479,8 +502,10 @@ namespace BBM
.addComponent<AnimatorComponent>()
.addComponent<KeyboardComponent>()
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
.addComponent<CollisionComponent>(1)
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
.addComponent<MovableComponent>()
.addComponent<SoundComponent>(soundPath)
.addComponent<MusicComponent>("assets/musics/music_battle.ogg")
.addComponent<BombHolderComponent>()
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
auto &animation = entity.getComponent<AnimationsComponent>();
@@ -489,26 +514,27 @@ namespace BBM
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
// scene->addEntity("cube")
// .addComponent<PositionComponent>(5, 0, 5)
// .addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
// .addComponent<ControllableComponent>()
// .addComponent<KeyboardComponent>()
// .addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, 3);
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
return scene;
}
std::shared_ptr<WAL::Scene> Runner::loadCreditScene()
{
auto scene = std::make_shared<WAL::Scene>();
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds);
auto &raylibLogo = scene->addEntity("raylib logo")
.addComponent<PositionComponent>(1920 / 4, 1080 / 1.75, 0)
+43 -12
View File
@@ -14,7 +14,7 @@ namespace BBM
: System(wal)
{ }
bool CollisionSystem::collide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB)
bool CollisionSystem::boxesCollide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB)
{
bool overlapX = (minA.x <= maxB.x && maxA.x >= minB.x) || (minB.x <= maxA.x && maxB.x >= minA.x);
bool overlapY = (minA.y <= maxB.y && maxA.y >= minB.y) || (minB.y <= maxA.y && maxB.y >= minA.y);
@@ -26,20 +26,51 @@ namespace BBM
void CollisionSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent> &entity)
{
auto &posA = entity.get<PositionComponent>();
auto &col = entity.get<CollisionComponent>();
Vector3f position = posA.position;
if (auto *movable = entity->tryGetComponent<MovableComponent>())
position += movable->getVelocity();
Vector3f minA = Vector3f::min(position, position + col.bound);
Vector3f maxA = Vector3f::max(position, position + col.bound);
auto &colA = entity.get<CollisionComponent>();
Vector3f pointA = posA.position + colA.positionOffset;
Vector3f pointAx = pointA;
Vector3f pointAy = pointA;
Vector3f pointAz = pointA;
if (auto *movable = entity->tryGetComponent<MovableComponent>()) {
auto vel = movable->getVelocity();
pointAx.x += vel.x;
pointAy.y += vel.y;
pointAz.z += vel.z;
}
Vector3f minAx = Vector3f::min(pointAx, pointAx + colA.bound);
Vector3f maxAx = Vector3f::max(pointAx, pointAx + colA.bound);
Vector3f minAy = Vector3f::min(pointAy, pointAy + colA.bound);
Vector3f maxAy = Vector3f::max(pointAy, pointAy + colA.bound);
Vector3f minAz = Vector3f::min(pointAz, pointAz + colA.bound);
Vector3f maxAz = Vector3f::max(pointAz, pointAz + colA.bound);
for (auto &[other, posB, colB] : this->getView()) {
if (other.getUid() == entity->getUid())
continue;
Vector3f minB = Vector3f::min(posB.position, posB.position + colB.bound);
Vector3f maxB = Vector3f::max(posB.position, posB.position + colB.bound);
if (collide(minA, maxA, minB, maxB)) {
col.onCollide(entity, other);
colB.onCollided(entity, other);
auto pointB = posB.position + colB.positionOffset;
int collidedAxis = 0;
// TODO if B is also a movable we don't check with it's changing position
Vector3f minB = Vector3f::min(pointB, pointB + colB.bound);
Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound);
if (boxesCollide(minAx, maxAx, minB, maxB)) {
collidedAxis += CollisionComponent::CollidedAxis::X;
}
if (boxesCollide(minAy, maxAy, minB, maxB)) {
collidedAxis += CollisionComponent::CollidedAxis::Y;
}
if (boxesCollide(minAz, maxAz, minB, maxB)) {
collidedAxis += CollisionComponent::CollidedAxis::Z;
}
if (collidedAxis) {
colA.onCollide(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
colB.onCollided(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
}
}
}
+1 -1
View File
@@ -31,6 +31,6 @@ namespace BBM
CollisionSystem &operator=(const CollisionSystem &) = delete;
//! @brief check AABB collision
static bool collide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB);
static bool boxesCollide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB);
};
}
+6 -5
View File
@@ -31,10 +31,11 @@ namespace BBM
for (auto key : keyPressedMap)
key.second = gamepad.isPressed(key.first);
controllable.move = Vector2f();
controllable.move.x += gamepad.isPressed(gamepadComponent.keyRight);
controllable.move.x -= gamepad.isPressed(gamepadComponent.keyLeft);
controllable.move.y += gamepad.isPressed(gamepadComponent.keyUp);
controllable.move.y -= gamepad.isPressed(gamepadComponent.keyDown);
controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1;
controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1;
controllable.move.x -= gamepad.isDown(gamepadComponent.keyRight);
controllable.move.x += gamepad.isDown(gamepadComponent.keyLeft);
controllable.move.y += gamepad.isDown(gamepadComponent.keyUp);
controllable.move.y -= gamepad.isDown(gamepadComponent.keyDown);
}
}
+2 -2
View File
@@ -31,9 +31,9 @@ namespace BBM
key.second = Keyboard::isDown(key.first);
controllable.move = Vector2f();
if (Keyboard::isDown(keyboard.keyRight))
controllable.move.x += 1;
if (Keyboard::isDown(keyboard.keyLeft))
controllable.move.x -= 1;
if (Keyboard::isDown(keyboard.keyLeft))
controllable.move.x += 1;
if (Keyboard::isDown(keyboard.keyUp))
controllable.move.y += 1;
if (Keyboard::isDown(keyboard.keyDown))
+24
View File
@@ -0,0 +1,24 @@
//
// Created by Tom Augier on 05/06/2021
//
#include "MusicSystem.hpp"
#include <map>
namespace BBM {
MusicSystem::MusicSystem(WAL::Wal &wal)
: System(wal)
{}
void MusicSystem::onFixedUpdate(WAL::ViewEntity<MusicComponent> &entity)
{
auto &music = entity.get<MusicComponent>();
music.setVolume(music.volume);
if (!music.isPlaying()) {
music.playMusic();
}
music.updateMusicStream();
}
}
+31
View File
@@ -0,0 +1,31 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "System/System.hpp"
#include "Window.hpp"
#include "Component/Music/MusicComponent.hpp"
#include "Component/Health/HealthComponent.hpp"
#include <Component/Controllable/ControllableComponent.hpp>
#include "Wal.hpp"
namespace BBM
{
class MusicSystem : public WAL::System<MusicComponent>
{
public:
//! @inherit
void onFixedUpdate(WAL::ViewEntity<MusicComponent> &entity) override;
//! @brief ctor
MusicSystem(WAL::Wal &wal);
//! @brief Default copy ctor
MusicSystem(const MusicSystem &) = default;
//! @brief Default dtor
~MusicSystem() override = default;
//! @brief A MusicManager screen system can't be assigned.
MusicSystem &operator=(const MusicSystem &) = delete;
};
}
+8 -4
View File
@@ -10,13 +10,16 @@
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Drawables/ADrawable3D.hpp"
#include "Component/Collision/CollisionComponent.hpp"
namespace BBM
{
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode)
: System(wal),
_window(window),
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
_debugMode(debugMode)
_window(window),
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
_debugMode(debugMode)
{
this->_window.setFPS(this->FPS);
}
@@ -44,7 +47,8 @@ namespace BBM
this->_window.endDrawing();
}
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity,
std::chrono::nanoseconds dtime)
{
const auto &pos = entity.get<PositionComponent>();
const auto &cam = entity.get<CameraComponent>();
@@ -0,0 +1,32 @@
//
// Created by Tom Augier on 05/06/2021
//
#include "MenuSoundManagerSystem.hpp"
#include <map>
namespace BBM {
MenuSoundManagerSystem::MenuSoundManagerSystem(WAL::Wal &wal)
: System(wal)
{}
void MenuSoundManagerSystem::onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent> &entity)
{
const auto &controllable = entity.get<ControllableComponent>();
auto &sound = entity.get<SoundComponent>();
sound.setVolume(sound.volume);
std::map<bool, SoundComponent::SoundIndex> soundIndex = {
{controllable.move.x, SoundComponent::MOVE},
{controllable.move.y, SoundComponent::MOVE},
{controllable.jump, SoundComponent::JUMP},
};
for (auto &a : soundIndex) {
if (a.first) {
sound.setIndex(a.second);
sound.playSound();
}
}
}
}
@@ -0,0 +1,31 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "System/System.hpp"
#include "Window.hpp"
#include "Component/Sound/SoundComponent.hpp"
#include "Component/Health/HealthComponent.hpp"
#include <Component/Controllable/ControllableComponent.hpp>
#include "Wal.hpp"
namespace BBM
{
class MenuSoundManagerSystem : public WAL::System<SoundComponent, ControllableComponent>
{
public:
//! @inherit
void onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent> &entity) override;
//! @brief ctor
MenuSoundManagerSystem(WAL::Wal &wal);
//! @brief Default copy ctor
MenuSoundManagerSystem(const MenuSoundManagerSystem &) = default;
//! @brief Default dtor
~MenuSoundManagerSystem() override = default;
//! @brief A SoundManager screen system can't be assigned.
MenuSoundManagerSystem &operator=(const MenuSoundManagerSystem &) = delete;
};
}
@@ -0,0 +1,34 @@
//
// Created by Tom Augier on 05/06/2021
//
#include "PlayerSoundManagerSystem.hpp"
#include <map>
namespace BBM {
PlayerSoundManagerSystem::PlayerSoundManagerSystem(WAL::Wal &wal)
: System(wal)
{}
void PlayerSoundManagerSystem::onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent, HealthComponent> &entity)
{
const auto &controllable = entity.get<ControllableComponent>();
auto &sound = entity.get<SoundComponent>();
auto &health = entity.get<HealthComponent>();
sound.setVolume(sound.volume);
std::map<bool, SoundComponent::SoundIndex> soundIndex = {
{health.getHealthPoint() <= 0, SoundComponent::DEATH},
{controllable.bomb, SoundComponent::BOMB},
{controllable.jump, SoundComponent::JUMP},
{controllable.move.x != 0 || controllable.move.y != 0, SoundComponent::MOVE}
};
for (auto &a : soundIndex) {
if (a.first) {
sound.setIndex(a.second);
sound.playSound();
}
}
}
}
@@ -0,0 +1,31 @@
//
// Created by Tom Augier on 05/06/2021
//
#pragma once
#include "System/System.hpp"
#include "Window.hpp"
#include "Component/Sound/SoundComponent.hpp"
#include "Component/Health/HealthComponent.hpp"
#include <Component/Controllable/ControllableComponent.hpp>
#include "Wal.hpp"
namespace BBM
{
class PlayerSoundManagerSystem : public WAL::System<SoundComponent, ControllableComponent, HealthComponent>
{
public:
//! @inherit
void onFixedUpdate(WAL::ViewEntity<SoundComponent, ControllableComponent, HealthComponent> &entity) override;
//! @brief ctor
PlayerSoundManagerSystem(WAL::Wal &wal);
//! @brief Default copy ctor
PlayerSoundManagerSystem(const PlayerSoundManagerSystem &) = default;
//! @brief Default dtor
~PlayerSoundManagerSystem() override = default;
//! @brief A SoundManager screen system can't be assigned.
PlayerSoundManagerSystem &operator=(const PlayerSoundManagerSystem &) = delete;
};
}
+20 -17
View File
@@ -8,6 +8,7 @@
#include "Wal.hpp"
#define private public
#include "System/Collision/CollisionSystem.hpp"
#include "System/Movable/MovableSystem.hpp"
#include "Component/Movable/MovableComponent.hpp"
@@ -24,14 +25,14 @@ TEST_CASE("Collision test", "[Component][System]")
wal.scene = std::make_shared<Scene>();
wal.scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<CollisionComponent>([](Entity &actual, const Entity &) {
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int _) {
try {
auto &pos = actual.getComponent<PositionComponent>();
pos.position.x = 1;
pos.position.y = 1;
pos.position.z = 1;
auto &pos = actual.getComponent<PositionComponent>();
pos.position.x = 1;
pos.position.y = 1;
pos.position.z = 1;
} catch (std::exception &e) {};
}, [](Entity &, const Entity &){}, 5.0);
}, [](Entity &, const Entity &, int) {}, 0, 5.0);
Entity &entity = wal.scene->getEntities().front();
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
@@ -44,10 +45,10 @@ TEST_CASE("Collision test", "[Component][System]")
REQUIRE(entity.getComponent<PositionComponent>().position.x == 0.0);
REQUIRE(entity.getComponent<PositionComponent>().position.y == 0.0);
REQUIRE(entity.getComponent<PositionComponent>().position.z == 0.0);
wal.scene->addEntity("block")
.addComponent<PositionComponent>(2,2,2)
.addComponent<CollisionComponent>(1);
.addComponent<PositionComponent>(2, 2, 2)
.addComponent<CollisionComponent>(0, 1);
Entity &player = wal.scene->getEntities().front();
collision.update(std::chrono::nanoseconds(1));
REQUIRE(player.hasComponent(typeid(PositionComponent)));
@@ -68,17 +69,19 @@ TEST_CASE("Collsion test with movable", "[Component][System]")
wal.scene = std::make_shared<Scene>();
wal.scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<CollisionComponent>([](Entity &actual, const Entity &) {}, [](Entity &actual, const Entity &) {}, 5.0)
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int) {},
[](Entity &actual, const Entity &, int) {}, 0, 5.0)
.addComponent<MovableComponent>();
wal.scene->addEntity("block")
.addComponent<PositionComponent>(0, 0, 0)
.addComponent<CollisionComponent>([](Entity &actual, const Entity &){}, [](Entity &actual, const Entity &) {
try {
auto &mov = actual.getComponent<MovableComponent>();
mov._velocity = Vector3f();
} catch (std::exception &e) {};
}, 1);
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int) {},
[](Entity &actual, const Entity &, int) {
try {
auto &mov = actual.getComponent<MovableComponent>();
mov._velocity = Vector3f();
} catch (std::exception &e) {};
}, 0, 1);
Entity &entity = wal.scene->getEntities().front();
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());