sorting scores

This commit is contained in:
arthur.jamet
2021-06-15 12:31:44 +02:00
parent de767e684d
commit a0784875d3
7 changed files with 54 additions and 2 deletions
+2
View File
@@ -136,6 +136,8 @@ set(SOURCES
sources/Runner/CreditScene.cpp
sources/Component/Score/ScoreComponent.cpp
sources/Component/Score/ScoreComponent.hpp
sources/System/Score/ScoreSystem.cpp
sources/System/Score/ScoreSystem.hpp
sources/System/EndCondition/EndConditionSystem.hpp
sources/System/EndCondition/EndConditionSystem.cpp
sources/Runner/LobbyScene.cpp
+5
View File
@@ -42,6 +42,11 @@ namespace RAY {
return *this;
}
const std::string &Texture::getResourcePath() const
{
return this->_resourcePath;
}
Texture::operator ::Texture() const
{
return *this->_texture;
+3
View File
@@ -44,6 +44,9 @@ namespace RAY
//! @brief Load texture from file, lets one use one entity for multiple files
Texture &use(const std::string &filename);
//! @return path of loaded texture
const std::string &getResourcePath() const;
protected:
private:
//! @brief Texture, really, that's just it...
+5
View File
@@ -61,6 +61,11 @@ namespace RAY::Drawables::Drawables3D
return true;
}
Texture &Model::getTextureByMaterial(MaterialType materialType)
{
return this->_textureList[materialType];
}
Model::operator ::Model() const
{
return *this->_model;
+4
View File
@@ -90,6 +90,10 @@ namespace RAY::Drawables::Drawables3D {
//! @brief Draw model's wires on window
void drawWiresOn(RAY::Window &) override;
//! @param materialType type of material
//! @return texture
Texture &getTextureByMaterial(MaterialType materialType);
private:
//! @brief Raw data from raylib
std::shared_ptr<::Model> _model;
+2
View File
@@ -34,6 +34,7 @@
#include "System/BumperTimer/BumperTimerSystem.hpp"
#include "System/Music/MusicSystem.hpp"
#include "System/Lobby/LobbySystem.hpp"
#include "System/Score/ScoreSystem.hpp"
#include "System/EndCondition/EndConditionSystem.hpp"
#include "Component/Lobby/LobbyComponent.hpp"
@@ -88,6 +89,7 @@ namespace BBM
.addSystem<GravitySystem>()
.addSystem<BumperTimerSystem>()
.addSystem<EndConditionSystem>()
.addSystem<ScoreSystem>()
.addSystem<MusicSystem>();
}
+33 -2
View File
@@ -6,22 +6,44 @@
#include "Component/Music/MusicComponent.hpp"
#include "Component/Position/PositionComponent.hpp"
#include "Component/Renderer/Drawable2DComponent.hpp"
#include "Component/Renderer/Drawable3DComponent.hpp"
#include "Component/Sound/SoundComponent.hpp"
#include "Drawables/Texture.hpp"
#include "Drawables/2D/Text.hpp"
#include "Component/Score/ScoreComponent.hpp"
#include "Model/Model.hpp"
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
std::shared_ptr<WAL::Scene> Runner::loadScoreScene(WAL::Scene &gameScene)
{
auto scene = std::make_shared<WAL::Scene>();
std::vector<std::string> playersIconPath;
std::vector<std::reference_wrapper<WAL::Entity>>players;
static const std::map<SoundComponent::SoundIndex, std::string> sounds = {
{SoundComponent::JUMP, "assets/sounds/click.ogg"}
};
static const std::vector<RAY::Color> tilesColor = {
GOLD, GRAY, BROWN, PURPLE
};
static const std::vector<std::string> rankName = {
"1st", "2nd", "3rd", "4th"
};
for (auto &[entity, score, drawable]: gameScene.view<ScoreComponent, Drawable3DComponent>())
players.push_back(entity);
std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) {
return entityA.getComponent<ScoreComponent>().aliveTime > entityB.getComponent<ScoreComponent>().aliveTime;
});
for (auto &entity: players) {
RAY3D::Model *model = dynamic_cast<RAY3D::Model *>(entity.get().getComponent<Drawable3DComponent>().drawable.get());
std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath();
playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons"));
}
addMenuControl(*scene);
scene->addEntity("Audio ressources")
@@ -30,13 +52,22 @@ namespace BBM
scene->addEntity("background")
.addComponent<PositionComponent>()
.addComponent<Drawable2DComponent, RAY::Texture>("assets/plain_menu_background.png");
for (int i = 0; i < 4; i++) {
scene->addEntity("scene title text")
.addComponent<PositionComponent>(1920 / 3.25, 100, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("GAME OVER", 120, RAY::Vector2(), ORANGE);
scene->addEntity("scene title text")
.addComponent<PositionComponent>(1920 / 2.37, 250, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>("CONGRATS", 50, RAY::Vector2(), ORANGE);
for (int i = 0; i < players.size(); i++) {
auto &playerTile = scene->addEntity("player tile")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 2.5, 0)
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200),tilesColor[i]);
auto &playerRank = scene->addEntity("player rank name")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 2.75, 0)
.addComponent<Drawable2DComponent, RAY2D::Text>(rankName[i], 30, RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), tilesColor[i]);
auto &player = scene->addEntity("player")
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 2.5, 0)
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png");
.addComponent<Drawable2DComponent, RAY::Texture>(playersIconPath[i]);
}
scene->addEntity("back to main menu")
.addComponent<PositionComponent>(10, 1080 - 85, 0)