merge develop in no_clip_bonus

This commit is contained in:
Askou
2021-06-15 12:23:39 +02:00
50 changed files with 707 additions and 168 deletions

View File

@@ -109,6 +109,10 @@ set(SOURCES
sources/System/Sound/PlayerSoundManagerSystem.hpp sources/System/Sound/PlayerSoundManagerSystem.hpp
sources/System/Music/MusicSystem.hpp sources/System/Music/MusicSystem.hpp
sources/System/Music/MusicSystem.cpp sources/System/Music/MusicSystem.cpp
sources/System/Lobby/LobbySystem.cpp
sources/System/Lobby/LobbySystem.hpp
sources/Component/Lobby/LobbyComponent.cpp
sources/Component/Lobby/LobbyComponent.hpp
sources/Component/Gravity/GravityComponent.hpp sources/Component/Gravity/GravityComponent.hpp
sources/Component/Gravity/GravityComponent.cpp sources/Component/Gravity/GravityComponent.cpp
sources/System/Gravity/GravitySystem.hpp sources/System/Gravity/GravitySystem.hpp
@@ -130,6 +134,7 @@ set(SOURCES
sources/Runner/PauseMenuScene.cpp sources/Runner/PauseMenuScene.cpp
sources/Runner/SettingsMenuScene.cpp sources/Runner/SettingsMenuScene.cpp
sources/Runner/CreditScene.cpp sources/Runner/CreditScene.cpp
sources/Runner/LobbyScene.cpp
) )
add_executable(bomberman add_executable(bomberman
sources/main.cpp sources/main.cpp

BIN
assets/player/icons/ai.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

BIN
assets/player/icons/red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 324 B

After

Width:  |  Height:  |  Size: 324 B

View File

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 396 B

View File

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

View File

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 345 B

View File

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

View File

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

View File

@@ -37,7 +37,7 @@ namespace RAY::Drawables::Drawables2D {
Rectangle &operator=(const Rectangle &) = default; Rectangle &operator=(const Rectangle &) = default;
//! @brief A default destructor //! @brief A default destructor
virtual ~Rectangle() override = default; ~Rectangle() override = default;
//! @return the dimensions of the rectangle //! @return the dimensions of the rectangle
const Vector2 &getDimensions(void); const Vector2 &getDimensions(void);

View File

@@ -13,6 +13,10 @@ namespace RAY {
Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture); Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture);
Texture::Texture()
: Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE)
{}
Texture::Texture(const std::string &filename, bool lonely): Texture::Texture(const std::string &filename, bool lonely):
Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE),
_texture(_texturesCache.fetch(filename, lonely)), _texture(_texturesCache.fetch(filename, lonely)),
@@ -34,6 +38,7 @@ namespace RAY {
return *this; return *this;
this->_texture = this->_texturesCache.fetch(filename); this->_texture = this->_texturesCache.fetch(filename);
this->_resourcePath = filename; this->_resourcePath = filename;
this->_dimensions = Vector2(this->_texture->width, this->_texture->height);
return *this; return *this;
} }
@@ -44,6 +49,9 @@ namespace RAY {
void Texture::drawOn(RAY::Window &) void Texture::drawOn(RAY::Window &)
{ {
if (!this->_texture)
return;
float scale = this->_dimensions.x / this->_texture->width; float scale = this->_dimensions.x / this->_texture->width;
DrawTextureEx(*this, this->_position, 0, scale, this->_color); DrawTextureEx(*this, this->_position, 0, scale, this->_color);

View File

@@ -21,7 +21,10 @@ namespace RAY
//! @brief Create an texture, loading a file //! @brief Create an texture, loading a file
//! @param filename: path to file to load //! @param filename: path to file to load
//! @param lonely: should be set to true if the entity's loaded data must be independant from others //! @param lonely: should be set to true if the entity's loaded data must be independant from others
Texture(const std::string &filename, bool lonely = false); explicit Texture(const std::string &filename, bool lonely = false);
//! @brief Create an empty texture
Texture();
//! @brief A texture is copy constructable //! @brief A texture is copy constructable
Texture(const Texture &) = default; Texture(const Texture &) = default;
@@ -33,7 +36,7 @@ namespace RAY
Texture &operator=(const Texture &) = default; Texture &operator=(const Texture &) = default;
//! @brief Texture destructor, will not unload ressources //! @brief Texture destructor, will not unload ressources
~Texture() = default; ~Texture() override = default;
//! @brief draw texture on a window //! @brief draw texture on a window
void drawOn(RAY::Window &) override; void drawOn(RAY::Window &) override;

View File

@@ -5,9 +5,10 @@
** ModelAnimation ** ModelAnimation
*/ */
#include <iostream>
#include "Model/ModelAnimation.hpp" #include "Model/ModelAnimation.hpp"
RAY::ModelAnimation::ModelAnimation(::ModelAnimation &animation): RAY::ModelAnimation::ModelAnimation(::ModelAnimation animation):
_animation(animation), _frameCounter(0) _animation(animation), _frameCounter(0)
{ {
} }
@@ -39,8 +40,3 @@ RAY::ModelAnimation::operator ::ModelAnimation() const
{ {
return this->_animation; return this->_animation;
} }
RAY::ModelAnimation::operator ::ModelAnimation *()
{
return &this->_animation;
}

View File

@@ -17,7 +17,7 @@ namespace RAY {
public: public:
//! @brief A Model animation constructor //! @brief A Model animation constructor
//! @param animationPtr an animation pointer, returned by the nimation-loading function //! @param animationPtr an animation pointer, returned by the nimation-loading function
ModelAnimation(::ModelAnimation &animationPtr); explicit ModelAnimation(::ModelAnimation animation);
//! @brief A default copy-constructor //! @brief A default copy-constructor
ModelAnimation(const ModelAnimation &) = default; ModelAnimation(const ModelAnimation &) = default;
@@ -41,13 +41,10 @@ namespace RAY {
~ModelAnimation() = default; ~ModelAnimation() = default;
private: private:
::ModelAnimation &_animation; ::ModelAnimation _animation;
size_t _frameCounter; size_t _frameCounter;
INTERNAL: INTERNAL:
//! @brief Castin Object to raw model animation pointer
operator ::ModelAnimation *();
//! @brief Castin Object to raw model animation pointer //! @brief Castin Object to raw model animation pointer
operator ::ModelAnimation() const; operator ::ModelAnimation() const;
}; };

View File

@@ -19,7 +19,7 @@ namespace RAY {
public: public:
//! @brief A Model animation constructor //! @brief A Model animation constructor
//! @param filePath Path to the file containing animations //! @param filePath Path to the file containing animations
ModelAnimations(const std::string &filePath); explicit ModelAnimations(const std::string &filePath);
//! @brief default copy ctor //! @brief default copy ctor
ModelAnimations(const ModelAnimations &) = default; ModelAnimations(const ModelAnimations &) = default;
@@ -59,7 +59,7 @@ namespace RAY {
int _animationCount; int _animationCount;
//! @brief The file where the animations were loaded (used to create a copy of this class) //! @brief The file where the animations were loaded (used to create a copy of this class)
const std::string _filePath; std::string _filePath;
static Cache<::ModelAnimation> _animationsCache; static Cache<::ModelAnimation> _animationsCache;
}; };

View File

@@ -73,24 +73,6 @@ namespace RAY {
template<> template<>
class Cache<::ModelAnimation> { class Cache<::ModelAnimation> {
public:
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
{};
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
{
if (this->_cache.find(path) != this->_cache.end())
return this->_cache[path];
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
unsigned int animCount = *counter;
this->_cache.emplace(path, std::shared_ptr<::ModelAnimation>(
animations, [this, animCount](::ModelAnimation *p) {
this->_dataUnloader(p, animCount);
}));
return this->_cache[path];
};
private: private:
//! @brief function to call to load data //! @brief function to call to load data
std::function<::ModelAnimation *(const char *, int *)> _dataLoader; std::function<::ModelAnimation *(const char *, int *)> _dataLoader;
@@ -98,10 +80,34 @@ namespace RAY {
//! @brief function to call when the ray data will be unloaded //! @brief function to call when the ray data will be unloaded
std::function<void(::ModelAnimation *, unsigned int)> _dataUnloader; std::function<void(::ModelAnimation *, unsigned int)> _dataUnloader;
//! @brief map storing shared ptr of caches typedef struct {
std::unordered_map<std::string, std::shared_ptr<::ModelAnimation>> _cache; std::shared_ptr<::ModelAnimation> animations;
}; int animationsCount;
} AnimationsHolder;
//! @brief map storing shared ptr of caches
std::unordered_map<std::string, AnimationsHolder> _cache;
public:
Cache(std::function<::ModelAnimation *(const char *, int *)> dataLoader, std::function<void(::ModelAnimation *, unsigned int)>dataUnloader):
_dataLoader(std::move(dataLoader)), _dataUnloader(std::move(dataUnloader))
{};
std::shared_ptr<::ModelAnimation> fetch(const std::string &path, int *counter)
{
if (this->_cache.find(path) != this->_cache.end()) {
*counter = this->_cache[path].animationsCount;
} else {
::ModelAnimation *animations = this->_dataLoader(path.c_str(), counter);
int animCount = *counter;
AnimationsHolder holder = {std::shared_ptr<::ModelAnimation>(
animations, [this, animCount](::ModelAnimation *p) {
this->_dataUnloader(p, animCount);
}),animCount};
this->_cache.emplace(path, holder);
}
return this->_cache[path].animations;
};
};
template<> template<>
class Cache<::Shader> class Cache<::Shader>
{ {

View File

@@ -74,13 +74,12 @@ namespace WAL
//! @brief A default constructor //! @brief A default constructor
Scene() = default; Scene() = default;
//! @brief A scene is copy constructable //! @brief A scene is not copy constructable
Scene(const Scene &) = default; Scene(const Scene &) = delete;
//! @brief A default destructor //! @brief A default destructor
~Scene() = default; ~Scene() = default;
//! @brief A scene is assignable //! @brief A scene is assignable
Scene &operator=(const Scene &); Scene &operator=(const Scene &);
Scene(Scene &&) = default;
friend Entity; friend Entity;
}; };

View File

@@ -61,14 +61,20 @@ namespace WAL
std::optional<ViewEntity<Components...>> _entity; std::optional<ViewEntity<Components...>> _entity;
public: public:
ViewEntity<Components...> &operator*() using iterator_category = std::forward_iterator_tag;
using difference_type = std::ptrdiff_t;
using value_type = ViewEntity<Components...>;
using pointer = value_type *;
using reference = value_type &;
reference operator*()
{ {
if (!this->_entity) if (!this->_entity)
this->_entity.emplace(*this->_it); this->_entity.emplace(*this->_it);
return *this->_entity; return *this->_entity;
} }
ViewEntity<Components...> *operator->() pointer operator->()
{ {
if (!this->_entity) if (!this->_entity)
this->_entity =(*this->_it); this->_entity =(*this->_it);

View File

@@ -8,9 +8,9 @@
namespace BBM namespace BBM
{ {
AnimationsComponent::AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play) AnimationsComponent::AnimationsComponent(WAL::Entity &entity, const std::string &path, int animIndex, bool play)
: WAL::Component(entity), : WAL::Component(entity),
_modelAnimation(std::move(modelAnimation)), _modelAnimation(path),
_currentAnimIndex(animIndex), _currentAnimIndex(animIndex),
_animDisabled(play) _animDisabled(play)
{ {
@@ -20,7 +20,7 @@ namespace BBM
WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const
{ {
return new AnimationsComponent(entity, return new AnimationsComponent(entity,
RAY::ModelAnimations(this->_modelAnimation.getFilePath()), this->_modelAnimation.getFilePath(),
this->_currentAnimIndex); this->_currentAnimIndex);
} }

View File

@@ -52,7 +52,7 @@ namespace BBM
bool isAnimDisabled() const; bool isAnimDisabled() const;
//! @brief ctor entity and the path of the animation file //! @brief ctor entity and the path of the animation file
explicit AnimationsComponent(WAL::Entity &entity, RAY::ModelAnimations modelAnimation, int animIndex, bool play = true); explicit AnimationsComponent(WAL::Entity &entity, const std::string &path, int animIndex, bool play = true);
//! @brief copy ctor //! @brief copy ctor
AnimationsComponent(const AnimationsComponent &) = default; AnimationsComponent(const AnimationsComponent &) = default;
//! @brief dtor //! @brief dtor

View File

@@ -17,6 +17,17 @@ namespace BBM
class ControllableComponent : public WAL::Component class ControllableComponent : public WAL::Component
{ {
public: public:
enum Layout
{
NONE,
KEYBOARD_0,
KEYBOARD_1,
GAMEPAD_0,
GAMEPAD_1,
GAMEPAD_2,
GAMEPAD_3
};
//! @brief The X and Z abscis of the movement. //! @brief The X and Z abscis of the movement.
Vector2f move; Vector2f move;
//! @brief input value for jump //! @brief input value for jump
@@ -27,6 +38,8 @@ namespace BBM
bool pause = false; bool pause = false;
//! @brief The speed applied to every controllable entities. //! @brief The speed applied to every controllable entities.
float speed = .15f; float speed = .15f;
//! @brief The layout used for this controllable.
Layout layout = NONE;
//! @inherit //! @inherit
WAL::Component *clone(WAL::Entity &entity) const override; WAL::Component *clone(WAL::Entity &entity) const override;

View File

@@ -3,6 +3,7 @@
// Edited by Benjamin Henry on 2021-05-20. // Edited by Benjamin Henry on 2021-05-20.
// //
#include <Component/Controllable/ControllableComponent.hpp>
#include "GamepadComponent.hpp" #include "GamepadComponent.hpp"
namespace BBM namespace BBM
@@ -31,4 +32,27 @@ namespace BBM
return this->_ID; return this->_ID;
} }
void GamepadComponent::onStart()
{
auto *controller = this->_entity.tryGetComponent<ControllableComponent>();
if (!controller)
return;
switch (this->_ID) {
case 0:
controller->layout = ControllableComponent::GAMEPAD_0;
break;
case 1:
controller->layout = ControllableComponent::GAMEPAD_1;
break;
case 2:
controller->layout = ControllableComponent::GAMEPAD_2;
break;
case 3:
controller->layout = ControllableComponent::GAMEPAD_3;
break;
default:
return;
}
}
} // namespace BMM } // namespace BMM

View File

@@ -44,6 +44,8 @@ namespace BBM
//! @inherit //! @inherit
WAL::Component *clone(WAL::Entity &entity) const override; WAL::Component *clone(WAL::Entity &entity) const override;
void onStart() override;
//! @brief Create a new gampad component using default keys. //! @brief Create a new gampad component using default keys.
explicit GamepadComponent(WAL::Entity &entity); explicit GamepadComponent(WAL::Entity &entity);

View File

@@ -3,25 +3,44 @@
// Edited by Benjamin Henry on 2021-05-20. // Edited by Benjamin Henry on 2021-05-20.
// //
#include <Component/Controllable/ControllableComponent.hpp>
#include "KeyboardComponent.hpp" #include "KeyboardComponent.hpp"
namespace BBM namespace BBM
{ {
KeyboardComponent::KeyboardComponent(WAL::Entity &entity, KeyboardComponent::KeyboardComponent(WAL::Entity &entity, ControllableComponent::Layout layout)
Key up, : WAL::Component(entity), layout(layout)
Key down, {
Key left, if (layout == ControllableComponent::KEYBOARD_0) {
Key right, this->keyUp = KEY_W;
Key jump, this->keyDown = KEY_S;
Key bomb, this->keyLeft = KEY_A;
Key pause) this->keyRight = KEY_D;
: WAL::Component(entity), keyJump(jump), keyBomb(bomb), keyPause(pause), this->keyJump = KEY_SPACE;
keyRight(right), keyLeft(left), keyUp(up), keyDown(down) this->keyBomb = KEY_E;
{} this->keyPause = KEY_ESCAPE;
} else {
this->keyUp = KEY_UP;
this->keyDown = KEY_DOWN;
this->keyLeft = KEY_LEFT;
this->keyRight = KEY_RIGHT;
this->keyJump = KEY_RIGHT_CONTROL;
this->keyBomb = KEY_ENTER;
this->keyPause = KEY_BACKSPACE;
}
}
WAL::Component *KeyboardComponent::clone(WAL::Entity &entity) const WAL::Component *KeyboardComponent::clone(WAL::Entity &entity) const
{ {
return new KeyboardComponent(entity); return new KeyboardComponent(entity, this->layout);
}
void KeyboardComponent::onStart()
{
auto *controller = this->_entity.tryGetComponent<ControllableComponent>();
if (!controller)
return;
controller->layout = this->layout;
} }
} // namespace BMM } // namespace BMM

View File

@@ -7,6 +7,7 @@
#include <Controllers/Keyboard.hpp> #include <Controllers/Keyboard.hpp>
#include "Component/Component.hpp" #include "Component/Component.hpp"
#include "Component/Controllable/ControllableComponent.hpp"
#include "Entity/Entity.hpp" #include "Entity/Entity.hpp"
using Key = RAY::Controller::Keyboard::Key; using Key = RAY::Controller::Keyboard::Key;
@@ -30,19 +31,16 @@ namespace BBM
Key keyUp = KEY_W; Key keyUp = KEY_W;
//! @brief move down key //! @brief move down key
Key keyDown = KEY_S; Key keyDown = KEY_S;
//! @brief Layout
ControllableComponent::Layout layout;
//! @inherit //! @inherit
WAL::Component *clone(WAL::Entity &entity) const override; WAL::Component *clone(WAL::Entity &entity) const override;
void onStart() override;
//! @brief Create a new keyboard component using custom keys. //! @brief Create a new keyboard component using custom keys.
explicit KeyboardComponent(WAL::Entity &entity, explicit KeyboardComponent(WAL::Entity &entity, ControllableComponent::Layout layout = ControllableComponent::Layout::KEYBOARD_0);
Key up = KEY_W,
Key down = KEY_S,
Key left = KEY_A,
Key right = KEY_D,
Key jump = KEY_SPACE,
Key bomb = KEY_E,
Key pause = KEY_ESCAPE);
//! @brief A Keyboard component is copy constructable. //! @brief A Keyboard component is copy constructable.
KeyboardComponent(const KeyboardComponent &) = default; KeyboardComponent(const KeyboardComponent &) = default;

View File

@@ -0,0 +1,20 @@
//
// Created by Zoe Roux on 6/11/21.
//
#include "LobbyComponent.hpp"
namespace BBM
{
LobbyComponent::LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile)
: WAL::Component(entity),
playerID(playerID),
readyButton(readyButton),
coloredTile(coloredTile)
{}
WAL::Component *LobbyComponent::clone(WAL::Entity &entity) const
{
return new LobbyComponent(entity, this->playerID, this->readyButton, this->coloredTile);
}
}

View File

@@ -0,0 +1,44 @@
//
// Created by Zoe Roux on 6/11/21.
//
#pragma once
#include <Component/Component.hpp>
#include <Entity/Entity.hpp>
#include <Color.hpp>
#include <Component/Controllable/ControllableComponent.hpp>
#include <chrono>
namespace BBM
{
class LobbyComponent : public WAL::Component
{
public:
//! @brief The layout used for this player.
ControllableComponent::Layout layout = ControllableComponent::NONE;
//! @brief The ID of the lobby player (from 0 to 3)
int playerID;
//! @brief The color of the player (as an index)
int color;
//! @brief Is this player ready
bool ready = false;
//! @brief The entity containing the ready display.
WAL::Entity &readyButton;
//! @brief The colored rectangle behind the player.
WAL::Entity &coloredTile;
//! @brief The time of last input that this lobby player has made.
std::chrono::time_point<std::chrono::steady_clock> lastInput;
Component *clone(WAL::Entity &entity) const override;
//! @brief Create a new lobby component.
explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile);
//! @brief A lobby component is copyable.
LobbyComponent(const LobbyComponent &) = default;
//! @brief A default destructor
~LobbyComponent() override = default;
//! @brief A lobby component is not assignable.
LobbyComponent &operator=(const LobbyComponent &) = delete;
};
}

View File

@@ -50,5 +50,8 @@ namespace BBM
TagComponent &operator=(const TagComponent &) = delete; TagComponent &operator=(const TagComponent &) = delete;
}; };
// interact with bombs & stop the explosion
constexpr const char Blowable[] = "Blowable"; constexpr const char Blowable[] = "Blowable";
// interact with bombs (getting damage etc) but doesn't stop explosion
constexpr const char BlowablePass[] = "BlowablePass";
} }

View File

@@ -101,7 +101,7 @@ namespace BBM
return; return;
wal.getScene()->scheduleNewEntity("Bonus") wal.getScene()->scheduleNewEntity("Bonus")
.addComponent<PositionComponent>(position) .addComponent<PositionComponent>(position)
.addComponent<TagComponent<Blowable>>() .addComponent<TagComponent<BlowablePass>>()
.addComponent<MovableComponent>() .addComponent<MovableComponent>()
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) { .addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) {
entity.scheduleDeletion(); entity.scheduleDeletion();

View File

@@ -23,13 +23,12 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"} {SoundComponent::JUMP, "assets/sounds/click.ogg"}
}; };
addMenuControl(*scene);
scene->addEntity("background") scene->addEntity("background")
.addComponent<PositionComponent>() .addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png"); .addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
scene->addEntity("Control entity") scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg") .addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds); .addComponent<SoundComponent>(sounds);

View File

@@ -2,11 +2,11 @@
#include <Wal.hpp> #include <Wal.hpp>
#include "Runner.hpp" #include "Runner.hpp"
#include <map> #include <map>
#include <Component/Bonus/PlayerBonusComponent.hpp>
#include "Component/Music/MusicComponent.hpp" #include "Component/Music/MusicComponent.hpp"
#include "Component/Sound/SoundComponent.hpp" #include "Component/Sound/SoundComponent.hpp"
#include "Component/Controllable/ControllableComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp"
#include "Component/Position/PositionComponent.hpp" #include "Component/Position/PositionComponent.hpp"
#include "Component/Keyboard/KeyboardComponent.hpp"
#include "Component/Animator/AnimatorComponent.hpp" #include "Component/Animator/AnimatorComponent.hpp"
#include "Component/Animation/AnimationsComponent.hpp" #include "Component/Animation/AnimationsComponent.hpp"
#include "Component/Health/HealthComponent.hpp" #include "Component/Health/HealthComponent.hpp"
@@ -14,7 +14,6 @@
#include "Component/Collision/CollisionComponent.hpp" #include "Component/Collision/CollisionComponent.hpp"
#include "Component/Movable/MovableComponent.hpp" #include "Component/Movable/MovableComponent.hpp"
#include "Component/BombHolder/BombHolderComponent.hpp" #include "Component/BombHolder/BombHolderComponent.hpp"
#include "Component/Bonus/PlayerBonusComponent.hpp"
#include "Component/Shaders/ShaderComponent.hpp" #include "Component/Shaders/ShaderComponent.hpp"
#include "Component/Tag/TagComponent.hpp" #include "Component/Tag/TagComponent.hpp"
#include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp"
@@ -32,42 +31,41 @@ namespace BBM
std::shared_ptr<WAL::Scene> Runner::loadGameScene() std::shared_ptr<WAL::Scene> Runner::loadGameScene()
{ {
auto scene = std::make_shared<WAL::Scene>(); auto scene = std::make_shared<WAL::Scene>();
scene->addEntity("control") scene->addEntity("camera")
.addComponent<ControllableComponent>() .addComponent<PositionComponent>(8, 20, 7)
.addComponent<KeyboardComponent>(); .addComponent<CameraComponent>(Vector3f(8, 0, 8));
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
return scene;
}
WAL::Entity &Runner::createPlayer(WAL::Scene &scene)
{
std::map<SoundComponent::SoundIndex, std::string> soundPath ={ std::map<SoundComponent::SoundIndex, std::string> soundPath ={
{SoundComponent::JUMP, "assets/sounds/jump.wav"}, {SoundComponent::JUMP, "assets/sounds/jump.wav"},
{SoundComponent::MOVE, "assets/sounds/move.ogg"}, {SoundComponent::MOVE, "assets/sounds/move.ogg"},
{SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"},
//{SoundComponent::DEATH, "assets/sounds/death.ogg"} //{SoundComponent::DEATH, "assets/sounds/death.ogg"}
}; };
scene->addEntity("player")
.addComponent<PositionComponent>(0, 1.01, 0) return scene.addEntity("player")
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent<PositionComponent>()
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true)
.addComponent<ControllableComponent>() .addComponent<ControllableComponent>()
.addComponent<AnimatorComponent>() .addComponent<AnimatorComponent>()
.addComponent<GravityComponent>() .addComponent<GravityComponent>()
.addComponent<BumperTimerComponent>() .addComponent<BumperTimerComponent>()
.addComponent<KeyboardComponent>() // .addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs")
.addComponent<ShaderComponentModel>("assets/shaders/glsl330/predator.fs") .addComponent<TagComponent<BlowablePass>>()
.addComponent<TagComponent<Blowable>>() .addComponent<AnimationsComponent>("assets/player/player.iqm", 3)
//.addComponent<GamepadComponent>(0)
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
.addComponent<MovableComponent>() .addComponent<MovableComponent>()
.addComponent<SoundComponent>(soundPath) .addComponent<SoundComponent>(soundPath)
.addComponent<MusicComponent>("assets/musics/music_battle.ogg") .addComponent<MusicComponent>("assets/musics/music_battle.ogg")
.addComponent<BombHolderComponent>() .addComponent<BombHolderComponent>()
.addComponent<PlayerBonusComponent>() .addComponent<PlayerBonusComponent>()
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) { .addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &) {
auto &animation = entity.getComponent<AnimationsComponent>(); auto &animation = entity.getComponent<AnimationsComponent>();
animation.setAnimIndex(5); animation.setAnimIndex(5);
}); });
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
return scene;
} }
} }

View File

@@ -0,0 +1,157 @@
//
// Created by Zoe Roux on 2021-06-14.
//
#include <Wal.hpp>
#include "System/Movable/MovableSystem.hpp"
#include <Model/Model.hpp>
#include <Drawables/2D/Rectangle.hpp>
#include <Drawables/2D/Text.hpp>
#include <TraceLog.hpp>
#include "Component/Button/ButtonComponent.hpp"
#include "Component/Renderer/CameraComponent.hpp"
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Runner.hpp"
#include "Models/GameState.hpp"
#include <Component/Animator/AnimatorComponent.hpp>
#include <Component/Tag/TagComponent.hpp>
#include <Drawables/Texture.hpp>
#include "System/Sound/PlayerSoundManagerSystem.hpp"
#include "System/Music/MusicSystem.hpp"
#include "System/Lobby/LobbySystem.hpp"
#include "Component/Lobby/LobbyComponent.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace BBM
{
std::shared_ptr<WAL::Scene> Runner::loadLobbyScene()
{
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
scene->addEntity("Control entity")
.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");
scene->addEntity("lobby text")
.addComponent<PositionComponent>(1920 / 2.75, 100, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("Get Ready", 120, RAY::Vector2(), ORANGE);
auto &play = scene->addEntity("play button")
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_new_game.png")
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_new_game.png");
})
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_new_game_hovered.png");
})
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
if (Runner::gameState.currentScene != GameState::LobbyScene
|| !LobbySystem::playersAreReady(*wal.getScene()))
return;
LobbySystem::switchToGame(wal);
})
.addComponent<TagComponent<"PlayButton">>();
auto &back = scene->addEntity("back to menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png")
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
{
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
})
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
{
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_back.png");
})
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
{
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_back_hovered.png");
});
auto &lavaOption = scene->addEntity("lava option text")
.addComponent<PositionComponent>(1920 / 6, 2 * 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("Lava: Off", 70, RAY::Vector2(), BLACK)
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
if (text->getString().find("Off") != std::string::npos) {
text->setText("Lava: On");
//do
} else {
text->setText("Lava: Off");
//do
}
})
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
{
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
})
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
{
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
auto &heightOption = scene->addEntity("Height option text")
.addComponent<PositionComponent>(1920 / 1.75, 2 * 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("2nd Level: Off", 70, RAY::Vector2(), BLACK)
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
if (text->getString().find("Off") != std::string::npos) {
text->setText("2nd Level: On");
//do
} else {
text->setText("2nd Level: Off");
//do
}
})
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
{
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
})
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
{
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
for (int i = 0; i < 4; i++) {
auto &playerTile = scene->addEntity("player tile")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), RAY::Color(0, 0, 0, 0));
auto &player = scene->addEntity("player")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png");
auto &ready = scene->addEntity("ready")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>();
player.addComponent<LobbyComponent>(i, ready, playerTile);
}
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
play.getComponent<OnClickComponent>().setButtonLinks(&lavaOption, &back, &back, nullptr);
back.getComponent<OnClickComponent>().setButtonLinks(&play, nullptr, nullptr, &play);
lavaOption.getComponent<OnClickComponent>().setButtonLinks(nullptr, &play, nullptr, &heightOption);
heightOption.getComponent<OnClickComponent>().setButtonLinks(nullptr, &play, &lavaOption, nullptr);
return scene;
}
}

View File

@@ -23,9 +23,8 @@ namespace BBM
}; };
auto scene = std::make_shared<WAL::Scene>(); auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
scene->addEntity("Control entity") scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg") .addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds); .addComponent<SoundComponent>(sounds);
scene->addEntity("background") scene->addEntity("background")
@@ -51,7 +50,7 @@ namespace BBM
}) })
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &) .addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
{ {
gameState.nextScene = BBM::GameState::SceneID::GameScene; gameState.nextScene = BBM::GameState::SceneID::LobbyScene;
}); });
auto &settings = scene->addEntity("settings button") auto &settings = scene->addEntity("settings button")
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 360, 0) .addComponent<PositionComponent>(1920 / 2.5, 1080 - 360, 0)

View File

@@ -23,9 +23,8 @@ namespace BBM
}; };
auto scene = std::make_shared<WAL::Scene>(); auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
scene->addEntity("Control entity") scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_player_select.ogg") .addComponent<MusicComponent>("assets/musics/music_player_select.ogg")
.addComponent<SoundComponent>(sounds); .addComponent<SoundComponent>(sounds);
scene->addEntity("background") scene->addEntity("background")

View File

@@ -6,37 +6,35 @@
#include <iostream> #include <iostream>
#include "System/Movable/MovableSystem.hpp" #include "System/Movable/MovableSystem.hpp"
#include "System/Renderer/RenderSystem.hpp" #include "System/Renderer/RenderSystem.hpp"
#include <Model/Model.hpp> #include <Drawables/2D/Rectangle.hpp>
#include <Drawables/2D/Text.hpp>
#include <TraceLog.hpp> #include <TraceLog.hpp>
#include "System/Keyboard/KeyboardSystem.hpp" #include "System/Keyboard/KeyboardSystem.hpp"
#include "System/Controllable/ControllableSystem.hpp" #include "System/Controllable/ControllableSystem.hpp"
#include "System/Gamepad/GamepadSystem.hpp" #include "System/Gamepad/GamepadSystem.hpp"
#include <System/Collision/CollisionSystem.hpp> #include <System/Collision/CollisionSystem.hpp>
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Runner.hpp" #include "Runner.hpp"
#include "Models/GameState.hpp" #include "Models/GameState.hpp"
#include <Model/ModelAnimations.hpp>
#include <System/Timer/TimerSystem.hpp> #include <System/Timer/TimerSystem.hpp>
#include <System/BombHolder/BombHolderSystem.hpp> #include <System/BombHolder/BombHolderSystem.hpp>
#include <System/Event/EventSystem.hpp> #include <System/Event/EventSystem.hpp>
#include <System/Health/HealthSystem.hpp> #include <System/Health/HealthSystem.hpp>
#include <System/Animator/AnimatorSystem.hpp> #include <System/Animator/AnimatorSystem.hpp>
#include <Component/Tag/TagComponent.hpp>
#include <System/IntroAnimation/IntroAnimationSystem.hpp> #include <System/IntroAnimation/IntroAnimationSystem.hpp>
#include <System/Levitate/LevitateSystem.hpp> #include <System/Levitate/LevitateSystem.hpp>
#include <System/Bonus/PlayerBonusSystem.hpp> #include <System/Bonus/PlayerBonusSystem.hpp>
#include "System/Animation/AnimationsSystem.hpp" #include "System/Animation/AnimationsSystem.hpp"
#include "Map/Map.hpp" #include "Map/Map.hpp"
#include "System/MenuControllable/MenuControllableSystem.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp"
#include <Drawables/Texture.hpp>
#include <System/Bomb/BombSystem.hpp> #include <System/Bomb/BombSystem.hpp>
#include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Sound/PlayerSoundManagerSystem.hpp"
#include "System/Sound/MenuSoundManagerSystem.hpp" #include "System/Sound/MenuSoundManagerSystem.hpp"
#include "System/Gravity/GravitySystem.hpp" #include "System/Gravity/GravitySystem.hpp"
#include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/BumperTimer/BumperTimerSystem.hpp"
#include "System/Music/MusicSystem.hpp" #include "System/Music/MusicSystem.hpp"
#include "System/Lobby/LobbySystem.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D; #include "Component/Lobby/LobbyComponent.hpp"
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace BBM namespace BBM
{ {
@@ -44,6 +42,7 @@ namespace BBM
void Runner::updateState(WAL::Wal &engine, GameState &state) void Runner::updateState(WAL::Wal &engine, GameState &state)
{ {
auto &view = engine.getScene()->view<ControllableComponent>();
if (RAY::Window::getInstance().shouldClose()) if (RAY::Window::getInstance().shouldClose())
engine.shouldClose = true; engine.shouldClose = true;
if (gameState.currentScene == GameState::SceneID::GameScene || gameState.currentScene == GameState::SceneID::SplashScreen) { if (gameState.currentScene == GameState::SceneID::GameScene || gameState.currentScene == GameState::SceneID::SplashScreen) {
@@ -69,6 +68,7 @@ namespace BBM
wal.addSystem<TimerSystem>() wal.addSystem<TimerSystem>()
.addSystem<KeyboardSystem>() .addSystem<KeyboardSystem>()
.addSystem<GamepadSystem>() .addSystem<GamepadSystem>()
.addSystem<LobbySystem>()
.addSystem<MenuControllableSystem>() .addSystem<MenuControllableSystem>()
.addSystem<ControllableSystem>() .addSystem<ControllableSystem>()
.addSystem<BombHolderSystem>() .addSystem<BombHolderSystem>()
@@ -96,15 +96,30 @@ namespace BBM
.addSystem<RenderSystem>(window); .addSystem<RenderSystem>(window);
} }
void Runner::addMenuControl(WAL::Scene &scene)
{
scene.addEntity("Keyboard default control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
scene.addEntity("Keyboard second control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>(ControllableComponent::Layout::KEYBOARD_1);
for (int i = 0; i < 4; i++) {
scene.addEntity("Gamepad controller")
.addComponent<ControllableComponent>()
.addComponent<GamepadComponent>(i);
}
}
void Runner::loadScenes() void Runner::loadScenes()
{ {
gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene();
gameState._loadedScenes[GameState::SceneID::GameScene] = loadGameScene();
gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene(); gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene();
gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene();
gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene();
gameState._loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene(); gameState._loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene();
gameState._loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene(); gameState._loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene();
gameState._loadedScenes[GameState::SceneID::LobbyScene] = loadLobbyScene();
} }
int Runner::run() int Runner::run()

View File

@@ -28,6 +28,8 @@ namespace BBM
//! @brief init all raylib-related data & context //! @brief init all raylib-related data & context
static void enableRaylib(WAL::Wal &wal); static void enableRaylib(WAL::Wal &wal);
static void addMenuControl(WAL::Scene &scene);
//! @brief load all data related to title screen //! @brief load all data related to title screen
static std::shared_ptr<WAL::Scene> loadTitleScreenScene(); static std::shared_ptr<WAL::Scene> loadTitleScreenScene();
@@ -46,6 +48,14 @@ namespace BBM
//! @brief load all data related to credit screen //! @brief load all data related to credit screen
static std::shared_ptr<WAL::Scene> loadCreditScene(); static std::shared_ptr<WAL::Scene> loadCreditScene();
//! @brief load all data related to lobby screen
static std::shared_ptr<WAL::Scene> loadLobbyScene();
//! @brief Create a player (without any controllable) and add it to the scene.
//! @param scene The scene where to player should reside.
//! @return A reference to the created player.
static WAL::Entity &createPlayer(WAL::Scene &scene);
//! @brief load all data related to splash screen //! @brief load all data related to splash screen
static std::shared_ptr<WAL::Scene> loadSplashScreenScene(); static std::shared_ptr<WAL::Scene> loadSplashScreenScene();

View File

@@ -24,9 +24,8 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"} {SoundComponent::JUMP, "assets/sounds/click.ogg"}
}; };
addMenuControl(*scene);
scene->addEntity("Control entity") scene->addEntity("Control entity")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<MusicComponent>("assets/musics/music_title.ogg") .addComponent<MusicComponent>("assets/musics/music_title.ogg")
.addComponent<SoundComponent>(sounds); .addComponent<SoundComponent>(sounds);
scene->addEntity("background") scene->addEntity("background")

View File

@@ -19,10 +19,9 @@ namespace BBM
{ {
auto scene = std::make_shared<WAL::Scene>(); auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
auto &splashComponent = scene->addEntity("animation component") auto &splashComponent = scene->addEntity("animation component")
.addComponent<IntroAnimationComponent>() .addComponent<IntroAnimationComponent>();
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>();
auto &background = scene->addEntity("background") auto &background = scene->addEntity("background")
.addComponent<PositionComponent>(0, 0, 0) .addComponent<PositionComponent>(0, 0, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(1920, 1080)); .addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(1920, 1080));

View File

@@ -22,9 +22,8 @@ namespace BBM
{SoundComponent::JUMP, "assets/sounds/click.ogg"} {SoundComponent::JUMP, "assets/sounds/click.ogg"}
}; };
auto scene = std::make_shared<WAL::Scene>(); auto scene = std::make_shared<WAL::Scene>();
addMenuControl(*scene);
scene->addEntity("control") scene->addEntity("control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>()
.addComponent<SoundComponent>(sounds) .addComponent<SoundComponent>(sounds)
.addComponent<MusicComponent>("assets/musics/music_title.ogg"); .addComponent<MusicComponent>("assets/musics/music_title.ogg");
scene->addEntity("background") scene->addEntity("background")

View File

@@ -44,7 +44,7 @@ namespace BBM
return; return;
wal.getScene()->scheduleNewEntity("explosion") wal.getScene()->scheduleNewEntity("explosion")
.addComponent<PositionComponent>(position) .addComponent<PositionComponent>(position)
.addComponent<TimerComponent>(1s, [](WAL::Entity &explosion, WAL::Wal &wal) { .addComponent<TimerComponent>(500ms, [](WAL::Entity &explosion, WAL::Wal &wal) {
explosion.scheduleDeletion(); explosion.scheduleDeletion();
}) })
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb", false, .addComponent<Drawable3DComponent, RAY3D::Model>("assets/bombs/explosion/explosion.glb", false,
@@ -60,6 +60,12 @@ namespace BBM
return; return;
} }
} }
for (auto &[entity, pos, _] : wal.getScene()->view<PositionComponent, TagComponent<BlowablePass>>()) {
if (pos.position.round() == position) {
if (auto *health = entity.tryGetComponent<HealthComponent>())
health->takeDmg(1);
}
}
if (expansionDirections & ExpansionDirection::FRONT) { if (expansionDirections & ExpansionDirection::FRONT) {
_dispatchExplosion(position + Vector3f{1, 0, 0}, wal, size - 1, ExpansionDirection::FRONT); _dispatchExplosion(position + Vector3f{1, 0, 0}, wal, size - 1, ExpansionDirection::FRONT);
} }
@@ -87,6 +93,14 @@ namespace BBM
{ {
this->_wal.getScene()->scheduleNewEntity("Bomb") this->_wal.getScene()->scheduleNewEntity("Bomb")
.addComponent<PositionComponent>(position.round()) .addComponent<PositionComponent>(position.round())
.addComponent<HealthComponent>(1, [](WAL::Entity &entity, WAL::Wal &wal) {
// the bomb explode when hit
entity.scheduleDeletion();
auto &pos = entity.getComponent<PositionComponent>();
auto &bombDetails = entity.getComponent<BasicBombComponent>();
BombHolderSystem::_dispatchExplosion(pos.position, wal, bombDetails.explosionRadius);
})
.addComponent<TagComponent<BlowablePass>>()
.addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, id) .addComponent<BasicBombComponent>(holder.damage, holder.explosionRadius, id)
.addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion) .addComponent<TimerComponent>(BombHolderSystem::explosionTimer, &BombHolderSystem::_bombExplosion)
.addComponent<CollisionComponent>( .addComponent<CollisionComponent>(

View File

@@ -30,7 +30,7 @@ namespace BBM
}; };
for (auto key : keyPressedMap) for (auto key : keyPressedMap)
key.second = gamepad.isPressed(key.first); key.second = gamepad.isDown(key.first);
controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1; controllable.move.x = gamepad.getAxisValue(gamepadComponent.LeftStickX) * -1;
controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1; controllable.move.y = gamepad.getAxisValue(gamepadComponent.LeftStickY) * -1;
controllable.move.x -= static_cast<float>(gamepad.isDown(gamepadComponent.keyRight)); controllable.move.x -= static_cast<float>(gamepad.isDown(gamepadComponent.keyRight));

View File

@@ -0,0 +1,173 @@
//
// Created by Zoe Roux on 6/11/21.
//
#include "System/Event/EventSystem.hpp"
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "System/Lobby/LobbySystem.hpp"
#include "Component/Controllable/ControllableComponent.hpp"
#include "System/MenuControllable/MenuControllableSystem.hpp"
#include "Component/Tag/TagComponent.hpp"
#include <algorithm>
#include <Runner/Runner.hpp>
#include <Component/Keyboard/KeyboardComponent.hpp>
#include <Component/Gamepad/GamepadComponent.hpp>
#include <Component/Position/PositionComponent.hpp>
#include <Component/Renderer/Drawable3DComponent.hpp>
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
std::array<std::string, 4> LobbySystem::_colors = {
"blue",
"red",
"green",
// "purple", TODO MISSING ICONS
// "cyan",
"yellow"
};
std::array<RAY::Color, 4> LobbySystem::_rayColors = {
BLUE,
RED,
GREEN,
// PURPLE,
// SKYBLUE,
YELLOW
};
LobbySystem::LobbySystem(WAL::Wal &wal)
: System(wal)
{}
void LobbySystem::_nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity)
{
auto &lobby = entity.get<LobbyComponent>();
if (lobby.color != -1)
this->_colorTaken[lobby.color] = false;
do {
lobby.color++;
if (lobby.color >= this->_colorTaken.size())
lobby.color = 0;
} while (this->_colorTaken[lobby.color]);
this->_colorTaken[lobby.color] = true;
entity.get<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icons/" + _colors[lobby.color] + ".png");
lobby.coloredTile.getComponent<Drawable2DComponent>().drawable->setColor(_rayColors[lobby.color]);
}
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
{
auto &lobby = entity.get<LobbyComponent>();
auto lastTick = std::chrono::steady_clock::now();
if (lastTick - lobby.lastInput < std::chrono::milliseconds(150))
return;
if (lobby.layout == ControllableComponent::NONE) {
for (auto &[_, ctrl] : this->_wal.getScene()->view<ControllableComponent>()) {
auto &controller = ctrl;
if (controller.jump) {
if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &view) {
return view.get<LobbyComponent>().layout == controller.layout;
}))
return;
lobby.lastInput = lastTick;
lobby.color = -1;
this->_nextColor(entity);
lobby.layout = controller.layout;
controller.jump = false;
return;
}
}
}
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
if (controller.layout != lobby.layout)
continue;
if (controller.jump && !lobby.ready) {
lobby.ready = true;
lobby.lastInput = lastTick;
controller.jump = false;
this->_wal.getSystem<MenuControllableSystem>().now = lastTick;
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
if (texture)
texture->use("assets/player/icons/ready.png");
}
if (controller.bomb && !lobby.ready) {
lobby.lastInput = lastTick;
this->_nextColor(entity);
}
}
}
void LobbySystem::onSelfUpdate()
{
auto &view = this->_wal.getScene()->view<TagComponent<"PlayButton">, Drawable2DComponent>();
if (view.size() == 0)
return;
auto *texture = dynamic_cast<RAY::Texture *>(view.front().get<Drawable2DComponent>().drawable.get());
if (!texture)
return;
if (playersAreReady(*this->_wal.getScene()))
texture->setColor(WHITE);
else
texture->setColor(GRAY);
}
bool LobbySystem::playersAreReady(WAL::Scene &scene)
{
auto &lobby = scene.view<LobbyComponent>();
return std::all_of(lobby.begin(), lobby.end(), [](WAL::ViewEntity<LobbyComponent> &entity) {
auto &lobbyPlayer = entity.get<LobbyComponent>();
return lobbyPlayer.ready || lobbyPlayer.layout == ControllableComponent::NONE;
});
}
void LobbySystem::_addController(WAL::Entity &player, ControllableComponent::Layout layout)
{
switch (layout) {
case ControllableComponent::KEYBOARD_0:
case ControllableComponent::KEYBOARD_1:
player.addComponent<KeyboardComponent>(layout);
break;
case ControllableComponent::GAMEPAD_0:
player.addComponent<GamepadComponent>(0);
break;
case ControllableComponent::GAMEPAD_1:
player.addComponent<GamepadComponent>(1);
break;
case ControllableComponent::GAMEPAD_2:
player.addComponent<GamepadComponent>(2);
break;
case ControllableComponent::GAMEPAD_3:
player.addComponent<GamepadComponent>(3);
break;
default:
throw std::runtime_error("Invalid controller for a player.");
}
}
void LobbySystem::switchToGame(WAL::Wal &wal)
{
auto scene = Runner::loadGameScene();
int mapWidth = 16;
int mapHeight = 16;
int playerCount = 0;
for (auto &[_, lobby] : wal.getScene()->view<LobbyComponent>()) {
if (lobby.layout == ControllableComponent::NONE)
continue;
auto &player = Runner::createPlayer(*scene);
_addController(player, lobby.layout);
player.getComponent<PositionComponent>().position = Vector3f(mapWidth * (playerCount % 2),
0,
mapHeight * ((playerCount + 1) % 2));
auto *model = dynamic_cast<RAY3D::Model *>(player.getComponent<Drawable3DComponent>().drawable.get());
model->setTextureToMaterial(MAP_DIFFUSE, "assets/player/textures/" + _colors[lobby.color] + ".png");
playerCount++;
}
Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene;
Runner::gameState.nextScene = BBM::GameState::SceneID::GameScene;
}
}

View File

@@ -0,0 +1,54 @@
//
// Created by Zoe Roux on 6/11/21.
//
#pragma once
#include "System/System.hpp"
#include "Component/Lobby/LobbyComponent.hpp"
#include "Component/Controllable/ControllableComponent.hpp"
#include "Entity/Entity.hpp"
#include <array>
#include <string>
namespace BBM
{
//! @brief A system to handle Health entities.
class LobbySystem : public WAL::System<LobbyComponent, Drawable2DComponent>
{
private:
//! @brief Add a controller for the player.
static void _addController(WAL::Entity &player, ControllableComponent::Layout layout);
void _nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity);
static std::array<std::string, 4> _colors;
static std::array<RAY::Color, 4> _rayColors;
std::array<bool, 4> _colorTaken = {};
public:
//! @inherit
void onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
//! @inherit
void onSelfUpdate() override;
//! @brief Check if every player is ready.
//! @param scene The lobby scene containing lobby players.
static bool playersAreReady(WAL::Scene &scene);
//! @brief Inform the engine that the next scene should be the game scene and load it.
//! @param wal The engine.
static void switchToGame(WAL::Wal &wal);
//! @brief A default constructor
explicit LobbySystem(WAL::Wal &wal);
//! @brief A Lobby system is copy constructable
LobbySystem(const LobbySystem &) = default;
//! @brief A default destructor
~LobbySystem() override = default;
//! @brief A system is not assignable.
LobbySystem &operator=(const LobbySystem &) = delete;
};
}

View File

@@ -4,7 +4,6 @@
#include <algorithm> #include <algorithm>
#include "Component/Button/ButtonComponent.hpp" #include "Component/Button/ButtonComponent.hpp"
#include "Component/Position/PositionComponent.hpp"
#include "System/MenuControllable/MenuControllableSystem.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp"
#include "Component/Controllable/ControllableComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp"
#include "Entity/Entity.hpp" #include "Entity/Entity.hpp"
@@ -12,12 +11,13 @@
namespace BBM namespace BBM
{ {
MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal) MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal)
: System(wal), wal(wal), currentButton() : System(wal),
_currentButton()
{} {}
void MenuControllableSystem::updateCurrentButton(bool selected) void MenuControllableSystem::_updateCurrentButton(bool selected, Vector2f move)
{ {
auto buttonComponent = this->currentButton->getComponent<OnClickComponent>(); auto &buttonComponent = this->_currentButton->getComponent<OnClickComponent>();
WAL::Entity *newButton = nullptr; WAL::Entity *newButton = nullptr;
if (move.y > 0 && buttonComponent._up) if (move.y > 0 && buttonComponent._up)
@@ -28,42 +28,38 @@ namespace BBM
newButton = buttonComponent._right; newButton = buttonComponent._right;
if (move.x > 0 && buttonComponent._left) if (move.x > 0 && buttonComponent._left)
newButton = buttonComponent._left; newButton = buttonComponent._left;
if (newButton || selected) {
auto lastTick = std::chrono::steady_clock::now();
if (lastTick - this->now < std::chrono::milliseconds(150))
return;
this->now = lastTick;
}
if (newButton) { if (newButton) {
this->currentButton->getComponent<OnIdleComponent>().onEvent(*this->currentButton, wal); this->_currentButton->getComponent<OnIdleComponent>().onEvent(*this->_currentButton, this->_wal);
this->currentButton = newButton; this->_currentButton = newButton;
this->currentButton->getComponent<OnHoverComponent>().onEvent(*this->currentButton, wal); this->_currentButton->getComponent<OnHoverComponent>().onEvent(*this->_currentButton, this->_wal);
} }
if (selected) if (selected)
this->currentButton->getComponent<OnClickComponent>().onEvent(*this->currentButton, wal); this->_currentButton->getComponent<OnClickComponent>().onEvent(*this->_currentButton, this->_wal);
} }
void MenuControllableSystem::onFixedUpdate(WAL::ViewEntity<ControllableComponent> &entity) void MenuControllableSystem::onFixedUpdate(WAL::ViewEntity<ControllableComponent> &entity)
{ {
auto lastTick = std::chrono::steady_clock::now();
auto &controllable = entity.get<ControllableComponent>(); auto &controllable = entity.get<ControllableComponent>();
auto &buttons = _wal.getScene()->view<OnClickComponent, OnHoverComponent, OnIdleComponent>(); auto &buttons = _wal.getScene()->view<OnClickComponent, OnHoverComponent, OnIdleComponent>();
if (lastTick - this->_now < std::chrono::milliseconds(100)) if (this->_currentButton && this->_currentButton->_scene.getID() != this->_wal.getScene()->getID()) {
this->_currentButton->getComponent<OnIdleComponent>().onEvent(*this->_currentButton, this->_wal);
this->_currentButton = nullptr;
}
if (this->_currentButton == nullptr && buttons.size()) {
this->_currentButton = &(*buttons.front());
this->_currentButton->getComponent<OnHoverComponent>().onEvent(*this->_currentButton, this->_wal);
}
if (!this->_currentButton)
return; return;
this->_now = lastTick; this->_updateCurrentButton(controllable.jump, controllable.move);
move = controllable.move;
select = controllable.jump;
if (currentButton && currentButton->_scene.getID() != wal.getScene()->getID()) {
currentButton->getComponent<OnIdleComponent>().onEvent(*this->currentButton, wal);
currentButton = nullptr;
}
if (currentButton == nullptr && buttons.size()) {
currentButton = &(**buttons.begin());
currentButton->getComponent<OnHoverComponent>().onEvent(*this->currentButton, wal);
}
if (!currentButton)
return;
this->updateCurrentButton(select);
}
void MenuControllableSystem::onSelfUpdate(void)
{
} }
} }

View File

@@ -14,41 +14,26 @@ namespace BBM
class MenuControllableSystem : public WAL::System<ControllableComponent> class MenuControllableSystem : public WAL::System<ControllableComponent>
{ {
private: private:
//! @brief reference to wal
WAL::Wal &wal;
//! @brief index of the current button selected //! @brief index of the current button selected
WAL::Entity *currentButton; WAL::Entity *_currentButton;
//! @brief move vector
Vector2f move;
//! @brief Select action
bool select = false;
//! @brief Cancel action
bool cancel = false;
//! @brief update current button reference //! @brief update current button reference
//! @param selected lets know if te new selected button is 'pressed' //! @param selected lets know if te new selected button is 'pressed'
void updateCurrentButton(bool selected); void _updateCurrentButton(bool selected, Vector2f move);
//! @brief time (in mili second) since last check
std::chrono::time_point<std::chrono::steady_clock> _now;
public: public:
//! @inherit //! @brief time (in millisecond) since last check
void onSelfUpdate(void) override; std::chrono::time_point<std::chrono::steady_clock> now;
//! @inherit //! @inherit
void onFixedUpdate(WAL::ViewEntity<ControllableComponent> &entities) override; void onFixedUpdate(WAL::ViewEntity<ControllableComponent> &entities) override;
//! @brief A default constructor //! @brief A default constructor
MenuControllableSystem(WAL::Wal &wal); explicit MenuControllableSystem(WAL::Wal &wal);
//! @brief A MenuControllable system is not copy constructable //! @brief A MenuControllable system is not copy constructable
MenuControllableSystem(const MenuControllableSystem &) = delete; MenuControllableSystem(const MenuControllableSystem &) = delete;
//! @brief A default destructor //! @brief A default destructor
~MenuControllableSystem() override = default; ~MenuControllableSystem() override = default;
//! @brief A MenuControllable system is assignable. //! @brief A MenuControllable system is not assignable.
MenuControllableSystem &operator=(const MenuControllableSystem &) = default; MenuControllableSystem &operator=(const MenuControllableSystem &) = delete;
}; };
} }