mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-26 07:49:33 +00:00
Fixing #255
This commit is contained in:
@@ -186,7 +186,6 @@ namespace BBM
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png");
|
||||
auto &ready = scene->addEntity("ready")
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3 - 50, 0)
|
||||
// todo check why it does this | hacky way to fix ready texture
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>();
|
||||
player.addComponent<LobbyComponent>(i, ready, playerTile);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||
#include <Map/Map.hpp>
|
||||
#include <Component/BombHolder/BombHolderComponent.hpp>
|
||||
#include <Parser/ParserYaml.hpp>
|
||||
#include <Drawables/2D/Text.hpp>
|
||||
#include "Component/Color/ColorComponent.hpp"
|
||||
#include "Component/Stat/StatComponent.hpp"
|
||||
@@ -66,7 +65,7 @@ namespace BBM
|
||||
lobby.coloredTile.getComponent<Drawable2DComponent>().drawable->setColor(_rayColors[lobby.color]);
|
||||
}
|
||||
|
||||
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds)
|
||||
{
|
||||
auto &lobby = entity.get<LobbyComponent>();
|
||||
|
||||
@@ -77,7 +76,7 @@ namespace BBM
|
||||
if (lobby.layout == ControllableComponent::NONE) {
|
||||
for (auto &[_, ctrl] : this->_wal.getScene()->view<ControllableComponent>()) {
|
||||
auto &controller = ctrl;
|
||||
if (controller.bomb) {
|
||||
if (controller.bomb && this->_canJoin()) {
|
||||
if (std::any_of(this->getView().begin(), this->getView().end(), [&controller](WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &view) {
|
||||
return view.get<LobbyComponent>().layout == controller.layout;
|
||||
}))
|
||||
@@ -95,7 +94,7 @@ namespace BBM
|
||||
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
|
||||
if (controller.layout != lobby.layout)
|
||||
continue;
|
||||
if (controller.bomb && !lobby.ready) {
|
||||
if (controller.bomb && !lobby.ready && this->_canJoin()) {
|
||||
lobby.ready = true;
|
||||
lobby.lastInput = lastTick;
|
||||
controller.bomb = false;
|
||||
@@ -104,13 +103,22 @@ namespace BBM
|
||||
if (texture)
|
||||
texture->use("assets/player/icons/ready.png");
|
||||
}
|
||||
if (controller.secondary && !lobby.ready) {
|
||||
if (controller.secondary) {
|
||||
lobby.lastInput = lastTick;
|
||||
this->_nextColor(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool LobbySystem::_canJoin()
|
||||
{
|
||||
auto *button = this->_wal.getSystem<MenuControllableSystem>().currentButton;
|
||||
|
||||
if (!button)
|
||||
return true;
|
||||
return button->hasComponent<TagComponent<"PlayButton">>();
|
||||
}
|
||||
|
||||
void LobbySystem::addAI()
|
||||
{
|
||||
for (auto entity : this->getView()) {
|
||||
@@ -152,7 +160,7 @@ namespace BBM
|
||||
texture->unload();
|
||||
}
|
||||
|
||||
void LobbySystem::onSelfUpdate(std::chrono::nanoseconds dtime)
|
||||
void LobbySystem::onSelfUpdate(std::chrono::nanoseconds)
|
||||
{
|
||||
auto &view = this->_wal.getScene()->view<TagComponent<"PlayButton">, Drawable2DComponent>();
|
||||
if (view.size() == 0)
|
||||
@@ -209,7 +217,7 @@ namespace BBM
|
||||
player.getComponent<ControllableComponent>().layout = layout;
|
||||
}
|
||||
|
||||
void LobbySystem::createTile(std::shared_ptr<WAL::Scene> scene, WAL::Entity &player, int color, int playerCount)
|
||||
void LobbySystem::createTile(const std::shared_ptr<WAL::Scene>& scene, WAL::Entity &player, int color, int playerCount)
|
||||
{
|
||||
std::string texturePath = "assets/player/ui/" + colors[color] + ".png";
|
||||
int x = (playerCount % 2 == 0) ? 1920 - 10 - 320 : 10;
|
||||
@@ -223,25 +231,25 @@ namespace BBM
|
||||
scene->addEntity("player hide fireup")
|
||||
.addComponent<PositionComponent>(x + 220, y + 35, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 20, x, y, WHITE)
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawble) {
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawable) {
|
||||
const BombHolderComponent *bonus = player.tryGetComponent<BombHolderComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(drawable.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(static_cast<int>(bonus->explosionRadius)));
|
||||
});
|
||||
scene->addEntity("player hide bombup")
|
||||
scene->addEntity("player hide bomb-up")
|
||||
.addComponent<PositionComponent>(x + 220, y + 77, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 20, x, y, WHITE)
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawble) {
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawable) {
|
||||
const BombHolderComponent *bonus = player.tryGetComponent<BombHolderComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(drawable.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(bonus->bombCount) + " / " + std::to_string(bonus->maxBombCount));
|
||||
@@ -249,12 +257,12 @@ namespace BBM
|
||||
scene->addEntity("player hide speedup")
|
||||
.addComponent<PositionComponent>(x + 220, y + 122, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 20, x, y, WHITE)
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawble) {
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawable) {
|
||||
auto *speed = player.tryGetComponent<SpeedComponent>();
|
||||
|
||||
if (!speed)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(drawable.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(static_cast<int>(speed->speed * 100)));
|
||||
@@ -262,12 +270,12 @@ namespace BBM
|
||||
scene->addEntity("player hide wall")
|
||||
.addComponent<PositionComponent>(x + 220, y + 161, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 20, x, y, WHITE)
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawble) {
|
||||
.addComponent<StatComponent>([&player](Drawable2DComponent &drawable) {
|
||||
const PlayerBonusComponent *bonus = player.tryGetComponent<PlayerBonusComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(drawable.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(bonus->isNoClipOn ? "YES" : "NO");
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace BBM
|
||||
{
|
||||
private:
|
||||
|
||||
bool _canJoin();
|
||||
|
||||
void _nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity);
|
||||
|
||||
|
||||
@@ -31,7 +33,7 @@ namespace BBM
|
||||
static void addController(WAL::Entity &player, ControllableComponent::Layout layout);
|
||||
|
||||
//! @brief Create ingame tile
|
||||
static void createTile(std::shared_ptr<WAL::Scene> scene, WAL::Entity &player, int color, int playerCount);
|
||||
static void createTile(const std::shared_ptr<WAL::Scene>& drawable, WAL::Entity &player, int color, int playerCount);
|
||||
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
@@ -18,13 +18,14 @@ namespace BBM
|
||||
{
|
||||
MenuControllableSystem::MenuControllableSystem(WAL::Wal &wal)
|
||||
: System(wal),
|
||||
_currentButton(), _oldMousePosition(-1, -1)
|
||||
_oldMousePosition(-1, -1),
|
||||
currentButton()
|
||||
{
|
||||
}
|
||||
|
||||
void MenuControllableSystem::_updateCurrentButton(bool selected, Vector2f move)
|
||||
{
|
||||
auto &buttonComponent = this->_currentButton->getComponent<OnClickComponent>();
|
||||
auto &buttonComponent = this->currentButton->getComponent<OnClickComponent>();
|
||||
WAL::Entity *newButton = nullptr;
|
||||
|
||||
if (move.y > 0 && buttonComponent._up)
|
||||
@@ -44,12 +45,12 @@ namespace BBM
|
||||
}
|
||||
|
||||
if (newButton) {
|
||||
this->_currentButton->getComponent<OnIdleComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
this->_currentButton = newButton;
|
||||
this->_currentButton->getComponent<OnHoverComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
this->currentButton->getComponent<OnIdleComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
this->currentButton = newButton;
|
||||
this->currentButton->getComponent<OnHoverComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
}
|
||||
if (selected)
|
||||
this->_currentButton->getComponent<OnClickComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
this->currentButton->getComponent<OnClickComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
}
|
||||
|
||||
bool MenuControllableSystem::_mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const
|
||||
@@ -83,16 +84,16 @@ namespace BBM
|
||||
|
||||
if (this->_oldMousePosition == Vector2f(-1, -1))
|
||||
this->_oldMousePosition = relativeMousePos;
|
||||
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 && this->currentButton->_scene.getID() != this->_wal.getScene()->getID()) {
|
||||
this->currentButton->getComponent<OnIdleComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
this->currentButton = nullptr;
|
||||
return;
|
||||
}
|
||||
if (this->_currentButton == nullptr && buttons.size()) {
|
||||
this->_currentButton = &(*buttons.front());
|
||||
this->_currentButton->getComponent<OnHoverComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
if (this->currentButton == nullptr && buttons.size()) {
|
||||
this->currentButton = &(*buttons.front());
|
||||
this->currentButton->getComponent<OnHoverComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
}
|
||||
if (!this->_currentButton)
|
||||
if (!this->currentButton)
|
||||
return;
|
||||
for (auto &[_, controllable]: controllableView)
|
||||
if (controllable.move.x || controllable.move.y || controllable.bomb) {
|
||||
@@ -104,12 +105,12 @@ namespace BBM
|
||||
this->_oldMousePosition = relativeMousePos;
|
||||
for (auto &entity: buttons) {
|
||||
if (_mouseOnButton(relativeMousePos, entity)) {
|
||||
if (this->_currentButton)
|
||||
this->_currentButton->getComponent<OnIdleComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
this->_currentButton = &(*entity);
|
||||
this->_currentButton->getComponent<OnHoverComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
if (this->currentButton)
|
||||
this->currentButton->getComponent<OnIdleComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
this->currentButton = &(*entity);
|
||||
this->currentButton->getComponent<OnHoverComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
if (RAYControl::Mouse::isPressed(RAYControl::Mouse::Button::MOUSE_BUTTON_LEFT))
|
||||
this->_currentButton->getComponent<OnClickComponent>().onEvent(*this->_currentButton, this->_wal);
|
||||
this->currentButton->getComponent<OnClickComponent>().onEvent(*this->currentButton, this->_wal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,6 @@ namespace BBM
|
||||
class MenuControllableSystem : public WAL::System<>
|
||||
{
|
||||
private:
|
||||
//! @brief index of the current button selected
|
||||
WAL::Entity *_currentButton;
|
||||
|
||||
//! @brief position of the mouse at the precedent scene (to know which controller event to watch)
|
||||
Vector2f _oldMousePosition;
|
||||
|
||||
@@ -30,6 +27,9 @@ namespace BBM
|
||||
//! @return true if mouse on entity
|
||||
bool _mouseOnButton(const Vector2f &mousePos, WAL::ViewEntity<OnClickComponent, OnHoverComponent, OnIdleComponent, PositionComponent, Drawable2DComponent> &entity) const;
|
||||
public:
|
||||
//! @brief index of the current button selected
|
||||
WAL::Entity *currentButton;
|
||||
|
||||
//! @brief time (in millisecond) since last check
|
||||
std::chrono::time_point<std::chrono::steady_clock> now;
|
||||
//! @inherit
|
||||
|
||||
Reference in New Issue
Block a user