zoe has to smile !

This commit is contained in:
Clément Le Bihan
2021-06-08 11:58:30 +02:00
parent 23e26b59ae
commit d08613a9d4
5 changed files with 172 additions and 149 deletions
@@ -16,8 +16,8 @@ namespace BBM
}
CollisionComponent::CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollided,
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),
@@ -28,8 +28,8 @@ namespace BBM
{}
CollisionComponent::CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollided,
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),
@@ -23,9 +23,9 @@ namespace BBM
};
//! @brief onCollide functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &, int> onCollide;
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollide;
//! @brief onCollided functions to be called
WAL::Callback<WAL::Entity &, const WAL::Entity &, int> onCollided;
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> onCollided;
//! @brief Bound size on all axis
Vector3f bound;
//! @brief Offset from the position component
@@ -39,15 +39,15 @@ namespace BBM
//! @brief Constructor with a WAL::Callback
CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollided,
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 with a WAL::Callback, same boundSize for all axis
CollisionComponent(WAL::Entity &entity,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, int> &onCollided,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollide,
const WAL::Callback<WAL::Entity &, const WAL::Entity &, CollidedAxis> &onCollided,
float positionOffset,
float boundSize);
+32 -14
View File
@@ -12,7 +12,9 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
namespace BBM
{
void MapGenerator::wallCollide(WAL::Entity &entity, const WAL::Entity &wall, int collidedAxis)
void MapGenerator::wallCollide(WAL::Entity &entity,
const WAL::Entity &wall,
CollisionComponent::CollidedAxis collidedAxis)
{
auto *mov = entity.tryGetComponent<MovableComponent>();
@@ -49,8 +51,11 @@ namespace BBM
if (!(i % 2) && !(j % 2)) {
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(i, 0, j)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePng));
.addComponent<CollisionComponent>(
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));
}
}
}
@@ -63,25 +68,33 @@ namespace BBM
scene->addEntity("Bottom Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Upper Wall")
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, height + 1))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(width + 3, 1, 1));
scene->addEntity("Left Wall")
.addComponent<PositionComponent>(Vector3f(width + 1, 0, height / 2))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(1, 1, height + 1));
scene->addEntity("Right Wall")
.addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<CollisionComponent>(
WAL::Callback<WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis>(),
&MapGenerator::wallCollide, 0.25, .75)
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
RAY::Vector3(1, 1, height + 1));
@@ -97,7 +110,7 @@ namespace BBM
if (map[std::make_tuple(i, 0, j)] != HOLE && map[std::make_tuple(i, -1, j)] != BUMPER)
scene->addEntity("Unbreakable Wall")
.addComponent<PositionComponent>(Vector3f(i, -1, j))
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj,
std::make_pair(MAP_DIFFUSE, floorPng));
}
}
@@ -131,7 +144,9 @@ namespace BBM
scene->addEntity("Breakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<HealthComponent>(1)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .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));
}
@@ -142,7 +157,7 @@ namespace BBM
scene->addEntity("Floor")
.addComponent<PositionComponent>(Vector3f(coords))
//.addComponent<CollisionComponent>(1)
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, std::make_pair(MAP_DIFFUSE, floorPng));
}
@@ -164,7 +179,9 @@ namespace BBM
scene->addEntity("Unbreakable Block")
.addComponent<PositionComponent>(coords)
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &, int>(), &MapGenerator::wallCollide, 0.25, .75)
.addComponent<CollisionComponent>(
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));
}
@@ -183,7 +200,8 @@ namespace BBM
if (coords.y == 0)
holeEntity.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
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) {
if (other.hasComponent<HealthComponent>()) {
auto &health = other.getComponent<HealthComponent>();
@@ -215,7 +233,7 @@ namespace BBM
scene->addEntity("Stairs Block")
.addComponent<PositionComponent>(coords)
//.addComponent<CollisionComponent>(1)
//.addComponent<CollisionComponent>(1)
.addComponent<Drawable3DComponent, RAY3D::Model>(stairsObj, std::make_pair(MAP_DIFFUSE, stairsPng));
}
@@ -328,7 +346,7 @@ namespace BBM
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);
generateFloor(map, width, height, scene);
+128 -123
View File
@@ -27,149 +27,154 @@ namespace BBM
class MapGenerator
{
private:
//! @brief Enum of the block available.
enum BlockType {
NOTHING,
BREAKABLE,
HOLE,
UPPERFLOOR,
FLOOR,
BUMPER,
STAIRS,
SPAWNER,
UNBREAKABLE
};
private:
//! @brief Enum of the block available.
enum BlockType
{
NOTHING,
BREAKABLE,
HOLE,
UPPERFLOOR,
FLOOR,
BUMPER,
STAIRS,
SPAWNER,
UNBREAKABLE
};
using MapElem = std::function<void (Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
using MapElem = std::function<void(Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
//! @brief Generate random block type
static BlockType getRandomBlockType();
//! @brief Generate random block type
static BlockType getRandomBlockType();
//! @param map ASCII map
//! @param x x index on the block
//! @param z z index on the block
//! @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);
//! @param map ASCII map
//! @param x x index on the block
//! @param z z index on the block
//! @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);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the unbreakable block of the map
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the unbreakable block of the map
static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the wall of the map
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the wall of the map
static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the floor of the map
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param width Width of the map
//! @param height Height of the map
//! @param scene Scene where the map is instanced
//! @brief Generate the floor of the map
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create element of the map
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create element of the map
static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create breakable of the map
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create breakable of the map
static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create unbreakable of the map
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create unbreakable of the map
static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create hole of the map
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create hole of the map
static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create bumper of the map
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create bumper of the map
static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create floor of the map
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create floor of the map
static void createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create upper floor of the map
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create upper floor of the map
static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
//! @param coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create stair of the map
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 coords coords of the element
//! @param scene Scene where the map is instanced
//! @brief Create stair of the map
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 height for the map
static MapBlock createHeight(MapBlock map, int width, int height);
//! @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 width Width of the map
//! @param height Height of the map
//! @brief Clean breakable on stairs, bumpers, etc..
static MapBlock cleanBreakable(MapBlock map, int width, int height);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Generate height for the map
static MapBlock createHeight(MapBlock map, int width, int height);
static const std::string assetsPath;
static const std::string wallAssetsPath;
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, int collidedAxis);
//! @param map Map to load with block declared inside
//! @param width Width of the map
//! @param height Height of the map
//! @brief Clean breakable on stairs, bumpers, etc..
static MapBlock cleanBreakable(MapBlock map, int width, int height);
//! @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);
static const std::string assetsPath;
static const std::string wallAssetsPath;
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);
//! @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
+2 -2
View File
@@ -69,8 +69,8 @@ namespace BBM
collidedAxis += CollisionComponent::CollidedAxis::Z;
}
if (collidedAxis) {
colA.onCollide(entity, other, collidedAxis);
colB.onCollided(entity, other, collidedAxis);
colA.onCollide(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
colB.onCollided(entity, other, static_cast<CollisionComponent::CollidedAxis>(collidedAxis));
}
}
}