mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 03:25:10 +00:00
merge from develop
This commit is contained in:
+9
-9
@@ -101,15 +101,15 @@ target_link_libraries(bomberman PUBLIC wal ray)
|
|||||||
|
|
||||||
|
|
||||||
add_executable(unit_tests EXCLUDE_FROM_ALL
|
add_executable(unit_tests EXCLUDE_FROM_ALL
|
||||||
${SOURCES}
|
${SOURCES}
|
||||||
tests/EntityTests.cpp
|
tests/EntityTests.cpp
|
||||||
tests/MainTest.cpp
|
tests/MainTest.cpp
|
||||||
tests/EngineTests.cpp
|
tests/EngineTests.cpp
|
||||||
tests/CallbackTest.cpp
|
tests/CallbackTest.cpp
|
||||||
tests/MoveTests.cpp
|
tests/MoveTests.cpp
|
||||||
tests/ViewTest.cpp
|
tests/ViewTest.cpp
|
||||||
tests/CollisionTest.cpp
|
tests/CollisionTest.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(unit_tests PUBLIC sources)
|
target_include_directories(unit_tests PUBLIC sources)
|
||||||
target_link_libraries(unit_tests PUBLIC wal ray)
|
target_link_libraries(unit_tests PUBLIC wal ray)
|
||||||
|
|
||||||
|
|||||||
@@ -4,31 +4,54 @@
|
|||||||
|
|
||||||
#include "Component/Collision/CollisionComponent.hpp"
|
#include "Component/Collision/CollisionComponent.hpp"
|
||||||
|
|
||||||
|
namespace BBM
|
||||||
namespace BBM
|
|
||||||
{
|
{
|
||||||
CollisionComponent::CollisionComponent(WAL::Entity &entity)
|
CollisionComponent::CollisionComponent(WAL::Entity &entity)
|
||||||
: WAL::Component(entity)
|
: WAL::Component(entity)
|
||||||
{ }
|
{}
|
||||||
|
|
||||||
WAL::Component *CollisionComponent::clone(WAL::Entity &entity) const
|
WAL::Component *CollisionComponent::clone(WAL::Entity &entity) const
|
||||||
{
|
{
|
||||||
return new CollisionComponent(entity);
|
return new CollisionComponent(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, Vector3f bound)
|
CollisionComponent::CollisionComponent(WAL::Entity &entity,
|
||||||
: WAL::Component(entity), onCollide(onCollide), onCollided(onCollided), bound(bound)
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
|
||||||
{ }
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
|
||||||
|
Vector3f positionOffset,
|
||||||
|
Vector3f bound)
|
||||||
|
: WAL::Component(entity),
|
||||||
|
onCollide(onCollide),
|
||||||
|
onCollided(onCollided),
|
||||||
|
bound(bound),
|
||||||
|
positionOffset(positionOffset)
|
||||||
|
{}
|
||||||
|
|
||||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, float boundSize)
|
CollisionComponent::CollisionComponent(WAL::Entity &entity,
|
||||||
: WAL::Component(entity), onCollide(onCollide), onCollided(onCollided), bound({boundSize, boundSize, boundSize})
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
|
||||||
{ }
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
|
||||||
|
float positionOffset,
|
||||||
|
float boundSize)
|
||||||
|
: WAL::Component(entity),
|
||||||
|
onCollide(onCollide),
|
||||||
|
onCollided(onCollided),
|
||||||
|
bound({boundSize, boundSize, boundSize}),
|
||||||
|
positionOffset({positionOffset, positionOffset, positionOffset})
|
||||||
|
{}
|
||||||
|
|
||||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, Vector3f bound)
|
CollisionComponent::CollisionComponent(WAL::Entity &entity, Vector3f positionOffset, Vector3f bound)
|
||||||
: WAL::Component(entity), onCollide(), onCollided(), bound(bound)
|
: WAL::Component(entity),
|
||||||
{ }
|
onCollide(),
|
||||||
|
onCollided(),
|
||||||
|
bound(bound),
|
||||||
|
positionOffset(positionOffset)
|
||||||
|
{}
|
||||||
|
|
||||||
CollisionComponent::CollisionComponent(WAL::Entity &entity, float boundSize)
|
CollisionComponent::CollisionComponent(WAL::Entity &entity, float positionOffset, float boundSize)
|
||||||
: WAL::Component(entity), onCollide(), onCollided(), bound({boundSize, boundSize, boundSize})
|
: WAL::Component(entity),
|
||||||
{ }
|
onCollide(),
|
||||||
|
onCollided(),
|
||||||
|
bound({boundSize, boundSize, boundSize}),
|
||||||
|
positionOffset({positionOffset, positionOffset, positionOffset})
|
||||||
|
{}
|
||||||
}
|
}
|
||||||
@@ -9,43 +9,61 @@
|
|||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
#include "Entity/Entity.hpp"
|
#include "Entity/Entity.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
class CollisionComponent : public WAL::Component
|
class CollisionComponent : public WAL::Component
|
||||||
{
|
{
|
||||||
private:
|
public:
|
||||||
public:
|
//! @brief Used to tell the collided axis
|
||||||
//! @brief onCollide functions to be called
|
//! @note Usage: (collidedAxis (int given by callback)) & CollidedAxis::X
|
||||||
WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide;
|
enum CollidedAxis {
|
||||||
//! @brief onCollided functions to be called
|
X = 1,
|
||||||
WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided;
|
Y = 2,
|
||||||
//! @brief Bound size on all axis
|
Z = 4
|
||||||
Vector3f bound;
|
};
|
||||||
//! @inherit
|
|
||||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
|
||||||
|
|
||||||
//! @brief A component can't be instantiated, it should be derived.
|
//! @brief onCollide functions to be called
|
||||||
explicit CollisionComponent(WAL::Entity &entity);
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollide;
|
||||||
|
//! @brief onCollided functions to be called
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollided;
|
||||||
|
//! @brief Bound size on all axis
|
||||||
|
Vector3f bound;
|
||||||
|
//! @brief Offset from the position component
|
||||||
|
Vector3f positionOffset;
|
||||||
|
|
||||||
//! @brief Constructor with a WAL::Callback
|
//! @inherit
|
||||||
CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided,Vector3f bound);
|
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||||
|
|
||||||
//! @brief Constructor with a WAL::Callback, same boundSize for all axis
|
//! @brief A component can't be instantiated, it should be derived.
|
||||||
CollisionComponent(WAL::Entity &entity, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollide, WAL::Callback<WAL::Entity &, const WAL::Entity &> onCollided, float boundSize = 0);
|
explicit CollisionComponent(WAL::Entity &entity);
|
||||||
|
|
||||||
//! @brief Constructor of collider with no callback
|
//! @brief Constructor with a WAL::Callback
|
||||||
CollisionComponent(WAL::Entity &entity, Vector3f bound);
|
CollisionComponent(WAL::Entity &entity,
|
||||||
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
|
||||||
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
|
||||||
|
Vector3f positionOffset,
|
||||||
|
Vector3f bound);
|
||||||
|
|
||||||
//! @brief Constructor no callback, same boundSize for all axis
|
//! @brief Constructor with a WAL::Callback, same boundSize for all axis
|
||||||
CollisionComponent(WAL::Entity &entity, float boundSize);
|
CollisionComponent(WAL::Entity &entity,
|
||||||
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
|
||||||
|
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
|
||||||
|
float positionOffset,
|
||||||
|
float boundSize);
|
||||||
|
|
||||||
//! @brief Default copy constructor
|
//! @brief Constructor of collider with no callback
|
||||||
CollisionComponent(const CollisionComponent &) = default;
|
CollisionComponent(WAL::Entity &entity, Vector3f positionOffset, Vector3f bound);
|
||||||
|
|
||||||
//! @brief default destructor
|
//! @brief Constructor no callback, same boundSize & positionOffset for all axis
|
||||||
~CollisionComponent() override = default;
|
CollisionComponent(WAL::Entity &entity, float positionOffset, float boundSize);
|
||||||
|
|
||||||
//! @brief A component can't be assigned
|
//! @brief Default copy constructor
|
||||||
CollisionComponent &operator=(const CollisionComponent &) = delete;
|
CollisionComponent(const CollisionComponent &) = default;
|
||||||
|
|
||||||
|
//! @brief default destructor
|
||||||
|
~CollisionComponent() override = default;
|
||||||
|
|
||||||
|
//! @brief A component can't be assigned
|
||||||
|
CollisionComponent &operator=(const CollisionComponent &) = delete;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
// Created by HENRY Benjamin on 02/06/2021.
|
// Created by HENRY Benjamin on 02/06/2021.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <Component/Collision/CollisionComponent.hpp>
|
||||||
#include "Component/Movable/MovableComponent.hpp"
|
#include "Component/Movable/MovableComponent.hpp"
|
||||||
#include "Bonus.hpp"
|
#include "Bonus.hpp"
|
||||||
#include "Component/BombHolder/BombHolderComponent.hpp"
|
#include "Component/BombHolder/BombHolderComponent.hpp"
|
||||||
|
|
||||||
namespace BBM {
|
namespace BBM {
|
||||||
void Bonus::BombUpBonus(WAL::Entity &player, const WAL::Entity &bonus)
|
void Bonus::BombUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
{
|
{
|
||||||
if (player.hasComponent<BombHolderComponent>()) {
|
if (player.hasComponent<BombHolderComponent>()) {
|
||||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||||
@@ -15,7 +16,7 @@ namespace BBM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bonus::DamageIncreasedBonus(WAL::Entity &player, const WAL::Entity &bonus)
|
void Bonus::DamageIncreasedBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
{
|
{
|
||||||
if (player.hasComponent<BombHolderComponent>()) {
|
if (player.hasComponent<BombHolderComponent>()) {
|
||||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||||
@@ -24,7 +25,7 @@ namespace BBM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus)
|
void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
{
|
{
|
||||||
if (player.hasComponent<BombHolderComponent>()) {
|
if (player.hasComponent<BombHolderComponent>()) {
|
||||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||||
@@ -33,7 +34,7 @@ namespace BBM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus)
|
void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
{
|
{
|
||||||
if (!player.hasComponent<MovableComponent>())
|
if (!player.hasComponent<MovableComponent>())
|
||||||
return;
|
return;
|
||||||
@@ -41,7 +42,7 @@ namespace BBM {
|
|||||||
movable.addForce(Vector3f(1, 0, 1));
|
movable.addForce(Vector3f(1, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus)
|
void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
{
|
{
|
||||||
if (player.hasComponent<BombHolderComponent>()) {
|
if (player.hasComponent<BombHolderComponent>()) {
|
||||||
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
auto &bombHolder = player.getComponent<BombHolderComponent>();
|
||||||
|
|||||||
@@ -13,26 +13,26 @@ namespace BBM {
|
|||||||
//! @param bonus bonus
|
//! @param bonus bonus
|
||||||
//! @param player the entity on which the effect will be applied
|
//! @param player the entity on which the effect will be applied
|
||||||
//! @brief Apply bonus effect that allows players to carry one more bomb than before
|
//! @brief Apply bonus effect that allows players to carry one more bomb than before
|
||||||
static void BombUpBonus(WAL::Entity &player, const WAL::Entity &bonus);
|
static void BombUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis);
|
||||||
|
|
||||||
//! @param bonus bonus
|
//! @param bonus bonus
|
||||||
//! @param player the entity on which the effect will be applied
|
//! @param player the entity on which the effect will be applied
|
||||||
//! @brief Apply bonus effect who increased the bomb damage
|
//! @brief Apply bonus effect who increased the bomb damage
|
||||||
static void DamageIncreasedBonus(WAL::Entity &player, const WAL::Entity &bonus);
|
static void DamageIncreasedBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis);
|
||||||
|
|
||||||
//! @param bonus bonus
|
//! @param bonus bonus
|
||||||
//! @param player the entity on which the effect will be applied
|
//! @param player the entity on which the effect will be applied
|
||||||
//! @brief Apply bonus effect that expend the explosion range of the bomb
|
//! @brief Apply bonus effect that expend the explosion range of the bomb
|
||||||
static void ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus);
|
static void ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis);
|
||||||
|
|
||||||
//! @param bonus bonus
|
//! @param bonus bonus
|
||||||
//! @param player the entity on which the effect will be applied
|
//! @param player the entity on which the effect will be applied
|
||||||
//! @brief Apply bonus effect that allows to run faster
|
//! @brief Apply bonus effect that allows to run faster
|
||||||
static void SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus);
|
static void SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis);
|
||||||
|
|
||||||
//! @param bonus bonus
|
//! @param bonus bonus
|
||||||
//! @param player the entity on which the effect will be applied
|
//! @param player the entity on which the effect will be applied
|
||||||
//! @brief Apply bonus effect that allows bomb explosion to pass through walls
|
//! @brief Apply bonus effect that allows bomb explosion to pass through walls
|
||||||
static void IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus);
|
static void IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+39
-25
@@ -3,7 +3,8 @@
|
|||||||
// Edited by Benjamin Henry on 5/26/21.
|
// Edited by Benjamin Henry on 5/26/21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <Component/Collision/CollisionComponent.hpp>
|
#include "Component/Collision/CollisionComponent.hpp"
|
||||||
|
#include "System/Collision/CollisionSystem.hpp"
|
||||||
#include "Map.hpp"
|
#include "Map.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Component/Bonus/BonusComponent.hpp>
|
#include <Component/Bonus/BonusComponent.hpp>
|
||||||
@@ -12,23 +13,20 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
|
|||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
void MapGenerator::wallCollide(WAL::Entity &entity, const WAL::Entity &wall)
|
void MapGenerator::wallCollide(WAL::Entity &entity,
|
||||||
|
const WAL::Entity &wall,
|
||||||
|
CollisionComponent::CollidedAxis collidedAxis)
|
||||||
{
|
{
|
||||||
auto *mov = entity.tryGetComponent<MovableComponent>();
|
auto *mov = entity.tryGetComponent<MovableComponent>();
|
||||||
|
|
||||||
if (!mov)
|
if (!mov)
|
||||||
return;
|
return;
|
||||||
auto &pos = entity.getComponent<PositionComponent>();
|
if (collidedAxis & CollisionComponent::CollidedAxis::X)
|
||||||
const auto &wallPos = wall.getComponent<PositionComponent>();
|
mov->_velocity.x = 0;
|
||||||
auto diff = pos.position + mov->getVelocity() - wallPos.position;
|
if (collidedAxis & CollisionComponent::CollidedAxis::Y)
|
||||||
// mov->_velocity = Vector3f();
|
mov->_velocity.x = 0;
|
||||||
// if (diff.x <= 0 && mov->_velocity.x < 0)
|
if (collidedAxis & CollisionComponent::CollidedAxis::Z)
|
||||||
// mov->_velocity.x = 0;
|
mov->_velocity.z = 0;
|
||||||
// if (diff.x >= 0 && mov->_velocity.x > 0)
|
|
||||||
// mov->_velocity.x = 0;
|
|
||||||
// if (diff.z <= 0 && mov->_velocity.z < 0)
|
|
||||||
// mov->_velocity.z = 0;
|
|
||||||
// if (diff.z >= 0 && mov->_velocity.z > 0)
|
|
||||||
// mov->_velocity.z = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGenerator::wallDestroyed(WAL::Entity &entity)
|
void MapGenerator::wallDestroyed(WAL::Entity &entity)
|
||||||
@@ -59,8 +57,11 @@ namespace BBM
|
|||||||
if (!(i % 2) && !(j % 2)) {
|
if (!(i % 2) && !(j % 2)) {
|
||||||
scene->addEntity("Unbreakable Wall")
|
scene->addEntity("Unbreakable Wall")
|
||||||
.addComponent<PositionComponent>(i, 0, j)
|
.addComponent<PositionComponent>(i, 0, j)
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePng));
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
|
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||||
|
std::make_pair(MAP_DIFFUSE, unbreakablePng));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,25 +74,33 @@ namespace BBM
|
|||||||
|
|
||||||
scene->addEntity("Bottom Wall")
|
scene->addEntity("Bottom Wall")
|
||||||
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
|
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||||
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
||||||
RAY::Vector3(width + 3, 1, 1));
|
RAY::Vector3(width + 3, 1, 1));
|
||||||
scene->addEntity("Upper Wall")
|
scene->addEntity("Upper Wall")
|
||||||
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
|
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||||
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
||||||
RAY::Vector3(width + 3, 1, 1));
|
RAY::Vector3(width + 3, 1, 1));
|
||||||
scene->addEntity("Left Wall")
|
scene->addEntity("Left Wall")
|
||||||
.addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
|
.addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||||
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
||||||
RAY::Vector3(1, 1, height + 1));
|
RAY::Vector3(1, 1, height + 1));
|
||||||
scene->addEntity("Right Wall")
|
scene->addEntity("Right Wall")
|
||||||
.addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
|
.addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||||
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
||||||
RAY::Vector3(1, 1, height + 1));
|
RAY::Vector3(1, 1, height + 1));
|
||||||
@@ -107,7 +116,7 @@ namespace BBM
|
|||||||
if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER)
|
if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER)
|
||||||
scene->addEntity("Unbreakable Wall")
|
scene->addEntity("Unbreakable Wall")
|
||||||
.addComponent<PositionComponent>(Vector3f(i, -1, j))
|
.addComponent<PositionComponent>(Vector3f(i, -1, j))
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
|
||||||
std::make_pair(MAP_DIFFUSE, floorPng));
|
std::make_pair(MAP_DIFFUSE, floorPng));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +151,9 @@ namespace BBM
|
|||||||
.addComponent<PositionComponent>(coords)
|
.addComponent<PositionComponent>(coords)
|
||||||
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
|
.addComponent<HealthComponent>(1, &MapGenerator::wallDestroyed)
|
||||||
.addComponent<BonusComponent>()
|
.addComponent<BonusComponent>()
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng));
|
.addComponent<Drawable3DComponent, RAY3D::Model>(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +186,9 @@ namespace BBM
|
|||||||
|
|
||||||
scene->addEntity("Unbreakable Block")
|
scene->addEntity("Unbreakable Block")
|
||||||
.addComponent<PositionComponent>(coords)
|
.addComponent<PositionComponent>(coords)
|
||||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
.addComponent<CollisionComponent>(
|
||||||
|
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
|
||||||
|
&MapGenerator::wallCollide, 0.25, .75)
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(UnbreakableObj,
|
.addComponent<Drawable3DComponent, RAY3D::Model>(UnbreakableObj,
|
||||||
std::make_pair(MAP_DIFFUSE, UnbreakablePng));
|
std::make_pair(MAP_DIFFUSE, UnbreakablePng));
|
||||||
}
|
}
|
||||||
@@ -194,7 +207,8 @@ namespace BBM
|
|||||||
if (coords.y == 0)
|
if (coords.y == 0)
|
||||||
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
|
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
|
||||||
else
|
else
|
||||||
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(secondFloorObj, std::make_pair(MAP_DIFFUSE, secondFloorPng));
|
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(secondFloorObj,
|
||||||
|
std::make_pair(MAP_DIFFUSE, secondFloorPng));
|
||||||
/*.addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
|
/*.addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
|
||||||
if (other.hasComponent<HealthComponent>()) {
|
if (other.hasComponent<HealthComponent>()) {
|
||||||
auto &health = other.getComponent<HealthComponent>();
|
auto &health = other.getComponent<HealthComponent>();
|
||||||
@@ -339,7 +353,7 @@ namespace BBM
|
|||||||
return (map);
|
return (map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapGenerator::loadMap(int width, int height, MapBlock map, std::shared_ptr<WAL::Scene> scene)
|
void MapGenerator::loadMap(int width, int height, MapBlock map, const std::shared_ptr<WAL::Scene> &scene)
|
||||||
{
|
{
|
||||||
generateWall(width, height, scene);
|
generateWall(width, height, scene);
|
||||||
generateFloor(map, width, height, scene);
|
generateFloor(map, width, height, scene);
|
||||||
|
|||||||
+129
-124
@@ -27,150 +27,155 @@ namespace BBM
|
|||||||
|
|
||||||
class MapGenerator
|
class MapGenerator
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! @brief Enum of the block available.
|
//! @brief Enum of the block available.
|
||||||
enum BlockType {
|
enum BlockType
|
||||||
NOTHING,
|
{
|
||||||
BREAKABLE,
|
NOTHING,
|
||||||
HOLE,
|
BREAKABLE,
|
||||||
UPPERFLOOR,
|
HOLE,
|
||||||
FLOOR,
|
UPPERFLOOR,
|
||||||
BUMPER,
|
FLOOR,
|
||||||
STAIRS,
|
BUMPER,
|
||||||
SPAWNER,
|
STAIRS,
|
||||||
UNBREAKABLE
|
SPAWNER,
|
||||||
};
|
UNBREAKABLE
|
||||||
|
};
|
||||||
|
|
||||||
using MapElem = std::function<void (Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
|
using MapElem = std::function<void(Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
|
||||||
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
|
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
|
||||||
|
|
||||||
//! @brief Generate random block type
|
//! @brief Generate random block type
|
||||||
static BlockType getRandomBlockType();
|
static BlockType getRandomBlockType();
|
||||||
|
|
||||||
//! @param map ASCII map
|
//! @param map ASCII map
|
||||||
//! @param x x index on the block
|
//! @param x x index on the block
|
||||||
//! @param z z index on the block
|
//! @param z z index on the block
|
||||||
//! @param blockType blockType to compare with position
|
//! @param blockType blockType to compare with position
|
||||||
static bool isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType);
|
static bool isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map,
|
||||||
|
int x, int y, int z,
|
||||||
|
BlockType blockType);
|
||||||
|
|
||||||
//! @param width Width of the map
|
//! @param width Width of the map
|
||||||
//! @param height Height of the map
|
//! @param height Height of the map
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Generate the unbreakable block of the map
|
//! @brief Generate the unbreakable block of the map
|
||||||
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
|
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param width Width of the map
|
//! @param width Width of the map
|
||||||
//! @param height Height of the map
|
//! @param height Height of the map
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Generate the wall of the map
|
//! @brief Generate the wall of the map
|
||||||
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
|
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param width Width of the map
|
//! @param width Width of the map
|
||||||
//! @param height Height of the map
|
//! @param height Height of the map
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Generate the floor of the map
|
//! @brief Generate the floor of the map
|
||||||
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
|
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create element of the map
|
//! @brief Create element of the map
|
||||||
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
|
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create breakable of the map
|
//! @brief Create breakable of the map
|
||||||
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create unbreakable of the map
|
//! @brief Create unbreakable of the map
|
||||||
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create hole of the map
|
//! @brief Create hole of the map
|
||||||
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create bumper of the map
|
//! @brief Create bumper of the map
|
||||||
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create floor of the map
|
//! @brief Create floor of the map
|
||||||
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create upper floor of the map
|
//! @brief Create upper floor of the map
|
||||||
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
|
|
||||||
//! @param coords coords of the element
|
//! @param coords coords of the element
|
||||||
//! @param scene Scene where the map is instanced
|
//! @param scene Scene where the map is instanced
|
||||||
//! @brief Create stair of the map
|
//! @brief Create stair of the map
|
||||||
static void createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
static void createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
|
||||||
|
|
||||||
//! @param map Map to load with block declared inside
|
|
||||||
//! @param width Width of the map
|
|
||||||
//! @param height Height of the map
|
|
||||||
//! @brief Generate map of block to be loaded
|
|
||||||
static MapBlock createSpawner(MapBlock map, int width, int height);
|
|
||||||
|
|
||||||
//! @param map Map to load with block declared inside
|
//! @param map Map to load with block declared inside
|
||||||
//! @param width Width of the map
|
//! @param width Width of the map
|
||||||
//! @param height Height of the map
|
//! @param height Height of the map
|
||||||
//! @brief Generate height for the map
|
//! @brief Generate map of block to be loaded
|
||||||
static MapBlock createHeight(MapBlock map, int width, int height);
|
static MapBlock createSpawner(MapBlock map, int width, int height);
|
||||||
|
|
||||||
//! @param map Map to load with block declared inside
|
//! @param map Map to load with block declared inside
|
||||||
//! @param width Width of the map
|
//! @param width Width of the map
|
||||||
//! @param height Height of the map
|
//! @param height Height of the map
|
||||||
//! @brief Clean breakable on stairs, bumpers, etc..
|
//! @brief Generate height for the map
|
||||||
static MapBlock cleanBreakable(MapBlock map, int width, int height);
|
static MapBlock createHeight(MapBlock map, int width, int height);
|
||||||
|
|
||||||
|
//! @param map Map to load with block declared inside
|
||||||
static const std::string assetsPath;
|
//! @param width Width of the map
|
||||||
|
//! @param height Height of the map
|
||||||
static const std::string wallAssetsPath;
|
//! @brief Clean breakable on stairs, bumpers, etc..
|
||||||
|
static MapBlock cleanBreakable(MapBlock map, int width, int height);
|
||||||
static const std::string imageExtension;
|
|
||||||
|
|
||||||
static const std::string objExtension;
|
|
||||||
|
|
||||||
static const std::string unbreakableWallPath;
|
|
||||||
|
|
||||||
static const std::string breakableWallPath;
|
|
||||||
|
|
||||||
static const std::string floorPath;
|
|
||||||
|
|
||||||
static const std::string stairsPath;
|
|
||||||
|
|
||||||
static const std::string bumperPath;
|
|
||||||
|
|
||||||
static const std::string secondFloorPath;
|
|
||||||
|
|
||||||
static const std::string holePath;
|
|
||||||
|
|
||||||
static const std::string secondFloorHolePath;
|
|
||||||
|
|
||||||
public:
|
|
||||||
static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall);
|
|
||||||
static void wallDestroyed(WAL::Entity &entity);
|
|
||||||
|
|
||||||
|
|
||||||
//! @param width Width of the map
|
static const std::string assetsPath;
|
||||||
//! @param height Height of the map
|
|
||||||
//! @brief Generate map of block to be loaded
|
static const std::string wallAssetsPath;
|
||||||
static MapBlock createMap(int width, int height);
|
|
||||||
|
static const std::string imageExtension;
|
||||||
|
|
||||||
|
static const std::string objExtension;
|
||||||
|
|
||||||
|
static const std::string unbreakableWallPath;
|
||||||
|
|
||||||
|
static const std::string breakableWallPath;
|
||||||
|
|
||||||
|
static const std::string floorPath;
|
||||||
|
|
||||||
|
static const std::string stairsPath;
|
||||||
|
|
||||||
|
static const std::string bumperPath;
|
||||||
|
|
||||||
|
static const std::string secondFloorPath;
|
||||||
|
|
||||||
|
static const std::string holePath;
|
||||||
|
|
||||||
|
static const std::string secondFloorHolePath;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void wallCollide(WAL::Entity &entity,
|
||||||
|
const WAL::Entity &wall,
|
||||||
|
CollisionComponent::CollidedAxis collidedAxis);
|
||||||
|
static void wallDestroyed(WAL::Entity &entity);
|
||||||
|
|
||||||
|
|
||||||
|
//! @param width Width of the map
|
||||||
|
//! @param height Height of the map
|
||||||
|
//! @brief Generate map of block to be loaded
|
||||||
|
static MapBlock createMap(int width, int height);
|
||||||
|
|
||||||
|
//! @param width Width of the map
|
||||||
|
//! @param height Height of the map
|
||||||
|
//! @param map Map to load with block declared inside
|
||||||
|
//! @param scene Scene where the map is instanced
|
||||||
|
//! @brief Generate the map
|
||||||
|
static void loadMap(int width, int height, MapBlock map, const std::shared_ptr<WAL::Scene> &scene);
|
||||||
|
|
||||||
//! @param width Width of the map
|
|
||||||
//! @param height Height of the map
|
|
||||||
//! @param map Map to load with block declared inside
|
|
||||||
//! @param scene Scene where the map is instanced
|
|
||||||
//! @brief Generate the map
|
|
||||||
static void loadMap(int width, int height, MapBlock map, std::shared_ptr<WAL::Scene> scene);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
} // namespace BBM
|
} // namespace BBM
|
||||||
@@ -80,7 +80,7 @@ namespace BBM
|
|||||||
.addComponent<AnimatorComponent>()
|
.addComponent<AnimatorComponent>()
|
||||||
.addComponent<KeyboardComponent>()
|
.addComponent<KeyboardComponent>()
|
||||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||||
.addComponent<CollisionComponent>(1)
|
.addComponent<CollisionComponent>(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75})
|
||||||
.addComponent<MovableComponent>()
|
.addComponent<MovableComponent>()
|
||||||
.addComponent<BombHolderComponent>()
|
.addComponent<BombHolderComponent>()
|
||||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||||
@@ -90,12 +90,12 @@ namespace BBM
|
|||||||
scene->addEntity("camera")
|
scene->addEntity("camera")
|
||||||
.addComponent<PositionComponent>(8, 20, 7)
|
.addComponent<PositionComponent>(8, 20, 7)
|
||||||
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
||||||
// scene->addEntity("cube")
|
/*scene->addEntity("cube")
|
||||||
// .addComponent<PositionComponent>(5, 0, 5)
|
.addComponent<PositionComponent>(-5, 0, -5)
|
||||||
// .addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
|
.addComponent<Drawable3DComponent, RAY3D::Cube>(Vector3f(0, 0, 0), Vector3f(3, 3, 3), RED)
|
||||||
// .addComponent<ControllableComponent>()
|
.addComponent<ControllableComponent>()
|
||||||
// .addComponent<KeyboardComponent>()
|
.addComponent<KeyboardComponent>()
|
||||||
// .addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, 3);
|
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, -1, 3);*/
|
||||||
std::srand(std::time(nullptr));
|
std::srand(std::time(nullptr));
|
||||||
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
|
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
|
||||||
return scene;
|
return scene;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace BBM
|
|||||||
: System(wal)
|
: System(wal)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
bool CollisionSystem::collide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB)
|
bool CollisionSystem::boxesCollide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB)
|
||||||
{
|
{
|
||||||
bool overlapX = (minA.x <= maxB.x && maxA.x >= minB.x) || (minB.x <= maxA.x && maxB.x >= minA.x);
|
bool overlapX = (minA.x <= maxB.x && maxA.x >= minB.x) || (minB.x <= maxA.x && maxB.x >= minA.x);
|
||||||
bool overlapY = (minA.y <= maxB.y && maxA.y >= minB.y) || (minB.y <= maxA.y && maxB.y >= minA.y);
|
bool overlapY = (minA.y <= maxB.y && maxA.y >= minB.y) || (minB.y <= maxA.y && maxB.y >= minA.y);
|
||||||
@@ -26,20 +26,51 @@ namespace BBM
|
|||||||
void CollisionSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent> &entity)
|
void CollisionSystem::onFixedUpdate(WAL::ViewEntity<PositionComponent, CollisionComponent> &entity)
|
||||||
{
|
{
|
||||||
auto &posA = entity.get<PositionComponent>();
|
auto &posA = entity.get<PositionComponent>();
|
||||||
auto &col = entity.get<CollisionComponent>();
|
auto &colA = entity.get<CollisionComponent>();
|
||||||
Vector3f position = posA.position;
|
Vector3f pointA = posA.position + colA.positionOffset;
|
||||||
if (auto *movable = entity->tryGetComponent<MovableComponent>())
|
Vector3f pointAx = pointA;
|
||||||
position += movable->getVelocity();
|
Vector3f pointAy = pointA;
|
||||||
Vector3f minA = Vector3f::min(position, position + col.bound);
|
Vector3f pointAz = pointA;
|
||||||
Vector3f maxA = Vector3f::max(position, position + col.bound);
|
|
||||||
|
if (auto *movable = entity->tryGetComponent<MovableComponent>()) {
|
||||||
|
auto vel = movable->getVelocity();
|
||||||
|
pointAx.x += vel.x;
|
||||||
|
pointAy.y += vel.y;
|
||||||
|
pointAz.z += vel.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3f minAx = Vector3f::min(pointAx, pointAx + colA.bound);
|
||||||
|
Vector3f maxAx = Vector3f::max(pointAx, pointAx + colA.bound);
|
||||||
|
|
||||||
|
Vector3f minAy = Vector3f::min(pointAy, pointAy + colA.bound);
|
||||||
|
Vector3f maxAy = Vector3f::max(pointAy, pointAy + colA.bound);
|
||||||
|
|
||||||
|
Vector3f minAz = Vector3f::min(pointAz, pointAz + colA.bound);
|
||||||
|
Vector3f maxAz = Vector3f::max(pointAz, pointAz + colA.bound);
|
||||||
|
|
||||||
for (auto &[other, posB, colB] : this->getView()) {
|
for (auto &[other, posB, colB] : this->getView()) {
|
||||||
if (other.getUid() == entity->getUid())
|
if (other.getUid() == entity->getUid())
|
||||||
continue;
|
continue;
|
||||||
Vector3f minB = Vector3f::min(posB.position, posB.position + colB.bound);
|
|
||||||
Vector3f maxB = Vector3f::max(posB.position, posB.position + colB.bound);
|
auto pointB = posB.position + colB.positionOffset;
|
||||||
if (collide(minA, maxA, minB, maxB)) {
|
int collidedAxis = 0;
|
||||||
col.onCollide(entity, other);
|
|
||||||
colB.onCollided(entity, other);
|
// TODO if B is also a movable we don't check with it's changing position
|
||||||
|
Vector3f minB = Vector3f::min(pointB, pointB + colB.bound);
|
||||||
|
Vector3f maxB = Vector3f::max(pointB, pointB + colB.bound);
|
||||||
|
|
||||||
|
if (boxesCollide(minAx, maxAx, minB, maxB)) {
|
||||||
|
collidedAxis += CollisionComponent::CollidedAxis::X;
|
||||||
|
}
|
||||||
|
if (boxesCollide(minAy, maxAy, minB, maxB)) {
|
||||||
|
collidedAxis += CollisionComponent::CollidedAxis::Y;
|
||||||
|
}
|
||||||
|
if (boxesCollide(minAz, maxAz, minB, maxB)) {
|
||||||
|
collidedAxis += CollisionComponent::CollidedAxis::Z;
|
||||||
|
}
|
||||||
|
if (collidedAxis) {
|
||||||
|
colA.onCollide(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
|
||||||
|
colB.onCollided(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ namespace BBM
|
|||||||
CollisionSystem &operator=(const CollisionSystem &) = delete;
|
CollisionSystem &operator=(const CollisionSystem &) = delete;
|
||||||
|
|
||||||
//! @brief check AABB collision
|
//! @brief check AABB collision
|
||||||
static bool collide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB);
|
static bool boxesCollide(Vector3f minA, Vector3f maxA, Vector3f minB, Vector3f maxB);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ namespace BBM
|
|||||||
{BonusComponent::BonusType::DAMAGEINC, "assets/items/fireup"},
|
{BonusComponent::BonusType::DAMAGEINC, "assets/items/fireup"},
|
||||||
{BonusComponent::BonusType::IGNOREWALLS, "assets/items/wallpass"}
|
{BonusComponent::BonusType::IGNOREWALLS, "assets/items/wallpass"}
|
||||||
};
|
};
|
||||||
static std::vector<std::function<void (WAL::Entity &, const WAL::Entity &)>> func = {
|
static std::vector<std::function<void (WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis)>> func = {
|
||||||
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, //&Bonus::ExplosionRangeBonus,
|
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, //&Bonus::ExplosionRangeBonus,
|
||||||
&Bonus::DamageIncreasedBonus, &Bonus::IgnoreWallsBonus
|
&Bonus::DamageIncreasedBonus, &Bonus::IgnoreWallsBonus
|
||||||
};
|
};
|
||||||
@@ -42,18 +42,18 @@ namespace BBM
|
|||||||
return;
|
return;
|
||||||
try {
|
try {
|
||||||
this->_wal.scene->scheduleNewEntity("Bonus")
|
this->_wal.scene->scheduleNewEntity("Bonus")
|
||||||
.addComponent<PositionComponent>(position)
|
.addComponent<PositionComponent>(position)
|
||||||
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
.addComponent<HealthComponent>(1, [](WAL::Entity &entity) {
|
||||||
entity.scheduleDeletion();
|
entity.scheduleDeletion();
|
||||||
})
|
})
|
||||||
.addComponent<LevitateComponent>(position.y)
|
.addComponent<LevitateComponent>(position.y)
|
||||||
.addComponent<CollisionComponent>([](WAL::Entity &bonus, const WAL::Entity &player) {
|
.addComponent<CollisionComponent>([](WAL::Entity &bonus, const WAL::Entity &player, CollisionComponent::CollidedAxis axis) {
|
||||||
bonus.scheduleDeletion();
|
bonus.scheduleDeletion();
|
||||||
}, func[bonusType - 1])
|
}, func[bonusType - 1], 0.25, .75)
|
||||||
.addComponent<TimerComponent>(timer, [](WAL::Entity &bonus, WAL::Wal &wal){
|
.addComponent<TimerComponent>(timer, [](WAL::Entity &bonus, WAL::Wal &wal){
|
||||||
bonus.scheduleDeletion();
|
bonus.scheduleDeletion();
|
||||||
})
|
})
|
||||||
.addComponent<Drawable3DComponent, RAY3D::Model>(map.at(bonusType) + ".obj", std::make_pair(MAP_DIFFUSE, "assets/items/items.png"));
|
.addComponent<Drawable3DComponent, RAY3D::Model>(map.at(bonusType) + ".obj", std::make_pair(MAP_DIFFUSE, "assets/items/items.png"));
|
||||||
} catch (std::out_of_range const &err) {}
|
} catch (std::out_of_range const &err) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,13 +10,16 @@
|
|||||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||||
#include "Drawables/ADrawable3D.hpp"
|
#include "Drawables/ADrawable3D.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
#include "Component/Collision/CollisionComponent.hpp"
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode)
|
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode)
|
||||||
: System(wal),
|
: System(wal),
|
||||||
_window(window),
|
_window(window),
|
||||||
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
|
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
|
||||||
_debugMode(debugMode)
|
_debugMode(debugMode)
|
||||||
{
|
{
|
||||||
this->_window.setFPS(this->FPS);
|
this->_window.setFPS(this->FPS);
|
||||||
}
|
}
|
||||||
@@ -44,7 +47,8 @@ namespace BBM
|
|||||||
this->_window.endDrawing();
|
this->_window.endDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime)
|
void RenderSystem::onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity,
|
||||||
|
std::chrono::nanoseconds dtime)
|
||||||
{
|
{
|
||||||
const auto &pos = entity.get<PositionComponent>();
|
const auto &pos = entity.get<PositionComponent>();
|
||||||
const auto &cam = entity.get<CameraComponent>();
|
const auto &cam = entity.get<CameraComponent>();
|
||||||
|
|||||||
+20
-17
@@ -8,6 +8,7 @@
|
|||||||
#include "Wal.hpp"
|
#include "Wal.hpp"
|
||||||
|
|
||||||
#define private public
|
#define private public
|
||||||
|
|
||||||
#include "System/Collision/CollisionSystem.hpp"
|
#include "System/Collision/CollisionSystem.hpp"
|
||||||
#include "System/Movable/MovableSystem.hpp"
|
#include "System/Movable/MovableSystem.hpp"
|
||||||
#include "Component/Movable/MovableComponent.hpp"
|
#include "Component/Movable/MovableComponent.hpp"
|
||||||
@@ -24,14 +25,14 @@ TEST_CASE("Collision test", "[Component][System]")
|
|||||||
wal.scene = std::make_shared<Scene>();
|
wal.scene = std::make_shared<Scene>();
|
||||||
wal.scene->addEntity("player")
|
wal.scene->addEntity("player")
|
||||||
.addComponent<PositionComponent>()
|
.addComponent<PositionComponent>()
|
||||||
.addComponent<CollisionComponent>([](Entity &actual, const Entity &) {
|
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int _) {
|
||||||
try {
|
try {
|
||||||
auto &pos = actual.getComponent<PositionComponent>();
|
auto &pos = actual.getComponent<PositionComponent>();
|
||||||
pos.position.x = 1;
|
pos.position.x = 1;
|
||||||
pos.position.y = 1;
|
pos.position.y = 1;
|
||||||
pos.position.z = 1;
|
pos.position.z = 1;
|
||||||
} catch (std::exception &e) {};
|
} catch (std::exception &e) {};
|
||||||
}, [](Entity &, const Entity &){}, 5.0);
|
}, [](Entity &, const Entity &, int) {}, 0, 5.0);
|
||||||
Entity &entity = wal.scene->getEntities().front();
|
Entity &entity = wal.scene->getEntities().front();
|
||||||
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
||||||
|
|
||||||
@@ -44,10 +45,10 @@ TEST_CASE("Collision test", "[Component][System]")
|
|||||||
REQUIRE(entity.getComponent<PositionComponent>().position.x == 0.0);
|
REQUIRE(entity.getComponent<PositionComponent>().position.x == 0.0);
|
||||||
REQUIRE(entity.getComponent<PositionComponent>().position.y == 0.0);
|
REQUIRE(entity.getComponent<PositionComponent>().position.y == 0.0);
|
||||||
REQUIRE(entity.getComponent<PositionComponent>().position.z == 0.0);
|
REQUIRE(entity.getComponent<PositionComponent>().position.z == 0.0);
|
||||||
|
|
||||||
wal.scene->addEntity("block")
|
wal.scene->addEntity("block")
|
||||||
.addComponent<PositionComponent>(2,2,2)
|
.addComponent<PositionComponent>(2, 2, 2)
|
||||||
.addComponent<CollisionComponent>(1);
|
.addComponent<CollisionComponent>(0, 1);
|
||||||
Entity &player = wal.scene->getEntities().front();
|
Entity &player = wal.scene->getEntities().front();
|
||||||
collision.update(std::chrono::nanoseconds(1));
|
collision.update(std::chrono::nanoseconds(1));
|
||||||
REQUIRE(player.hasComponent(typeid(PositionComponent)));
|
REQUIRE(player.hasComponent(typeid(PositionComponent)));
|
||||||
@@ -68,17 +69,19 @@ TEST_CASE("Collsion test with movable", "[Component][System]")
|
|||||||
wal.scene = std::make_shared<Scene>();
|
wal.scene = std::make_shared<Scene>();
|
||||||
wal.scene->addEntity("player")
|
wal.scene->addEntity("player")
|
||||||
.addComponent<PositionComponent>()
|
.addComponent<PositionComponent>()
|
||||||
.addComponent<CollisionComponent>([](Entity &actual, const Entity &) {}, [](Entity &actual, const Entity &) {}, 5.0)
|
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int) {},
|
||||||
|
[](Entity &actual, const Entity &, int) {}, 0, 5.0)
|
||||||
.addComponent<MovableComponent>();
|
.addComponent<MovableComponent>();
|
||||||
|
|
||||||
wal.scene->addEntity("block")
|
wal.scene->addEntity("block")
|
||||||
.addComponent<PositionComponent>(0, 0, 0)
|
.addComponent<PositionComponent>(0, 0, 0)
|
||||||
.addComponent<CollisionComponent>([](Entity &actual, const Entity &){}, [](Entity &actual, const Entity &) {
|
.addComponent<CollisionComponent>([](Entity &actual, const Entity &, int) {},
|
||||||
try {
|
[](Entity &actual, const Entity &, int) {
|
||||||
auto &mov = actual.getComponent<MovableComponent>();
|
try {
|
||||||
mov._velocity = Vector3f();
|
auto &mov = actual.getComponent<MovableComponent>();
|
||||||
} catch (std::exception &e) {};
|
mov._velocity = Vector3f();
|
||||||
}, 1);
|
} catch (std::exception &e) {};
|
||||||
|
}, 0, 1);
|
||||||
Entity &entity = wal.scene->getEntities().front();
|
Entity &entity = wal.scene->getEntities().front();
|
||||||
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
REQUIRE(entity.getComponent<PositionComponent>().position == Vector3f());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user