mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-07 11:34:46 +00:00
fix emrge conflict
This commit is contained in:
@@ -0,0 +1,238 @@
|
||||
//
|
||||
// Created by Tom Augier on 5/26/21.
|
||||
// Edited by Benjamin Henry on 5/26/21.
|
||||
//
|
||||
|
||||
#include "Map.hpp"
|
||||
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
void MapGenerator::generateUnbreakableBlock(int width, int height, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj";
|
||||
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png";
|
||||
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
if (!(i % 2) && !(j % 2)) {
|
||||
scene->addEntity("Unbreakable Wall")
|
||||
.addComponent<PositionComponent>(Vector3f(i, 0, j))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapGenerator::generateWall(int width, int height, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
std::string unbreakableObj = "assets/wall/unbreakable_wall.obj";
|
||||
std::string unbreakablePnj = "assets/wall/unbreakable_wall.png";
|
||||
|
||||
scene->addEntity("Bottom Wall")
|
||||
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.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>(1)
|
||||
.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 + 1) / 2))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
|
||||
scene->addEntity("Right Wall")
|
||||
.addComponent<PositionComponent>(Vector3f(-1, 0, (height + 1) / 2))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
|
||||
}
|
||||
|
||||
void MapGenerator::generateFloor(int width, int height, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(width / 2, -1, height / 2))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"), RAY::Vector3(width + 2, 0, height + 2));
|
||||
}
|
||||
|
||||
void MapGenerator::createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType)
|
||||
{
|
||||
std::map<BlockType, MapElem> elements = {
|
||||
{BREAKABLE, &createBreakable},
|
||||
{UNBREAKABLE, &createUnbreakable},
|
||||
{HOLE, &createHole},
|
||||
{FLOOR, &createFloor},
|
||||
/* {BUMPER, &createBumper},
|
||||
{STAIRS, &createStairs} */
|
||||
};
|
||||
|
||||
try {
|
||||
auto element = elements.at(blockType);
|
||||
element(coords, scene);
|
||||
} catch (std::exception const &err) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MapGenerator::createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Breakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
.addComponent<HealthComponent>(1)
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png"));
|
||||
}
|
||||
|
||||
void MapGenerator::createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(coords))
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"));
|
||||
}
|
||||
|
||||
void MapGenerator::createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Unbreakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png"));
|
||||
}
|
||||
|
||||
void MapGenerator::createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Hole Block")
|
||||
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z))
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/hole.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/hole.png"));
|
||||
/* .addComponent<CollisionComponent>([](const WAL::Entity &entity, WAL::Entity &other) {
|
||||
if (other.hasComponent<HealthComponent>()) {
|
||||
auto &health = other.getComponent<HealthComponent>();
|
||||
health.takeDmg(health.getHealthPoint());
|
||||
}
|
||||
}); */
|
||||
}
|
||||
|
||||
void MapGenerator::createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Bumper Block")
|
||||
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y - 1, coords.z))
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/bumper_block.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/bumper_block.png"));
|
||||
/* .addComponent<CollisionComponent>([](const WAL::Entity &entity, WAL::Entity &other) {
|
||||
if (other.hasComponent<MovableComponent>()) {
|
||||
auto &movable = other.getComponent<MovableComponent>();
|
||||
movable.addForce(Vector3f(0, 5, 0));
|
||||
}
|
||||
} */
|
||||
}
|
||||
|
||||
void MapGenerator::createStairs(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Stairs Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/wall/stairs_block.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/stairs_block.png"));
|
||||
}
|
||||
|
||||
bool MapGenerator::isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType)
|
||||
{
|
||||
return (map[std::make_tuple(x - 1, y, z)] == blockType ||
|
||||
map[std::make_tuple(x + 1, y, z)] == blockType ||
|
||||
map[std::make_tuple(x, y, z + 1)] == blockType ||
|
||||
map[std::make_tuple(x, y, z - 1)] == blockType);
|
||||
}
|
||||
|
||||
MapGenerator::BlockType MapGenerator::getRandomBlockType()
|
||||
{
|
||||
double rnd = static_cast<double>(std::rand())/RAND_MAX;
|
||||
|
||||
if (rnd > 0.95)
|
||||
return HOLE;
|
||||
if (rnd > 0.10)
|
||||
return BREAKABLE;
|
||||
return NOTHING;
|
||||
}
|
||||
|
||||
MapGenerator::MapBlock MapGenerator::createHeight(MapBlock map, int width, int height)
|
||||
{
|
||||
double rnd = static_cast<double>(std::rand())/RAND_MAX;
|
||||
|
||||
if (rnd > 0.60) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
map[std::make_tuple(i, 1, height)] = map[std::make_tuple(i, 0, height)];
|
||||
map[std::make_tuple(i, 0, height)] = FLOOR;
|
||||
}
|
||||
for (int j = 0; j < height; j++) {
|
||||
map[std::make_tuple(width, 1, j)] = map[std::make_tuple(width, 0, j)];
|
||||
map[std::make_tuple(width, 0, j)] = FLOOR;
|
||||
}
|
||||
}
|
||||
if (rnd > 0.30) {
|
||||
for (int i = width - width/4; i < width + width/4 + 1; i++) {
|
||||
for (int j = height - height/4; j < height + height/4 + 1; j++) {
|
||||
map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)];
|
||||
map[std::make_tuple(i, 0, j)] = FLOOR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
MapGenerator::MapBlock MapGenerator::createSpawner(MapBlock map, int width, int height)
|
||||
{
|
||||
map[std::make_tuple(0, 0, 0)] = SPAWNER;
|
||||
map[std::make_tuple(width, 0, 0)] = SPAWNER;
|
||||
map[std::make_tuple(0, 0, height)] = SPAWNER;
|
||||
map[std::make_tuple(width, 0, height)] = SPAWNER;
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
MapGenerator::MapBlock MapGenerator::createMap(int width, int height)
|
||||
{
|
||||
MapBlock map;
|
||||
|
||||
width = width % 2 ? width + 1 : width;
|
||||
height = height % 2 ? height + 1 : height;
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++)
|
||||
map[std::make_tuple(i, 0, j)] = NOTHING;
|
||||
}
|
||||
map = createSpawner(map, width, height);
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
if (map[std::make_tuple(i, 0, j)] == SPAWNER)
|
||||
continue;
|
||||
if (isCloseToBlockType(map, i , 0, j, SPAWNER))
|
||||
map[std::make_tuple(i, 0, j)] = NOTHING;
|
||||
else
|
||||
map[std::make_tuple(i, 0, j)] = getRandomBlockType();
|
||||
if (map[std::make_tuple(i, 0, j)] == UNBREAKABLE && isCloseToBlockType(map, i, 0, j, UNBREAKABLE))
|
||||
map[std::make_tuple(i, 0, j)] = BREAKABLE;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
if (!((i + 1) % 2) && !((j + 1) % 2))
|
||||
map[std::make_tuple(i, 0, j)] = UNBREAKABLE;
|
||||
}
|
||||
}
|
||||
map = createHeight(map, width, height);
|
||||
return (map);
|
||||
}
|
||||
|
||||
void MapGenerator::loadMap(int width, int height, std::map<std::tuple<int, int, int>,
|
||||
BlockType> map, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
generateWall(width, height, scene);
|
||||
generateFloor(width, height, scene);
|
||||
for (int x = 0; x < width + 1; x++) {
|
||||
for (int z = 0; z < height + 1; z++) {
|
||||
for (int y = 0; y < 1 + 1; y++)
|
||||
createElement(Vector3f(x, y, z), scene, map[std::make_tuple(x, y, z)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace BBM
|
||||
@@ -0,0 +1,137 @@
|
||||
//
|
||||
// Created by Tom Augier on 5/26/21.
|
||||
// Edited by Benjamin Henry on 5/26/21.
|
||||
//
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
#include <random>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "System/Renderer/Renderer3DSystem.hpp"
|
||||
#include "Scene/Scene.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Component/Component.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
|
||||
class MapGenerator
|
||||
{
|
||||
private:
|
||||
//! @brief Enum of the block available.
|
||||
enum BlockType {
|
||||
NOTHING,
|
||||
BREAKABLE,
|
||||
HOLE,
|
||||
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>;
|
||||
|
||||
//! @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 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 floor of the map
|
||||
static void generateFloor(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 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 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 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 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 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);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//! @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, std::shared_ptr<WAL::Scene> scene);
|
||||
|
||||
};
|
||||
} // namespace BBM
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Runner.hpp"
|
||||
#include "Models/GameState.hpp"
|
||||
#include "Map/Map.hpp"
|
||||
|
||||
namespace RAY2D = RAY::Drawables::Drawables2D;
|
||||
namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
@@ -66,7 +67,6 @@ namespace BBM
|
||||
std::shared_ptr<WAL::Scene> loadGameScene()
|
||||
{
|
||||
auto scene = std::make_shared<WAL::Scene>();
|
||||
RAY3D::Cube cube(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED);
|
||||
scene->addEntity("player")
|
||||
.addComponent<PositionComponent>()
|
||||
.addComponent<Drawable3DComponent<RAY3D::Model>>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
@@ -76,7 +76,7 @@ namespace BBM
|
||||
.addComponent<MovableComponent>();
|
||||
scene->addEntity("cube")
|
||||
.addComponent<PositionComponent>(-5, 0, -5)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Cube>>(cube)
|
||||
.addComponent<Drawable3DComponent<RAY3D::Cube>>(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED)
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<CollisionComponent>([](WAL::Entity &, const WAL::Entity &){},
|
||||
@@ -88,8 +88,10 @@ namespace BBM
|
||||
}, 3);
|
||||
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(0, 20, -1)
|
||||
.addComponent<CameraComponent>();
|
||||
.addComponent<PositionComponent>(8, 20, 7)
|
||||
.addComponent<CameraComponent>(Vector3f(8, 0, 8));
|
||||
std::srand(std::time(NULL));
|
||||
MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene);
|
||||
return scene;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ namespace BBM
|
||||
}),
|
||||
_window(window),
|
||||
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
|
||||
{}
|
||||
{
|
||||
this->_window.setFPS(60);
|
||||
}
|
||||
|
||||
void RenderScreenSystem::onSelfUpdate()
|
||||
{
|
||||
|
||||
+10
-5
@@ -22,8 +22,10 @@
|
||||
#include "Drawables/3D/Sphere.hpp"
|
||||
#include "Model/Model.hpp"
|
||||
#include "Model/ModelAnimations.hpp"
|
||||
#include "System/Renderer/Renderer3DSystem.hpp"
|
||||
#include "System/Renderer/Renderer2DSystem.hpp"
|
||||
#include <System/Renderer/RenderScreenSystem.hpp>
|
||||
#include <System/Renderer/Render2DScreenSystem.hpp>
|
||||
#include <System/Renderer/Renderer2DSystem.hpp>
|
||||
#include <System/Renderer/Renderer3DSystem.hpp>
|
||||
#include "Component/Renderer/Drawable3DComponent.hpp"
|
||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||
#include "System/Renderer/RenderScreenSystem.hpp"
|
||||
@@ -45,8 +47,11 @@ std::string get_full_path(const std::string &color)
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int demo(void)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void usage(const std::string &bin)
|
||||
{
|
||||
@@ -62,6 +67,6 @@ int main(int argc, char **argv)
|
||||
usage(argv[0]);
|
||||
return 1;
|
||||
}
|
||||
// return demo();
|
||||
//return demo();
|
||||
return BBM::run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user