diff --git a/lib/Ray/sources/Model/ModelAnimation.cpp b/lib/Ray/sources/Model/ModelAnimation.cpp index 8569c6dd..043f57e3 100644 --- a/lib/Ray/sources/Model/ModelAnimation.cpp +++ b/lib/Ray/sources/Model/ModelAnimation.cpp @@ -5,9 +5,10 @@ ** ModelAnimation */ +#include #include "Model/ModelAnimation.hpp" -RAY::ModelAnimation::ModelAnimation(::ModelAnimation &animation): +RAY::ModelAnimation::ModelAnimation(::ModelAnimation *animation): _animation(animation), _frameCounter(0) { } @@ -19,28 +20,31 @@ size_t RAY::ModelAnimation::getFrameCounter() const size_t RAY::ModelAnimation::getFrameCount() const { - return this->_animation.frameCount; + return this->_animation->frameCount; } RAY::ModelAnimation &RAY::ModelAnimation::setFrameCounter(size_t frameCounter) { - this->_frameCounter = frameCounter % this->_animation.frameCount; + std::cout << this << std::endl; + std::cout << this->_animation << std::endl; + std::cout << this->_animation->frameCount << std::endl; + this->_frameCounter = frameCounter % this->_animation->frameCount; return *this; } RAY::ModelAnimation &RAY::ModelAnimation::incrementFrameCounter() { - this->_frameCounter = (this->_frameCounter + 1) % this->_animation.frameCount; + this->_frameCounter = (this->_frameCounter + 1) % this->_animation->frameCount; return *this; } RAY::ModelAnimation::operator ::ModelAnimation() const { - return this->_animation; + return *this->_animation; } RAY::ModelAnimation::operator ::ModelAnimation *() { - return &this->_animation; + return this->_animation; } \ No newline at end of file diff --git a/lib/Ray/sources/Model/ModelAnimation.hpp b/lib/Ray/sources/Model/ModelAnimation.hpp index 308599ba..5386fec2 100644 --- a/lib/Ray/sources/Model/ModelAnimation.hpp +++ b/lib/Ray/sources/Model/ModelAnimation.hpp @@ -17,7 +17,7 @@ namespace RAY { public: //! @brief A Model animation constructor //! @param animationPtr an animation pointer, returned by the nimation-loading function - ModelAnimation(::ModelAnimation &animationPtr); + ModelAnimation(::ModelAnimation *animationPtr); //! @brief A default copy-constructor ModelAnimation(const ModelAnimation &) = default; @@ -41,7 +41,7 @@ namespace RAY { ~ModelAnimation() = default; private: - ::ModelAnimation &_animation; + ::ModelAnimation *_animation; size_t _frameCounter; INTERNAL: diff --git a/lib/Ray/sources/Model/ModelAnimations.cpp b/lib/Ray/sources/Model/ModelAnimations.cpp index 6d41832d..7f1af249 100644 --- a/lib/Ray/sources/Model/ModelAnimations.cpp +++ b/lib/Ray/sources/Model/ModelAnimations.cpp @@ -16,7 +16,7 @@ RAY::ModelAnimations::ModelAnimations(const std::string &filePath): ::ModelAnimation *ptr = this->_animationsPtr.get(); for (int i = 0; i < this->_animationCount; i++) - this->_animations.emplace_back(ptr[i]); + this->_animations.emplace_back(ptr + i); } RAY::ModelAnimation &RAY::ModelAnimations::operator[](int index) diff --git a/sources/Component/Animation/AnimationsComponent.cpp b/sources/Component/Animation/AnimationsComponent.cpp index 2922683e..4acf5041 100644 --- a/sources/Component/Animation/AnimationsComponent.cpp +++ b/sources/Component/Animation/AnimationsComponent.cpp @@ -8,9 +8,9 @@ namespace BBM { - AnimationsComponent::AnimationsComponent(WAL::Entity &entity, const RAY::ModelAnimations &modelAnimation, int animIndex, bool play) + AnimationsComponent::AnimationsComponent(WAL::Entity &entity, int animIndex, bool play) : WAL::Component(entity), - _modelAnimation(modelAnimation), + _modelAnimation("assets/player/player.iqm"), _currentAnimIndex(animIndex), _animDisabled(play) { @@ -20,7 +20,6 @@ namespace BBM WAL::Component *AnimationsComponent::clone(WAL::Entity &entity) const { return new AnimationsComponent(entity, - RAY::ModelAnimations(this->_modelAnimation.getFilePath()), this->_currentAnimIndex); } @@ -29,7 +28,7 @@ namespace BBM return this->_modelAnimation.at(this->_currentAnimIndex).getFrameCounter(); } - RAY::ModelAnimation AnimationsComponent::getCurrentModelAnim() + RAY::ModelAnimation &AnimationsComponent::getCurrentModelAnim() { return this->_modelAnimation[this->_currentAnimIndex]; } diff --git a/sources/Component/Animation/AnimationsComponent.hpp b/sources/Component/Animation/AnimationsComponent.hpp index 7d037094..8f4e6a6e 100644 --- a/sources/Component/Animation/AnimationsComponent.hpp +++ b/sources/Component/Animation/AnimationsComponent.hpp @@ -34,7 +34,7 @@ namespace BBM size_t getCurrentAnimFrameCounter() const; //! @brief get the current - RAY::ModelAnimation getCurrentModelAnim(); + RAY::ModelAnimation &getCurrentModelAnim(); //! @brief set the anim frame counter void setCurrentAnimFrameCounter(size_t animFrameCounter); @@ -52,7 +52,7 @@ namespace BBM bool isAnimDisabled() const; //! @brief ctor entity and the path of the animation file - explicit AnimationsComponent(WAL::Entity &entity, const RAY::ModelAnimations& modelAnimation, int animIndex, bool play = true); + AnimationsComponent(WAL::Entity &entity, int animIndex, bool play = true); //! @brief copy ctor AnimationsComponent(const AnimationsComponent &) = default; //! @brief dtor diff --git a/sources/Component/Lobby/LobbyComponent.hpp b/sources/Component/Lobby/LobbyComponent.hpp index 28135c11..18647649 100644 --- a/sources/Component/Lobby/LobbyComponent.hpp +++ b/sources/Component/Lobby/LobbyComponent.hpp @@ -19,8 +19,8 @@ namespace BBM ControllableComponent::Layout layout = ControllableComponent::NONE; //! @brief The ID of the lobby player (from 0 to 3) int playerID; - //! @brief The color of the player - RAY::Color color = RED; + //! @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. diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index dda31514..55f2f28c 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -16,7 +16,6 @@ #include "Component/Shaders/ShaderComponent.hpp" #include "Component/Tag/TagComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" -#include "Drawables/2D/Text.hpp" #include "Model/Model.hpp" #include "Map/Map.hpp" @@ -45,12 +44,12 @@ namespace BBM return scene.addEntity("player") .addComponent() - .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/textures/blue.png")) + .addComponent("assets/player/player.iqm", true) .addComponent() .addComponent() - .addComponent("assets/shaders/glsl330/predator.fs") +// .addComponent("assets/shaders/glsl330/predator.fs") .addComponent>() - .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) + .addComponent(3) .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() .addComponent(soundPath) diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index a6e921b3..8c12ce79 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -2,7 +2,6 @@ // Created by Zoe Roux on 6/11/21. // -#include "Component/Animation/AnimationsComponent.hpp" #include "System/Event/EventSystem.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include "System/Lobby/LobbySystem.hpp" @@ -14,13 +13,31 @@ #include #include #include +#include + +namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { + std::vector LobbySystem::_colors = { + "blue", + "red", + "green", +// "purple", TODO MISSING ICONS +// "cyan", + "yellow" + }; + LobbySystem::LobbySystem(WAL::Wal &wal) : System(wal) {} + void LobbySystem::_nextColor(WAL::ViewEntity &entity) + { + auto &lobby = entity.get(); + entity.get().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); + } + void LobbySystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { auto &lobby = entity.get(); @@ -30,18 +47,24 @@ namespace BBM return; if (lobby.layout == ControllableComponent::NONE) { - for (auto &[_, controller] : this->_wal.getScene()->view()) { + for (auto &[_, ctrl] : this->_wal.getScene()->view()) { + auto &controller = ctrl; if (controller.jump) { if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity &view) { return view.get().layout == controller.layout; })) return; lobby.lastInput = lastTick; + lobby.color = 0; + entity.get().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); + + // this->_nextColor(entity); lobby.layout = controller.layout; controller.jump = false; - entity.get().drawable = std::make_shared("assets/player/icons/blue.png"); return; } +// if (controller.bomb) +// this->_nextColor(entity); } } @@ -121,6 +144,8 @@ namespace BBM _addController(player, lobby.layout); player.getComponent().position = Vector3f(mapWidth * playerCount % 2, 0, static_cast(mapHeight * playerCount / 2)); + auto *model = dynamic_cast(player.getComponent().drawable.get()); + model->setTextureToMaterial(MAP_DIFFUSE, "assets/player/textures/" + _colors[lobby.color] + ".png"); playerCount++; } Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene; diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index 9b419bd8..b1b3a495 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -8,6 +8,8 @@ #include "Component/Lobby/LobbyComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" #include "Entity/Entity.hpp" +#include +#include namespace BBM { @@ -17,6 +19,10 @@ namespace BBM private: //! @brief Add a controller for the player. static void _addController(WAL::Entity &player, ControllableComponent::Layout layout); + + static void _nextColor(WAL::ViewEntity &entity); + + static std::vector _colors; public: //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;