From d795f367470b54081bf25a1a740a96f51c5a5f10 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 15:56:27 +0200 Subject: [PATCH] distri for bonus --- sources/Items/Bonus.cpp | 21 +++++++++++++++++---- sources/Map/Map.cpp | 20 ++++++-------------- sources/Map/Map.hpp | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index a543395b..17266a5f 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -7,6 +7,8 @@ #include #include "Component/Movable/MovableComponent.hpp" #include "Bonus.hpp" +#include +#include #include "Component/BombHolder/BombHolderComponent.hpp" namespace BBM { @@ -55,10 +57,21 @@ namespace BBM { Bonus::BonusType Bonus::getRandomBonusType() { - double rnd = static_cast(std::rand()) / RAND_MAX; + static std::default_random_engine generator(time(nullptr)); + std::map chanceValue = { + {NOTHING, 100.0f}, + {SPEEDUP, 45.0f}, + {BOMBSTOCK, 30.0f}, + {EXPLOSIONINC, 15.0f}, + {NOCLIP, 1.5f}, + }; + std::uniform_int_distribution distribution(1,1000); + float value = (distribution(generator) / 10); + BonusType bonus = NOTHING; - if (rnd <= 0.8) - return (static_cast((std::rand() % NOCLIP) + 1)); - return (NOTHING); + for (auto &chance : chanceValue) + if (chance.second > value) + bonus = chance.first; + return (bonus); } } \ No newline at end of file diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 2128c39c..acdaa08f 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -45,7 +45,7 @@ namespace BBM health->takeDmg(health->getHealthPoint()); } - void MapGenerator::wallYouShouldNotPass(WAL::Entity &entity, + void MapGenerator::wallCollision(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) { @@ -65,19 +65,11 @@ namespace BBM const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) { - auto *mov = entity.tryGetComponent(); auto *playerBonus = entity.tryGetComponent(); - if (!mov) - return; if (playerBonus && playerBonus->isNoClipOn) return; - if (collidedAxis & CollisionComponent::CollidedAxis::X) - mov->_velocity.x = 0; - if (collidedAxis & CollisionComponent::CollidedAxis::Y) - mov->_velocity.y = 0; - if (collidedAxis & CollisionComponent::CollidedAxis::Z) - mov->_velocity.z = 0; + wallCollision(entity, wall, collidedAxis); } void MapGenerator::wallDestroyed(WAL::Entity &entity, WAL::Wal &wal) @@ -177,7 +169,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, -1)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallCollision, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -185,7 +177,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, height + 1)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallCollision, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -193,7 +185,7 @@ namespace BBM .addComponent(Vector3f(width + 1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallCollision, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); @@ -201,7 +193,7 @@ namespace BBM .addComponent(Vector3f(-1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallCollision, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 87757813..e04a00fc 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -176,9 +176,9 @@ namespace BBM public: - static void wallYouShouldNotPass(WAL::Entity &entity, - const WAL::Entity &wall, - CollisionComponent::CollidedAxis collidedAxis); + static void wallCollision(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); static void wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis);