Bomberman
Map.hpp
Go to the documentation of this file.
1 //
2 // Created by Tom Augier on 5/26/21.
3 // Edited by Benjamin Henry on 5/26/21.
4 //
5 
6 
7 #pragma once
8 
9 #include <cmath>
10 #include <ctime>
11 #include <cstdlib>
12 #include <random>
13 #include <map>
14 #include <tuple>
15 #include <algorithm>
17 #include "Scene/Scene.hpp"
18 #include "Model/Model.hpp"
19 #include "Component/Component.hpp"
24 #include <chrono>
25 #include <Items/Bonus.hpp>
26 
27 
28 namespace BBM
29 {
30 
32  {
33  public:
35  enum BlockType
36  {
45  };
46 
47  using MapBlock = std::map<std::tuple<int, int, int>, BlockType>;
48 
49  static void createBonus(WAL::Entity &entity, Vector3f position, Bonus::BonusType bonusType);
50 
51  static void wallCollision(WAL::Entity &entity,
52  const WAL::Entity &wall,
54  static void wallCollided(WAL::Entity &entity,
55  const WAL::Entity &wall,
57  static void wallDestroyed(WAL::Entity &entity, WAL::Wal &wal);
58 
59  static void holeCollide(WAL::Entity &entity,
60  const WAL::Entity &wall,
62 
63  static void bumperCollide(WAL::Entity &entity,
64  const WAL::Entity &wall,
66 
67 
68 
72  static MapBlock createMap(int width, int height, bool isHeight = false, bool isNotClassic = false);
73 
79  static void loadMap(int width, int height, MapBlock map, const std::shared_ptr<WAL::Scene> &scene);
80 
84  static void createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType);
85  private:
86 
87  using MapElem = std::function<void(Vector3f coords, std::shared_ptr<WAL::Scene> scene)>;
88 
90  static BlockType getRandomBlockType(bool = false);
91 
96  static bool isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map,
97  int x, int y, int z,
98  BlockType blockType);
99 
104  static void generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene);
105 
110  static void generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene);
111 
116  static void generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene);
117 
121  static void createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
122 
126  static void createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
127 
131  static void createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
132 
136  static void createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
137 
141  static void createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene);
142 
147  static void generateHeightCollision(MapBlock map, int width, int height,
148  std::shared_ptr<WAL::Scene> scene);
149 
154  static MapBlock createClassicUnbreakable(MapBlock map, int width, int height);
155 
160  static MapBlock createLongClassicUnbreakable(MapBlock map, int width, int height);
161 
166  static MapBlock createSpawner(MapBlock map, int width, int height);
167 
172  static MapBlock createHeight(MapBlock map, int width, int height);
173 
178  static MapBlock cleanBreakable(MapBlock map, int width, int height);
179 
180 
181  static const std::string assetsPath;
182 
183  static const std::string wallAssetsPath;
184 
185  static const std::string imageExtension;
186 
187  static const std::string objExtension;
188 
189  static const std::string unbreakableWallPath;
190 
191  static const std::string outerWallPath;
192 
193  static const std::string breakableWallPath;
194 
195  static const std::string floorPath;
196 
197  static const std::string stairsPath;
198 
199  static const std::string bumperPath;
200 
201  static const std::string secondFloorPath;
202 
203  static const std::string holePath;
204 
205  static const std::string secondFloorHolePath;
206  };
207 } // namespace BBM
BBM::MapGenerator::BUMPER
@ BUMPER
Definition: Map.hpp:41
BBM::MapGenerator::SPAWNER
@ SPAWNER
Definition: Map.hpp:42
BBM::MapGenerator::secondFloorHolePath
static const std::string secondFloorHolePath
Definition: Map.hpp:205
BBM::MapGenerator::createMap
static MapBlock createMap(int width, int height, bool isHeight=false, bool isNotClassic=false)
Generate map of block to be loaded.
Definition: Map.cpp:435
Bonus.hpp
BBM::MapGenerator::wallCollision
static void wallCollision(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis)
Definition: Map.cpp:84
BBM::MapGenerator::INVISIBLE
@ INVISIBLE
Definition: Map.hpp:44
BBM::MapGenerator::BlockType
BlockType
Enum of the block available.
Definition: Map.hpp:35
BBM::MapGenerator::createBumper
static void createBumper(Vector3f coords, std::shared_ptr< WAL::Scene > scene)
Create bumper of the map.
Definition: Map.cpp:316
BBM::MapGenerator::createHole
static void createHole(Vector3f coords, std::shared_ptr< WAL::Scene > scene)
Create hole of the map.
Definition: Map.cpp:294
BBM::MapGenerator::wallCollided
static void wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis)
Definition: Map.cpp:100
BBM::MapGenerator::createBreakable
static void createBreakable(Vector3f coords, std::shared_ptr< WAL::Scene > scene)
Create breakable of the map.
Definition: Map.cpp:251
BBM::MapGenerator::UNBREAKABLE
@ UNBREAKABLE
Definition: Map.hpp:43
BBM::MapGenerator::imageExtension
static const std::string imageExtension
Definition: Map.hpp:185
CollisionComponent.hpp
BBM::Bonus::BonusType
BonusType
Definition: Bonus.hpp:34
BBM::MapGenerator::generateFloor
static void generateFloor(MapBlock map, int width, int height, std::shared_ptr< WAL::Scene > scene)
Generate the floor of the map.
Definition: Map.cpp:219
BBM::MapGenerator::MapBlock
std::map< std::tuple< int, int, int >, BlockType > MapBlock
Definition: Map.hpp:47
BBM::MapGenerator::objExtension
static const std::string objExtension
Definition: Map.hpp:187
BBM
Definition: AnimationsComponent.cpp:9
PositionComponent.hpp
BBM::MapGenerator::holePath
static const std::string holePath
Definition: Map.hpp:203
WAL::Wal
The main WAL class, it is used to setup and run the ECS.
Definition: Wal.hpp:27
BBM::MapGenerator::bumperPath
static const std::string bumperPath
Definition: Map.hpp:199
WAL::Entity
An entity of the WAL's ECS.
Definition: Entity.hpp:20
BBM::CollisionComponent::CollidedAxis
CollidedAxis
Used to tell the collided axis.
Definition: CollisionComponent.hpp:19
BBM::MapGenerator::createSpawner
static MapBlock createSpawner(MapBlock map, int width, int height)
Generate map of block to be loaded.
Definition: Map.cpp:383
BBM::MapGenerator::createUpperFloor
static void createUpperFloor(Vector3f coords, std::shared_ptr< WAL::Scene > scene)
Create upper floor of the map.
Definition: Map.cpp:267
MovableComponent.hpp
BBM::MapGenerator::getRandomBlockType
static BlockType getRandomBlockType(bool=false)
Generate random block type.
Definition: Map.cpp:339
BBM::MapGenerator::NOTHING
@ NOTHING
Definition: Map.hpp:37
BBM::Vector3< float >
Component.hpp
BBM::MapGenerator::createHeight
static MapBlock createHeight(MapBlock map, int width, int height)
Generate height for the map.
Definition: Map.cpp:350
BBM::MapGenerator::createClassicUnbreakable
static MapBlock createClassicUnbreakable(MapBlock map, int width, int height)
Generate unbreakable block on the map.
Definition: Map.cpp:405
BBM::MapGenerator::assetsPath
static const std::string assetsPath
Definition: Map.hpp:181
BBM::MapGenerator::HOLE
@ HOLE
Definition: Map.hpp:39
BBM::MapGenerator::wallAssetsPath
static const std::string wallAssetsPath
Definition: Map.hpp:183
BBM::MapGenerator::createUnbreakable
static void createUnbreakable(Vector3f coords, std::shared_ptr< WAL::Scene > scene)
Create unbreakable of the map.
Definition: Map.cpp:278
BBM::MapGenerator::wallDestroyed
static void wallDestroyed(WAL::Entity &entity, WAL::Wal &wal)
Definition: Map.cpp:111
BBM::MapGenerator
Definition: Map.hpp:31
BBM::MapGenerator::secondFloorPath
static const std::string secondFloorPath
Definition: Map.hpp:201
Model.hpp
BBM::MapGenerator::createBonus
static void createBonus(WAL::Entity &entity, Vector3f position, Bonus::BonusType bonusType)
Definition: Map.cpp:22
BBM::MapGenerator::createLongClassicUnbreakable
static MapBlock createLongClassicUnbreakable(MapBlock map, int width, int height)
Generate unbreakable block on map.
Definition: Map.cpp:416
BBM::MapGenerator::MapElem
std::function< void(Vector3f coords, std::shared_ptr< WAL::Scene > scene)> MapElem
Definition: Map.hpp:87
BBM::MapGenerator::floorPath
static const std::string floorPath
Definition: Map.hpp:195
BBM::MapGenerator::isCloseToBlockType
static bool isCloseToBlockType(std::map< std::tuple< int, int, int >, BlockType > map, int x, int y, int z, BlockType blockType)
Definition: Map.cpp:330
HealthComponent.hpp
BBM::MapGenerator::bumperCollide
static void bumperCollide(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis)
Definition: Map.cpp:50
BBM::MapGenerator::cleanBreakable
static MapBlock cleanBreakable(MapBlock map, int width, int height)
Clean breakable on stairs, bumpers, etc..
Definition: Map.cpp:393
BBM::MapGenerator::generateUnbreakableBlock
static void generateUnbreakableBlock(int width, int height, std::shared_ptr< WAL::Scene > scene)
Generate the unbreakable block of the map.
Definition: Map.cpp:144
BBM::MapGenerator::outerWallPath
static const std::string outerWallPath
Definition: Map.hpp:191
BBM::MapGenerator::generateWall
static void generateWall(int width, int height, std::shared_ptr< WAL::Scene > scene)
Generate the wall of the map.
Definition: Map.cpp:166
BBM::MapGenerator::holeCollide
static void holeCollide(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis)
Definition: Map.cpp:65
BBM::MapGenerator::BREAKABLE
@ BREAKABLE
Definition: Map.hpp:38
Scene.hpp
BBM::MapGenerator::loadMap
static void loadMap(int width, int height, MapBlock map, const std::shared_ptr< WAL::Scene > &scene)
Generate the map.
Definition: Map.cpp:514
BBM::MapGenerator::breakableWallPath
static const std::string breakableWallPath
Definition: Map.hpp:193
BBM::MapGenerator::stairsPath
static const std::string stairsPath
Definition: Map.hpp:197
BBM::MapGenerator::unbreakableWallPath
static const std::string unbreakableWallPath
Definition: Map.hpp:189
BBM::MapGenerator::createElement
static void createElement(Vector3f coords, std::shared_ptr< WAL::Scene > scene, BlockType blockType)
Create element of the map.
Definition: Map.cpp:235
Drawable3DComponent.hpp
BBM::MapGenerator::UPPERFLOOR
@ UPPERFLOOR
Definition: Map.hpp:40
BBM::MapGenerator::generateHeightCollision
static void generateHeightCollision(MapBlock map, int width, int height, std::shared_ptr< WAL::Scene > scene)
Generate the height hitbox of the map.
Definition: Map.cpp:472