diff --git a/CMakeLists.txt b/CMakeLists.txt index d7dc8112f..b545bd0ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,9 @@ set(SOURCES sources/Component/Collision/CollisionComponent.hpp sources/System/Collision/CollisionSystem.hpp sources/System/Collision/CollisionSystem.cpp + sources/Component/Button/ButtonComponent.hpp + sources/System/MenuControllable/MenuControllableSystem.cpp + sources/System/MenuControllable/MenuControllableSystem.hpp sources/Component/Animator/AnimatorComponent.cpp sources/Component/Animator/AnimatorComponent.hpp sources/System/Animator/AnimatorSystem.cpp @@ -88,6 +91,8 @@ set(SOURCES 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 diff --git a/assets/bomberman.TTF b/assets/bomberman.TTF new file mode 100644 index 000000000..f44247055 Binary files /dev/null and b/assets/bomberman.TTF differ diff --git a/assets/buttons/button_back.png b/assets/buttons/button_back.png new file mode 100644 index 000000000..1d461ced3 Binary files /dev/null and b/assets/buttons/button_back.png differ diff --git a/assets/buttons/button_back_hovered.png b/assets/buttons/button_back_hovered.png new file mode 100644 index 000000000..460a64ce3 Binary files /dev/null and b/assets/buttons/button_back_hovered.png differ diff --git a/assets/buttons/button_exit.png b/assets/buttons/button_exit.png new file mode 100644 index 000000000..3dbfacfc9 Binary files /dev/null and b/assets/buttons/button_exit.png differ diff --git a/assets/buttons/button_exit_hovered.png b/assets/buttons/button_exit_hovered.png new file mode 100644 index 000000000..ac6571f43 Binary files /dev/null and b/assets/buttons/button_exit_hovered.png differ diff --git a/assets/buttons/button_minus.png b/assets/buttons/button_minus.png new file mode 100644 index 000000000..4d0020692 Binary files /dev/null and b/assets/buttons/button_minus.png differ diff --git a/assets/buttons/button_minus_hovered.png b/assets/buttons/button_minus_hovered.png new file mode 100644 index 000000000..f07e6896f Binary files /dev/null and b/assets/buttons/button_minus_hovered.png differ diff --git a/assets/buttons/button_new_game.png b/assets/buttons/button_new_game.png new file mode 100644 index 000000000..1b184e7bb Binary files /dev/null and b/assets/buttons/button_new_game.png differ diff --git a/assets/buttons/button_new_game_hovered.png b/assets/buttons/button_new_game_hovered.png new file mode 100644 index 000000000..3d9a8e750 Binary files /dev/null and b/assets/buttons/button_new_game_hovered.png differ diff --git a/assets/buttons/button_plus.png b/assets/buttons/button_plus.png new file mode 100644 index 000000000..e31e31e51 Binary files /dev/null and b/assets/buttons/button_plus.png differ diff --git a/assets/buttons/button_plus_hovered.png b/assets/buttons/button_plus_hovered.png new file mode 100644 index 000000000..d4ef106e2 Binary files /dev/null and b/assets/buttons/button_plus_hovered.png differ diff --git a/assets/buttons/button_settings.png b/assets/buttons/button_settings.png new file mode 100644 index 000000000..31b628b4b Binary files /dev/null and b/assets/buttons/button_settings.png differ diff --git a/assets/buttons/button_settings_hovered.png b/assets/buttons/button_settings_hovered.png new file mode 100644 index 000000000..8f42d3e54 Binary files /dev/null and b/assets/buttons/button_settings_hovered.png differ diff --git a/assets/buttons/tickbox_ticked.png b/assets/buttons/tickbox_ticked.png new file mode 100644 index 000000000..7059fad55 Binary files /dev/null and b/assets/buttons/tickbox_ticked.png differ diff --git a/assets/buttons/tickbox_unticked.png b/assets/buttons/tickbox_unticked.png new file mode 100644 index 000000000..a63e92ca8 Binary files /dev/null and b/assets/buttons/tickbox_unticked.png differ diff --git a/assets/logo_big.png b/assets/logo_big.png new file mode 100644 index 000000000..a68c69dc7 Binary files /dev/null and b/assets/logo_big.png differ diff --git a/assets/logo_small.png b/assets/logo_small.png new file mode 100644 index 000000000..18d67ffb3 Binary files /dev/null and b/assets/logo_small.png differ diff --git a/assets/musics/music_battle.ogg b/assets/musics/music_battle.ogg index ddc302188..affce4e30 100644 Binary files a/assets/musics/music_battle.ogg and b/assets/musics/music_battle.ogg differ diff --git a/assets/musics/music_player_select.ogg b/assets/musics/music_player_select.ogg index 8889fd0b7..1d412d1ed 100644 Binary files a/assets/musics/music_player_select.ogg and b/assets/musics/music_player_select.ogg differ diff --git a/assets/musics/music_result.ogg b/assets/musics/music_result.ogg index 1f82ad239..9c6ad0fcf 100644 Binary files a/assets/musics/music_result.ogg and b/assets/musics/music_result.ogg differ diff --git a/assets/musics/music_title.ogg b/assets/musics/music_title.ogg index 86d6e7ee5..e6d636612 100644 Binary files a/assets/musics/music_title.ogg and b/assets/musics/music_title.ogg differ diff --git a/assets/plain_menu_background.png b/assets/plain_menu_background.png new file mode 100644 index 000000000..9cb1e0e11 Binary files /dev/null and b/assets/plain_menu_background.png differ diff --git a/assets/raylib.png b/assets/raylib.png new file mode 100644 index 000000000..4576dd0fc Binary files /dev/null and b/assets/raylib.png differ diff --git a/assets/sounds/click.ogg b/assets/sounds/click.ogg new file mode 100644 index 000000000..4d328e60c Binary files /dev/null and b/assets/sounds/click.ogg differ diff --git a/lib/Ray/sources/Drawables/Image.cpp b/lib/Ray/sources/Drawables/Image.cpp index 685aa3765..a95246be7 100644 --- a/lib/Ray/sources/Drawables/Image.cpp +++ b/lib/Ray/sources/Drawables/Image.cpp @@ -8,13 +8,15 @@ #include "Drawables/Image.hpp" #include "Drawables/ADrawable2D.hpp" #include "Drawables/2D/Rectangle.hpp" +#include "Exceptions/RayError.hpp" namespace RAY { Cache<::Image> Image::_imagesCache(LoadImage, UnloadImage); Image::Image(const std::string &filename, bool lonely): Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), - _image(_imagesCache.fetch(filename, lonely)) + _image(_imagesCache.fetch(filename, lonely)), + _ressourcePath(filename) { this->_dimensions = Vector2(this->_image->width, this->_image->height); } @@ -30,6 +32,15 @@ namespace RAY { return *this->_image; } + Image &Image::use(const std::string &filename) + { + if (this->_ressourcePath == filename) + return *this; + this->_image = this->_imagesCache.fetch(filename); + this->_ressourcePath = filename; + return *this; + } + Image::operator ::Image *() { return this->_image.get(); @@ -40,16 +51,15 @@ namespace RAY { drawable.drawOn(*this); } - void Image::drawOn(RAY::Window &) + void Image::resize(const RAY::Vector2 &dimensions) { - //Since the image is a shared object, when it is resized, it mush be resized after to its previous dimensions - Vector2 oldDims = Vector2(this->_image->width, this->_image->height); - - ImageResize(*this, this->_dimensions.x, this->_dimensions.y); - Texture texture(*this); + ImageResize(*this, dimensions.x, dimensions.y); + this->setDimensions(dimensions); + } - DrawTexture(texture, this->_position.x, this->_position.y, this->_color); - ImageResize(*this, oldDims.x, oldDims.y); + void Image::drawOn(RAY::Window &) + { + throw RAY::Exception::NotSupportedError("An image cannot be drawn onto a window"); } void Image::drawOn(RAY::Image &image) diff --git a/lib/Ray/sources/Drawables/Image.hpp b/lib/Ray/sources/Drawables/Image.hpp index 911f1a966..7963328d6 100644 --- a/lib/Ray/sources/Drawables/Image.hpp +++ b/lib/Ray/sources/Drawables/Image.hpp @@ -45,7 +45,12 @@ namespace RAY //! @brief Draw image on another image void drawOn(RAY::Image &image) override; + + //! @brief Resize image; + void resize(const RAY::Vector2 &dimensions); + //! @brief Load image from file, lets one use one entity for multiple files + Image &use(const std::string &filename); private: //! @brief Image, really, that's just it... @@ -53,6 +58,8 @@ namespace RAY static Cache<::Image> _imagesCache; + std::string _ressourcePath; + INTERNAL: //! @brief get image diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index 821a743d9..dfdf1213a 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -6,25 +6,46 @@ */ #include "Drawables/Texture.hpp" +#include "Drawables/2D/Rectangle.hpp" +#include "Drawables/Image.hpp" namespace RAY { Cache<::Texture> Texture::_texturesCache(LoadTexture, UnloadTexture); Texture::Texture(const std::string &filename, bool lonely): + Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), _texture(_texturesCache.fetch(filename, lonely)), _resourcePath(filename) { + this->_dimensions = Vector2(this->_texture->width, this->_texture->height); } Texture::Texture(const Image &image): + Rectangle(Vector2(0, 0), Vector2(0, 0), WHITE), _texture(std::make_shared<::Texture>(LoadTextureFromImage(image))), _resourcePath() { } + Texture &Texture::use(const std::string &filename) + { + if (this->_resourcePath == filename) + return *this; + this->_texture = this->_texturesCache.fetch(filename); + this->_resourcePath = filename; + return *this; + } + Texture::operator ::Texture() const { return *this->_texture; } + + void Texture::drawOn(RAY::Window &) + { + float scale = this->_dimensions.x / this->_texture->width; + + DrawTextureEx(*this, this->_position, 0, scale, this->_color); + } } diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 2952b58de..931699e2f 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -11,11 +11,12 @@ #include #include #include "Utils/Cache.hpp" +#include "Drawables/2D/Rectangle.hpp" namespace RAY { //! @brief Object representation of a texture - class Texture { + class Texture: public Drawables::Drawables2D::Rectangle { public: //! @brief Create an texture, loading a file //! @param filename: path to file to load @@ -34,6 +35,12 @@ namespace RAY //! @brief Texture destructor, will not unload ressources ~Texture() = default; + //! @brief draw texture on a window + void drawOn(RAY::Window &) override; + + //! @brief Load texture from file, lets one use one entity for multiple files + Texture &use(const std::string &filename); + protected: private: //! @brief Texture, really, that's just it... diff --git a/lib/Ray/sources/Window.cpp b/lib/Ray/sources/Window.cpp index a9a1d9bf4..8a41d8509 100644 --- a/lib/Ray/sources/Window.cpp +++ b/lib/Ray/sources/Window.cpp @@ -49,6 +49,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; } @@ -160,11 +161,6 @@ void RAY::Window::draw(RAY::Drawables::IDrawable &drawable) drawable.drawOn(*this); } -void RAY::Window::draw(const RAY::Texture &texture, const Vector2 &position, const Color &tint) -{ - DrawTexture(texture, position.x, position.y, tint); -} - void RAY::Window::draw(const Mesh &mesh, const Material &material, const Matrix &transform) { DrawMesh(mesh, material, transform); @@ -183,4 +179,9 @@ void RAY::Window::drawFPS(const RAY::Vector2 &position) bool RAY::Window::isReady() const { return IsWindowReady(); +} + +void RAY::Window::setExitKey(RAY::Controller::Keyboard::Key key) +{ + SetExitKey(key); } \ No newline at end of file diff --git a/lib/Ray/sources/Window.hpp b/lib/Ray/sources/Window.hpp index f3c507b09..525f29923 100644 --- a/lib/Ray/sources/Window.hpp +++ b/lib/Ray/sources/Window.hpp @@ -17,7 +17,6 @@ #include "Camera/Camera2D.hpp" #include "Camera/Camera3D.hpp" #include "Color.hpp" -#include "Drawables/Texture.hpp" namespace RAY { //! @brief Window manager @@ -124,12 +123,6 @@ namespace RAY { //! @param drawable The drawable to render on screen void draw(RAY::Drawables::IDrawable &drawable); - //! @brief draw texture at position - //! @param texture The object to render - //! @param position The position of the texture relative to the top left window corner - //! @param tint - void draw(const Texture &texture, const Vector2 &position, const Color &tint); - //! @brief Draw a 3d mesh with material and transform void draw(const Mesh &mesh, const Material &material, const Matrix &transform); @@ -138,6 +131,11 @@ namespace RAY { //! @return true if the window's context has been correctly initialized bool isReady() const; + //! @param key if this key is pressed, the window will close + //! @info Default is ESC key + //! @info Calling this function override the previous closing key + void setExitKey(Controller::Keyboard::Key key); + private: //! @brief Creates window, and opens it if openNow is set to true diff --git a/lib/wal/sources/Entity/Entity.cpp b/lib/wal/sources/Entity/Entity.cpp index 8e4ff0f18..0142a4aa4 100644 --- a/lib/wal/sources/Entity/Entity.cpp +++ b/lib/wal/sources/Entity/Entity.cpp @@ -85,6 +85,11 @@ namespace WAL this->_scene._componentRemoved(*this, type); } + bool Entity::operator==(const Entity &other) const + { + return other.getUid() == this->_uid; + } + bool Entity::shouldDelete() const { return this->_shouldDelete; diff --git a/lib/wal/sources/Entity/Entity.hpp b/lib/wal/sources/Entity/Entity.hpp index aa7521364..5cffcc5f2 100644 --- a/lib/wal/sources/Entity/Entity.hpp +++ b/lib/wal/sources/Entity/Entity.hpp @@ -46,9 +46,9 @@ namespace WAL friend Scene; friend class Wal; protected: + public: //! @brief A reference to the ECS. Scene &_scene; - public: //! @brief Get the ID of the entity. unsigned getUid() const; //! @brief Get the name fo the entity @@ -181,5 +181,8 @@ namespace WAL ~Entity() = default; //! @brief An entity is not assignable Entity &operator=(const Entity &) = delete; + + //! @return true if the two entities hold the same uid + bool operator==(const Entity &) const; }; } // namespace WAL \ No newline at end of file diff --git a/lib/wal/sources/Scene/Scene.cpp b/lib/wal/sources/Scene/Scene.cpp index 493c79320..aab82e82f 100644 --- a/lib/wal/sources/Scene/Scene.cpp +++ b/lib/wal/sources/Scene/Scene.cpp @@ -51,6 +51,11 @@ namespace WAL } } + int Scene::getID() const + { + return this->_id; + } + void Scene::_entityRemoved(const Entity &entity) { for (auto &view : this->_views) @@ -81,9 +86,4 @@ namespace WAL } this->_entities.splice(this->_entities.end(), this->_newEntities); } - - int Scene::getID() const - { - return this->_id; - } } // namespace WAL \ No newline at end of file diff --git a/sources/Component/Button/ButtonComponent.hpp b/sources/Component/Button/ButtonComponent.hpp new file mode 100644 index 000000000..42055be62 --- /dev/null +++ b/sources/Component/Button/ButtonComponent.hpp @@ -0,0 +1,74 @@ +// +// Created by Louis Auzuret on 06/03/21 +// + +#pragma once + +#include "Models/Callback.hpp" +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include +#include "Wal.hpp" + +namespace BBM +{ + enum ButtonComponentType { IDLE, CLICK, HOVER }; + + template + class ButtonComponent: public WAL::Component + { + public: + //! @brief onEvent callback + WAL::Callback onEvent; + + //! @brief button which is at the top of this button + WAL::Entity *_up; + //! @brief button which is below of this button + WAL::Entity *_down; + //! @brief button which is on the right of this button + WAL::Entity *_right; + //! @brief button which is on the left of this button + WAL::Entity *_left; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override + { + return new ButtonComponent(entity, onEvent); + } + + //! @brief Initialize a new Button component. + explicit ButtonComponent(WAL::Entity &entity) + : WAL::Component(entity), onEvent() + { } + + //! @brief Constructor with the 3 callback + ButtonComponent(WAL::Entity &entity, WAL::Callback callback) + : WAL::Component(entity), + onEvent(callback), _up(nullptr), _down(nullptr), _left(nullptr), _right(nullptr) + { } + + ButtonComponent &setButtonLinks(WAL::Entity *up = nullptr, WAL::Entity *down = nullptr, + WAL::Entity *left = nullptr, WAL::Entity *right = nullptr) + { + this->_up = up; + this->_down = down; + this->_left = left; + this->_right = right; + return *this; + } + + //! @brief A Controllable component is copy constructable. + ButtonComponent(const ButtonComponent &) = default; + //! @brief default destructor + ~ButtonComponent() override = default; + //! @brief A Button component default assign operator + ButtonComponent &operator=(const ButtonComponent &) = default; + + //! @brief Empty button callback + static void emptyButtonCallback(WAL::Entity &) + { } + }; + typedef ButtonComponent OnIdleComponent; + typedef ButtonComponent OnClickComponent; + typedef ButtonComponent OnHoverComponent; +} diff --git a/sources/Component/Keyboard/KeyboardComponent.hpp b/sources/Component/Keyboard/KeyboardComponent.hpp index 2ad2e6f24..36ac49686 100644 --- a/sources/Component/Keyboard/KeyboardComponent.hpp +++ b/sources/Component/Keyboard/KeyboardComponent.hpp @@ -21,7 +21,7 @@ namespace BBM //! @brief bomb key Key keyBomb = KEY_E; //! @brief pause key - Key keyPause = KEY_ESCAPE; + Key keyPause = RAY::Controller::Keyboard::Key::KEY_ESCAPE; //! @brief move right key Key keyRight = KEY_D; //! @brief move left key diff --git a/sources/Component/Music/MusicComponent.cpp b/sources/Component/Music/MusicComponent.cpp index 40dc33b14..ae6a91517 100644 --- a/sources/Component/Music/MusicComponent.cpp +++ b/sources/Component/Music/MusicComponent.cpp @@ -39,15 +39,15 @@ namespace BBM this->_music.pause(); } - void MusicComponent::setVolume(float &volumeUpdate) + void MusicComponent::setVolume(float volumeUpdate) { - if (volumeUpdate >= 0) { + if (volumeUpdate >= 0 && volumeUpdate <= 1) { this->volume = volumeUpdate; this->_music.setVolume(this->volume); } } - void MusicComponent::setPitch(float &pitch) + void MusicComponent::setPitch(float pitch) { this->_music.setPitch(pitch); } @@ -62,4 +62,14 @@ namespace BBM this->_music.updateMusicStream(); } + void MusicComponent::turnDownVolume() + { + this->setVolume(MusicComponent::volume - 0.1); + } + + void MusicComponent::turnUpVolume() + { + this->setVolume(MusicComponent::volume + 0.1); + } + } // namespace WAL diff --git a/sources/Component/Music/MusicComponent.hpp b/sources/Component/Music/MusicComponent.hpp index 7898fd6e3..3251ff439 100644 --- a/sources/Component/Music/MusicComponent.hpp +++ b/sources/Component/Music/MusicComponent.hpp @@ -24,10 +24,16 @@ namespace BBM void pauseMusic(); //! @brief set music volume - void setVolume(float &); + void setVolume(float); + + //! @brief volume -= 0.1 + void turnDownVolume(); + + //! @brief volume += 0.1 + void turnUpVolume(); //! @brief set pitch volume - void setPitch(float &); + void setPitch(float); //! @brief is music playing bool isPlaying(void); diff --git a/sources/Component/Sound/SoundComponent.cpp b/sources/Component/Sound/SoundComponent.cpp index a2dde1db8..038b58e1c 100644 --- a/sources/Component/Sound/SoundComponent.cpp +++ b/sources/Component/Sound/SoundComponent.cpp @@ -56,17 +56,16 @@ namespace BBM this->_soundList[this->_soundIndex].get()->pause(); } - void SoundComponent::setVolume(float &volumeUpdate) + void SoundComponent::setVolume(float volumeUpdate) { - if (!this->_isSoundLoad.at(this->_soundIndex)) - return; - if (volumeUpdate >= 0) { + if (volumeUpdate >= 0 && volumeUpdate <= 1) { this->volume = volumeUpdate; - this->_soundList[this->_soundIndex].get()->setVolume(this->volume); + for (auto &sound : _soundList) + sound.second->setVolume(volume); } } - void SoundComponent::setPitch(float &pitch) + void SoundComponent::setPitch(float pitch) { if (!this->_isSoundLoad.at(this->_soundIndex)) return; @@ -90,4 +89,14 @@ namespace BBM return (this->_soundIndex); } + void SoundComponent::turnDownVolume() + { + this->setVolume(SoundComponent::volume - 0.1); + } + + void SoundComponent::turnUpVolume() + { + this->setVolume(SoundComponent::volume + 0.1); + } + } // namespace WAL diff --git a/sources/Component/Sound/SoundComponent.hpp b/sources/Component/Sound/SoundComponent.hpp index 926d02cce..ec42fd24e 100644 --- a/sources/Component/Sound/SoundComponent.hpp +++ b/sources/Component/Sound/SoundComponent.hpp @@ -42,10 +42,16 @@ namespace BBM void pauseSound(); //! @brief set Sound volume - void setVolume(float &); + void setVolume(float); + + //! @brief volume -= 0.1 + void turnDownVolume(); + + //! @brief volume += 0.1 + void turnUpVolume(); //! @brief set pitch volume - void setPitch(float &); + void setPitch(float); //! @brief is Sound playing bool isPlaying(); diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index 883578bfc..61f7f3090 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -14,18 +14,27 @@ namespace BBM //! @brief A class representing the current game state. This allow one to retain information between update calls. class GameState { + public: //! @brief The list of scenes available. enum SceneID { - MainMenu, - GameScene + MainMenuScene, + GameScene, + SettingsScene, + PauseMenuScene, + LobbyScene, + TitleScreenScene, + CreditScene, }; //! @brief The currently loaded scene - SceneID currentScene = MainMenu; + SceneID currentScene = TitleScreenScene; + + //! @brief The next scene to load (if smae as currentScene, nothing to do) + SceneID nextScene = TitleScreenScene; //! @brief The list of loaded scenes. - std::unordered_map _loadedScenes = {}; + std::unordered_map> _loadedScenes = {}; }; } \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 2ee460623..6d6b36cb2 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -9,6 +9,10 @@ #include #include #include +#include +#include