From eefc560a8102414f3b3da0fea6108ff3509500a1 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 11:56:02 +0200 Subject: [PATCH] fix random chance of bonuses --- sources/Items/Bonus.cpp | 2 +- sources/Map/Map.cpp | 24 ++++++++++++++++++++---- sources/Map/Map.hpp | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 23c53ef6..32267389 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -58,7 +58,7 @@ namespace BBM { { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd <= 1) + if (rnd <= 0.8) return (static_cast((std::rand() % NOCLIP) + 1)); return (NOTHING); } diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index fb19fb24..e2e3b5de 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -44,6 +44,22 @@ namespace BBM return; health->takeDmg(health->getHealthPoint()); } + + void MapGenerator::wallYouShouldNotPass(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *mov = entity.tryGetComponent(); + + if (!mov) + 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; + } void MapGenerator::wallCollided(WAL::Entity &entity, const WAL::Entity &wall, @@ -161,7 +177,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, -1)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallYouShouldNotPass, 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)); @@ -169,7 +185,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, height + 1)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallYouShouldNotPass, 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)); @@ -177,7 +193,7 @@ namespace BBM .addComponent(Vector3f(width + 1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallYouShouldNotPass, 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)); @@ -185,7 +201,7 @@ namespace BBM .addComponent(Vector3f(-1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallYouShouldNotPass, 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 f7eef37c..87757813 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -175,6 +175,10 @@ namespace BBM static const std::string secondFloorHolePath; public: + + static void wallYouShouldNotPass(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); static void wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis);