mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-25 15:39:50 +00:00
Handling ready buttons
This commit is contained in:
@@ -38,6 +38,7 @@ namespace RAY {
|
||||
return *this;
|
||||
this->_texture = this->_texturesCache.fetch(filename);
|
||||
this->_resourcePath = filename;
|
||||
this->_dimensions = Vector2(this->_texture->width, this->_texture->height);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <Entity/Entity.hpp>
|
||||
#include <Color.hpp>
|
||||
#include <Component/Controllable/ControllableComponent.hpp>
|
||||
#include <chrono>
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
@@ -24,8 +25,10 @@ namespace BBM
|
||||
bool ready = false;
|
||||
//! @brief The entity containing the ready display.
|
||||
WAL::Entity &readyButton;
|
||||
//! @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;
|
||||
Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new lobby component.
|
||||
explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton);
|
||||
|
||||
@@ -18,6 +18,11 @@ namespace BBM
|
||||
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 &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
|
||||
if (controller.jump) {
|
||||
@@ -25,27 +30,22 @@ namespace BBM
|
||||
return view.get<LobbyComponent>().layout == controller.layout;
|
||||
}))
|
||||
return;
|
||||
lobby.lastInput = lastTick;
|
||||
lobby.layout = controller.layout;
|
||||
entity.get<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icons/blue.png");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
|
||||
if (controller.layout == lobby.layout && controller.jump) {
|
||||
lobby.ready = true;
|
||||
if (lobby.ready) {
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
|
||||
if (texture)
|
||||
texture->use("assets/player/icons/ready.png");
|
||||
}
|
||||
lobby.lastInput = lastTick;
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(lobby.readyButton.getComponent<Drawable2DComponent>().drawable.get());
|
||||
if (texture)
|
||||
texture->use("assets/player/icons/ready.png");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//void LobbySystem::updateEntityConnectedUser(WAL::Entity &entity)
|
||||
//{
|
||||
// RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
// texture->use("assets/player/icons/blue.png");
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user