Allowing players to join the lobby

This commit is contained in:
Zoe Roux
2021-06-11 12:15:51 +02:00
21 changed files with 180 additions and 64 deletions

Before

Width:  |  Height:  |  Size: 19 KiB

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

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Before

Width:  |  Height:  |  Size: 324 B

After

Width:  |  Height:  |  Size: 324 B

Before

Width:  |  Height:  |  Size: 396 B

After

Width:  |  Height:  |  Size: 396 B

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

Before

Width:  |  Height:  |  Size: 345 B

After

Width:  |  Height:  |  Size: 345 B

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

Before

Width:  |  Height:  |  Size: 333 B

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

+8 -2
View File
@@ -61,14 +61,20 @@ namespace WAL
std::optional<ViewEntity<Components...>> _entity;
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)
this->_entity.emplace(*this->_it);
return *this->_entity;
}
ViewEntity<Components...> *operator->()
pointer operator->()
{
if (!this->_entity)
this->_entity =(*this->_it);
@@ -3,6 +3,7 @@
// Edited by Benjamin Henry on 2021-05-20.
//
#include <Component/Controllable/ControllableComponent.hpp>
#include "GamepadComponent.hpp"
namespace BBM
@@ -31,4 +32,27 @@ namespace BBM
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
@@ -44,6 +44,8 @@ namespace BBM
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
void onStart() override;
//! @brief Create a new gampad component using default keys.
explicit GamepadComponent(WAL::Entity &entity);
@@ -3,25 +3,44 @@
// Edited by Benjamin Henry on 2021-05-20.
//
#include <Component/Controllable/ControllableComponent.hpp>
#include "KeyboardComponent.hpp"
namespace BBM
{
KeyboardComponent::KeyboardComponent(WAL::Entity &entity,
Key up,
Key down,
Key left,
Key right,
Key jump,
Key bomb,
Key pause)
: WAL::Component(entity), keyJump(jump), keyBomb(bomb), keyPause(pause),
keyRight(right), keyLeft(left), keyUp(up), keyDown(down)
{}
KeyboardComponent::KeyboardComponent(WAL::Entity &entity, ControllableComponent::Layout layout)
: WAL::Component(entity), layout(layout)
{
if (layout == ControllableComponent::KEYBOARD_0) {
this->keyUp = KEY_W;
this->keyDown = KEY_S;
this->keyLeft = KEY_A;
this->keyRight = KEY_D;
this->keyJump = KEY_SPACE;
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
{
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
@@ -7,6 +7,7 @@
#include <Controllers/Keyboard.hpp>
#include "Component/Component.hpp"
#include "Component/Controllable/ControllableComponent.hpp"
#include "Entity/Entity.hpp"
using Key = RAY::Controller::Keyboard::Key;
@@ -30,19 +31,16 @@ namespace BBM
Key keyUp = KEY_W;
//! @brief move down key
Key keyDown = KEY_S;
//! @brief Layout
ControllableComponent::Layout layout;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
void onStart() override;
//! @brief Create a new keyboard component using custom keys.
explicit KeyboardComponent(WAL::Entity &entity,
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);
explicit KeyboardComponent(WAL::Entity &entity, ControllableComponent::Layout layout = ControllableComponent::Layout::KEYBOARD_0);
//! @brief A Keyboard component is copy constructable.
KeyboardComponent(const KeyboardComponent &) = default;
+85 -39
View File
@@ -255,6 +255,27 @@ namespace BBM
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 &)
{
RAY::Texture *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 &)
{
RAY::Texture *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 &)
{
gameState._loadedScenes[GameState::SceneID::GameScene] = loadGameScene();
gameState.nextScene = BBM::GameState::SceneID::GameScene;
});
auto &back = scene->addEntity("back to menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0)
@@ -275,72 +296,97 @@ namespace BBM
texture->use("assets/buttons/button_back_hovered.png");
});
auto &play = scene->addEntity("play button")
.addComponent<PositionComponent>(1920 / 2.5, 1080 - 180, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_new_game.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 &)
{
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
texture->use("assets/buttons/button_new_game.png");
entity.getComponent<Drawable2DComponent>().drawable->setColor(BLACK);
})
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
{
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
texture->use("assets/buttons/button_new_game_hovered.png");
})
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
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)
{
gameState.nextScene = BBM::GameState::SceneID::GameScene;
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);
});
auto &p1tile = scene->addEntity("player1 tile")
.addComponent<PositionComponent>(224, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
// auto &p1tile = scene->addEntity("player1 tile")
// .addComponent<PositionComponent>(224, 1080 / 3, 0)
// .addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
auto &p1 = scene->addEntity("player1")
.addComponent<PositionComponent>(224, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/none_icon.png")
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png")
.addComponent<LobbyComponent>(0);
auto &p2tile = scene->addEntity("player2 tile")
.addComponent<PositionComponent>(2 * 224 + 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
// auto &p2tile = scene->addEntity("player2 tile")
// .addComponent<PositionComponent>(2 * 224 + 200, 1080 / 3, 0)
// .addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
auto &p2 = scene->addEntity("player2")
.addComponent<PositionComponent>(2 * 224 + 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/none_icon.png")
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png")
.addComponent<LobbyComponent>(1);
auto &p3tile = scene->addEntity("player3 tile")
.addComponent<PositionComponent>(3 * 224 + 2 * 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
// auto &p3tile = scene->addEntity("player3 tile")
// .addComponent<PositionComponent>(3 * 224 + 2 * 200, 1080 / 3, 0)
// .addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
auto &p3 = scene->addEntity("player3")
.addComponent<PositionComponent>(3 * 224 + 2 * 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/none_icon.png")
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png")
.addComponent<LobbyComponent>(2);
auto &p4tile = scene->addEntity("player4 tile")
.addComponent<PositionComponent>(4 * 224 + 3 * 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
// auto &p4tile = scene->addEntity("player4 tile")
// .addComponent<PositionComponent>(4 * 224 + 3 * 200, 1080 / 3, 0)
// .addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(), RAY::Vector2(200, 200), WHITE);
auto &p4 = scene->addEntity("player4")
.addComponent<PositionComponent>(4 * 224 + 3 * 200, 1080 / 3, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/none_icon.png")
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png")
.addComponent<LobbyComponent>(3);
scene->addEntity("camera")
.addComponent<PositionComponent>(8, 20, 7)
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
//when a player is ready:
p1tile.getComponent<Drawable2DComponent>().drawable.get()->setColor(BLUE);
//p2tile.getComponent<Drawable2DComponent>().drawable.get()->setColor(RED);
//p3tile.getComponent<Drawable2DComponent>().drawable.get()->setColor(GREEN);
//p4tile.getComponent<Drawable2DComponent>().drawable.get()->setColor(YELLOW);
//pX
p1.getComponent<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/valid_selection_icon.png");
//p1.getComponent<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icvalid_selection_icon.png");
//to do
// quand no player is reaydy, the play button should be diasbled
//The other non-ready players shoudl be IAs
play.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, &back, nullptr);
back.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, nullptr, &play);
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;
}
@@ -416,7 +462,7 @@ namespace BBM
})
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
{
//empty scene
gameState._loadedScenes[GameState::SceneID::GameScene].reset();
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
});
play.getComponent<OnClickComponent>().setButtonLinks(nullptr, nullptr, nullptr, &settings);
@@ -583,6 +629,7 @@ namespace BBM
{
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
});
auto &back = scene->addEntity("back to menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png")
@@ -628,7 +675,7 @@ namespace BBM
};
scene->addEntity("player")
.addComponent<PositionComponent>()
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/textures/blue.png"))
.addComponent<ControllableComponent>()
.addComponent<AnimatorComponent>()
.addComponent<KeyboardComponent>()
@@ -712,7 +759,7 @@ namespace BBM
.addComponent<KeyboardComponent>();
scene.addEntity("Keyboard second control")
.addComponent<ControllableComponent>()
.addComponent<KeyboardComponent>(KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, KEY_RIGHT_CONTROL, KEY_ENTER, KEY_BACKSPACE);
.addComponent<KeyboardComponent>(ControllableComponent::Layout::KEYBOARD_1);
for (int i = 0; i < 4; i++) {
scene.addEntity("Gamepad controller")
.addComponent<ControllableComponent>()
@@ -723,7 +770,6 @@ namespace BBM
void Runner::loadScenes()
{
gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene();
gameState._loadedScenes[GameState::SceneID::GameScene] = loadGameScene();
gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene();
gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene();
gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene();
+18 -1
View File
@@ -1,7 +1,13 @@
//
// 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"
#include "Component/Controllable/ControllableComponent.hpp"
#include <algorithm>
namespace BBM
{
@@ -9,13 +15,18 @@ namespace BBM
: System(wal)
{}
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent> &entity, std::chrono::nanoseconds dtime)
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
{
auto &lobby = entity.get<LobbyComponent>();
if (lobby.layout == ControllableComponent::NONE) {
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
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.layout = controller.layout;
entity.get<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icons/blue.png");
return;
}
}
@@ -28,4 +39,10 @@ namespace BBM
}
}
}
//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");
//}
}
+6 -2
View File
@@ -1,3 +1,7 @@
//
// Created by Zoe Roux on 6/11/21.
//
#pragma once
#include "System/System.hpp"
@@ -6,11 +10,11 @@
namespace BBM
{
//! @brief A system to handle Health entities.
class LobbySystem : public WAL::System<LobbyComponent>
class LobbySystem : public WAL::System<LobbyComponent, Drawable2DComponent>
{
public:
//! @inherit
void onUpdate(WAL::ViewEntity<LobbyComponent> &entity, std::chrono::nanoseconds dtime) override;
void onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
//! @brief A default constructor
explicit LobbySystem(WAL::Wal &wal);