Merging with develop
@@ -1,11 +1,9 @@
|
||||
name: Web Build (Emscripten)
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
wasm
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
Push:
|
||||
Build:
|
||||
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
@@ -10,6 +10,8 @@ include_directories(bomberman sources)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/wal)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/Ray)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
|
||||
@@ -40,7 +40,7 @@ mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
cd -
|
||||
cd ..
|
||||
```
|
||||
|
||||
Enjoy !
|
||||
|
||||
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,13 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl floor
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd hole.png
|
||||
@@ -0,0 +1,54 @@
|
||||
# Blender v2.92.0 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib upper_floor.mtl
|
||||
o floor
|
||||
v -0.500000 -0.499144 0.500854
|
||||
v -0.500000 -0.500854 -0.499144
|
||||
v 0.500000 -0.499144 0.500855
|
||||
v 0.500000 -0.500855 -0.499144
|
||||
v 0.500000 0.500854 0.499144
|
||||
v 0.500000 0.499144 -0.500854
|
||||
v -0.500000 0.500855 0.499144
|
||||
v -0.500000 0.499144 -0.500855
|
||||
vt 0.000977 0.667790
|
||||
vt 0.000977 0.333151
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 0.333151
|
||||
vt 0.666341 0.667790
|
||||
vt 0.666341 0.333151
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 1.002429
|
||||
vt 0.000977 0.667790
|
||||
vt 0.000977 1.002429
|
||||
vt 0.666341 0.667790
|
||||
vt 0.666341 1.002429
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 1.002429
|
||||
vt 0.666341 0.333151
|
||||
vt 0.999024 0.333151
|
||||
vt 0.666341 0.667790
|
||||
vt 0.999024 0.667790
|
||||
vt 0.999024 1.002429
|
||||
vt 0.666341 1.002429
|
||||
vt 0.999024 0.667790
|
||||
vt 0.666341 0.667790
|
||||
vn -0.0000 -1.0000 0.0017
|
||||
vn 1.0000 -0.0000 0.0000
|
||||
vn 0.0000 1.0000 -0.0017
|
||||
vn -1.0000 0.0000 -0.0000
|
||||
vn 0.0000 -0.0017 -1.0000
|
||||
vn -0.0000 0.0017 1.0000
|
||||
usemtl floor
|
||||
s 1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
f 3/3/1 2/2/1 4/4/1
|
||||
f 3/3/2 4/4/2 5/5/2
|
||||
f 5/5/2 4/4/2 6/6/2
|
||||
f 5/7/3 6/8/3 7/9/3
|
||||
f 7/9/3 6/8/3 8/10/3
|
||||
f 7/11/4 8/12/4 1/13/4
|
||||
f 1/13/4 8/12/4 2/14/4
|
||||
f 2/15/5 8/16/5 4/17/5
|
||||
f 4/17/5 8/16/5 6/18/5
|
||||
f 7/19/6 1/20/6 5/21/6
|
||||
f 5/21/6 1/20/6 3/22/6
|
||||
|
After Width: | Height: | Size: 138 KiB |
@@ -0,0 +1,12 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl Cube.001
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
@@ -0,0 +1,61 @@
|
||||
# hole.obj
|
||||
#
|
||||
|
||||
mtllib hole.mtl
|
||||
o hole
|
||||
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
|
||||
vt 0.000000 0.000000
|
||||
vt 0.333333 0.000000
|
||||
vt 0.666666 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 0.500000
|
||||
vt 0.333333 0.500000
|
||||
vt 0.666666 0.500000
|
||||
vt 1.000000 0.500000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.333333 1.000000
|
||||
vt 0.666666 1.000000
|
||||
vt 1.000000 1.000000
|
||||
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
|
||||
g floor
|
||||
usemtl floor
|
||||
# Back
|
||||
s 1
|
||||
f 1/1/1 2/4/1 3/9/1
|
||||
f 3/9/1 2/4/1 4/12/1
|
||||
# Top
|
||||
s 2
|
||||
f 3/1/2 4/4/2 5/9/2
|
||||
f 5/9/2 4/4/2 6/12/2
|
||||
# Front
|
||||
s 3
|
||||
f 5/1/3 6/4/3 7/9/3
|
||||
f 7/9/3 6/4/3 8/12/3
|
||||
# Bottom
|
||||
s 4
|
||||
f 7/1/4 8/4/4 1/9/4
|
||||
f 1/9/4 8/4/4 2/12/4
|
||||
# Right
|
||||
s 5
|
||||
f 2/1/5 8/4/5 4/9/5
|
||||
f 4/9/5 8/4/5 6/12/5
|
||||
# Left
|
||||
s 6
|
||||
f 7/1/6 1/4/6 5/9/6
|
||||
f 5/9/6 1/4/6 3/12/6
|
||||
|
After Width: | Height: | Size: 880 B |
@@ -0,0 +1,54 @@
|
||||
# Blender v2.92.0 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib breakable_wall.mtl
|
||||
o cube
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
vt 0.000000 0.000000
|
||||
vt 0.333333 0.000000
|
||||
vt 0.000000 0.500000
|
||||
vt 0.333333 0.500000
|
||||
vt 0.666666 1.000000
|
||||
vt 1.000000 1.000000
|
||||
vt 0.666666 0.500000
|
||||
vt 1.000000 0.500000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.333333 1.000000
|
||||
vt 0.000000 0.500000
|
||||
vt 0.333333 0.500000
|
||||
vt 0.666666 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.666666 0.500000
|
||||
vt 1.000000 0.500000
|
||||
vt 0.666666 0.500000
|
||||
vt 0.666666 1.000000
|
||||
vt 0.333333 0.000000
|
||||
vt 0.666666 0.000000
|
||||
vt 0.333333 0.500000
|
||||
vt 0.666666 0.500000
|
||||
vn 0.0000 -0.0000 1.0000
|
||||
vn 0.0000 1.0000 0.0000
|
||||
vn 0.0000 0.0000 -1.0000
|
||||
vn 0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 0.0000 0.0000
|
||||
vn -1.0000 0.0000 0.0000
|
||||
usemtl cube
|
||||
s 1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
f 3/3/1 2/2/1 4/4/1
|
||||
f 3/5/2 4/6/2 5/7/2
|
||||
f 5/7/2 4/6/2 6/8/2
|
||||
f 5/9/3 6/10/3 7/11/3
|
||||
f 7/11/3 6/10/3 8/12/3
|
||||
f 7/13/4 8/14/4 1/15/4
|
||||
f 1/15/4 8/14/4 2/16/4
|
||||
f 2/17/5 8/12/5 4/18/5
|
||||
f 4/18/5 8/12/5 6/10/5
|
||||
f 7/19/6 1/20/6 5/21/6
|
||||
f 5/21/6 1/20/6 3/22/6
|
||||
@@ -0,0 +1,61 @@
|
||||
# floor.obj
|
||||
#
|
||||
|
||||
mtllib floor.mtl
|
||||
o floor
|
||||
|
||||
v -0.500000 -0.500000 0.500000
|
||||
v 0.500000 -0.500000 0.500000
|
||||
v -0.500000 0.500000 0.500000
|
||||
v 0.500000 0.500000 0.500000
|
||||
v -0.500000 0.500000 -0.500000
|
||||
v 0.500000 0.500000 -0.500000
|
||||
v -0.500000 -0.500000 -0.500000
|
||||
v 0.500000 -0.500000 -0.500000
|
||||
|
||||
vt 0.000000 0.000000
|
||||
vt 0.333333 0.000000
|
||||
vt 0.666666 0.000000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 0.500000
|
||||
vt 0.333333 0.500000
|
||||
vt 0.666666 0.500000
|
||||
vt 1.000000 0.500000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.333333 1.000000
|
||||
vt 0.666666 1.000000
|
||||
vt 1.000000 1.000000
|
||||
|
||||
vn 0.000000 0.000000 1.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
|
||||
g floor
|
||||
usemtl floor
|
||||
# Back
|
||||
s 1
|
||||
f 1/1/1 2/4/1 3/9/1
|
||||
f 3/9/1 2/4/1 4/12/1
|
||||
# Top
|
||||
s 2
|
||||
f 3/1/2 4/4/2 5/9/2
|
||||
f 5/9/2 4/4/2 6/12/2
|
||||
# Front
|
||||
s 3
|
||||
f 5/1/3 6/4/3 7/9/3
|
||||
f 7/9/3 6/4/3 8/12/3
|
||||
# Bottom
|
||||
s 4
|
||||
f 7/1/4 8/4/4 1/9/4
|
||||
f 1/9/4 8/4/4 2/12/4
|
||||
# Right
|
||||
s 5
|
||||
f 2/1/5 8/4/5 4/9/5
|
||||
f 4/9/5 8/4/5 6/12/5
|
||||
# Left
|
||||
s 6
|
||||
f 7/1/6 1/4/6 5/9/6
|
||||
f 5/9/6 1/4/6 3/12/6
|
||||
|
After Width: | Height: | Size: 3.7 MiB |
|
Before Width: | Height: | Size: 108 KiB After Width: | Height: | Size: 108 KiB |
@@ -0,0 +1,13 @@
|
||||
# Blender MTL File: 'None'
|
||||
# Material Count: 1
|
||||
|
||||
newmtl floor
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
Ni 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd upper_floor.png
|
||||
@@ -0,0 +1,54 @@
|
||||
# Blender v2.92.0 OBJ File: ''
|
||||
# www.blender.org
|
||||
mtllib upper_floor.mtl
|
||||
o floor
|
||||
v -0.500000 -0.499144 0.500854
|
||||
v -0.500000 -0.500854 -0.499144
|
||||
v 0.500000 -0.499144 0.500855
|
||||
v 0.500000 -0.500855 -0.499144
|
||||
v 0.500000 0.500854 0.499144
|
||||
v 0.500000 0.499144 -0.500854
|
||||
v -0.500000 0.500855 0.499144
|
||||
v -0.500000 0.499144 -0.500855
|
||||
vt 0.000977 0.667790
|
||||
vt 0.000977 0.333151
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 0.333151
|
||||
vt 0.666341 0.667790
|
||||
vt 0.666341 0.333151
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 1.002429
|
||||
vt 0.000977 0.667790
|
||||
vt 0.000977 1.002429
|
||||
vt 0.666341 0.667790
|
||||
vt 0.666341 1.002429
|
||||
vt 0.333659 0.667790
|
||||
vt 0.333659 1.002429
|
||||
vt 0.666341 0.333151
|
||||
vt 0.999024 0.333151
|
||||
vt 0.666341 0.667790
|
||||
vt 0.999024 0.667790
|
||||
vt 0.999024 1.002429
|
||||
vt 0.666341 1.002429
|
||||
vt 0.999024 0.667790
|
||||
vt 0.666341 0.667790
|
||||
vn -0.0000 -1.0000 0.0017
|
||||
vn 1.0000 -0.0000 0.0000
|
||||
vn 0.0000 1.0000 -0.0017
|
||||
vn -1.0000 0.0000 -0.0000
|
||||
vn 0.0000 -0.0017 -1.0000
|
||||
vn -0.0000 0.0017 1.0000
|
||||
usemtl floor
|
||||
s 1
|
||||
f 1/1/1 2/2/1 3/3/1
|
||||
f 3/3/1 2/2/1 4/4/1
|
||||
f 3/3/2 4/4/2 5/5/2
|
||||
f 5/5/2 4/4/2 6/6/2
|
||||
f 5/7/3 6/8/3 7/9/3
|
||||
f 7/9/3 6/8/3 8/10/3
|
||||
f 7/11/4 8/12/4 1/13/4
|
||||
f 1/13/4 8/12/4 2/14/4
|
||||
f 2/15/5 8/16/5 4/17/5
|
||||
f 4/17/5 8/16/5 6/18/5
|
||||
f 7/19/6 1/20/6 5/21/6
|
||||
f 5/21/6 1/20/6 3/22/6
|
||||
|
After Width: | Height: | Size: 158 KiB |
|
Before Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 1.5 KiB |
@@ -173,6 +173,11 @@ void RAY::Window::setIcon(RAY::Image &img)
|
||||
SetWindowIcon(img);
|
||||
}
|
||||
|
||||
void RAY::Window::drawFPS(const RAY::Vector2 &position)
|
||||
{
|
||||
DrawFPS(position.x, position.y);
|
||||
}
|
||||
|
||||
bool RAY::Window::isReady() const
|
||||
{
|
||||
return IsWindowReady();
|
||||
|
||||
@@ -133,6 +133,8 @@ namespace RAY {
|
||||
//! @brief Draw a 3d mesh with material and transform
|
||||
void draw(const Mesh &mesh, const Material &material, const Matrix &transform);
|
||||
|
||||
//! @brief Draws current FPS on the frame
|
||||
void drawFPS(const Vector2 &position);
|
||||
//! @return true if the window's context has been correctly initialized
|
||||
bool isReady() const;
|
||||
|
||||
|
||||
@@ -30,10 +30,22 @@ namespace BBM
|
||||
mov->_velocity.z = 0;
|
||||
}
|
||||
|
||||
const std::string MapGenerator::assetsPath = "./assets/";
|
||||
const std::string MapGenerator::wallAssetsPath = MapGenerator::assetsPath + "map/";
|
||||
const std::string MapGenerator::imageExtension = ".png";
|
||||
const std::string MapGenerator::objExtension = ".obj";
|
||||
const std::string MapGenerator::breakableWallPath = MapGenerator::wallAssetsPath + "breakable_wall";
|
||||
const std::string MapGenerator::unbreakableWallPath = MapGenerator::wallAssetsPath + "unbreakable_wall";
|
||||
const std::string MapGenerator::floorPath = MapGenerator::wallAssetsPath + "floor";
|
||||
const std::string MapGenerator::secondFloorPath = MapGenerator::wallAssetsPath + "upper_floor";
|
||||
const std::string MapGenerator::stairsPath = MapGenerator::wallAssetsPath + "stairs";
|
||||
const std::string MapGenerator::bumperPath = MapGenerator::wallAssetsPath + "bumper";
|
||||
const std::string MapGenerator::holePath = MapGenerator::wallAssetsPath + "hole";
|
||||
|
||||
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";
|
||||
static const std::string unbreakableObj = unbreakableWallPath + objExtension;
|
||||
static const std::string unbreakablePng = unbreakableWallPath + imageExtension;
|
||||
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
@@ -41,7 +53,7 @@ namespace BBM
|
||||
scene->addEntity("Unbreakable Wall")
|
||||
.addComponent<PositionComponent>(i, 0, j)
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj));
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePng));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,43 +61,61 @@ namespace BBM
|
||||
|
||||
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";
|
||||
static const std::string unbreakableObj = unbreakableWallPath + objExtension;
|
||||
static const std::string unbreakablePnj = unbreakableWallPath + imageExtension;
|
||||
|
||||
scene->addEntity("Bottom Wall")
|
||||
.addComponent<PositionComponent>(Vector3f((width + 1) / 2, 0, -1))
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 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>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 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<PositionComponent>(Vector3f(width + 1, 0, height / 2))
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
|
||||
.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 + 1) / 2))
|
||||
.addComponent<PositionComponent>(Vector3f(-1, 0, height / 2))
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 3));
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(unbreakableObj,
|
||||
std::make_pair(MAP_DIFFUSE, unbreakablePnj),
|
||||
RAY::Vector3(1, 1, height + 1));
|
||||
}
|
||||
|
||||
void MapGenerator::generateFloor(int width, int height, std::shared_ptr<WAL::Scene> scene)
|
||||
void MapGenerator::generateFloor(MapBlock map, int width, int height, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
scene->addEntity("Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(width / 2, -1, height / 2))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"), RAY::Vector3(width + 2, 0, height + 2));
|
||||
static const std::string floorObj = floorPath + objExtension;
|
||||
static const std::string floorPng = floorPath + imageExtension;
|
||||
|
||||
for (int i = 0; i < width + 1; i++) {
|
||||
for (int j = 0; j < height + 1; j++) {
|
||||
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,
|
||||
std::make_pair(MAP_DIFFUSE, floorPng));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapGenerator::createElement(Vector3f coords, std::shared_ptr<WAL::Scene> scene, BlockType blockType)
|
||||
{
|
||||
std::map<BlockType, MapElem> elements = {
|
||||
{BREAKABLE, &createBreakable},
|
||||
{BREAKABLE, &createBreakable},
|
||||
{UNBREAKABLE, &createUnbreakable},
|
||||
{HOLE, &createHole},
|
||||
{FLOOR, &createFloor},
|
||||
/* {BUMPER, &createBumper},
|
||||
{STAIRS, &createStairs} */
|
||||
{HOLE, &createHole},
|
||||
{FLOOR, &createFloor},
|
||||
{BUMPER, &createBumper},
|
||||
{STAIRS, &createStairs},
|
||||
{UPPERFLOOR, &createUpperFloor},
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -98,77 +128,109 @@ namespace BBM
|
||||
|
||||
void MapGenerator::createBreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string breakableObj = breakableWallPath + objExtension;
|
||||
static const std::string breakablePng = breakableWallPath + imageExtension;
|
||||
|
||||
scene->addEntity("Breakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
.addComponent<HealthComponent>(1)
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png"));
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(breakableObj, std::make_pair(MAP_DIFFUSE, breakablePng));
|
||||
}
|
||||
|
||||
void MapGenerator::createFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string floorObj = floorPath + objExtension;
|
||||
static const std::string floorPng = floorPath + imageExtension;
|
||||
|
||||
scene->addEntity("Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(coords))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png"));
|
||||
//.addComponent<CollisionComponent>(1)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, std::make_pair(MAP_DIFFUSE, floorPng));
|
||||
}
|
||||
|
||||
void MapGenerator::createUpperFloor(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string floorObj = secondFloorPath + objExtension;
|
||||
static const std::string floorPng = secondFloorPath + imageExtension;
|
||||
|
||||
scene->addEntity("Upper Floor")
|
||||
.addComponent<PositionComponent>(Vector3f(coords))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(floorObj, std::make_pair(MAP_DIFFUSE, floorPng));
|
||||
}
|
||||
|
||||
|
||||
void MapGenerator::createUnbreakable(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string UnbreakableObj = unbreakableWallPath + objExtension;
|
||||
static const std::string UnbreakablePng = unbreakableWallPath + imageExtension;
|
||||
|
||||
scene->addEntity("Unbreakable Block")
|
||||
.addComponent<PositionComponent>(coords)
|
||||
.addComponent<CollisionComponent>(WAL::Callback<WAL::Entity &, const WAL::Entity &>(), &MapGenerator::wallCollide, .75)
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png"));
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(UnbreakableObj,
|
||||
std::make_pair(MAP_DIFFUSE, UnbreakablePng));
|
||||
}
|
||||
|
||||
void MapGenerator::createHole(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string holeObj = holePath + objExtension;
|
||||
static const std::string holePng = holePath + imageExtension;
|
||||
|
||||
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());
|
||||
}
|
||||
}); */
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(holeObj, std::make_pair(MAP_DIFFUSE, holePng));
|
||||
/*.addComponent<CollisionComponent>([](WAL::Entity &other, const WAL::Entity &entity) {
|
||||
if (other.hasComponent<HealthComponent>()) {
|
||||
auto &health = other.getComponent<HealthComponent>();
|
||||
health.takeDmg(health.getHealthPoint());
|
||||
}
|
||||
}, [](WAL::Entity &other, const WAL::Entity &entity){}); */
|
||||
}
|
||||
|
||||
void MapGenerator::createBumper(Vector3f coords, std::shared_ptr<WAL::Scene> scene)
|
||||
{
|
||||
static const std::string bumperObj = bumperPath + objExtension;
|
||||
static const std::string bumperPng = bumperPath + imageExtension;
|
||||
|
||||
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));
|
||||
}
|
||||
} */
|
||||
.addComponent<PositionComponent>(Vector3f(coords.x, coords.y, coords.z))
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(bumperObj, std::make_pair(MAP_DIFFUSE, bumperPng));
|
||||
/* .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)
|
||||
{
|
||||
static const std::string stairsObj = stairsPath + objExtension;
|
||||
static const std::string stairsPng = stairsPath + imageExtension;
|
||||
|
||||
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"));
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>(stairsObj, std::make_pair(MAP_DIFFUSE, stairsPng));
|
||||
}
|
||||
|
||||
bool MapGenerator::isCloseToBlockType(std::map<std::tuple<int, int, int>, BlockType> map, int x, int y, int z, BlockType blockType)
|
||||
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);
|
||||
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;
|
||||
|
||||
{
|
||||
double rnd = static_cast<double>(std::rand()) / RAND_MAX;
|
||||
|
||||
if (rnd > 0.95)
|
||||
return HOLE;
|
||||
if (rnd > 0.10)
|
||||
if (rnd > 0.25)
|
||||
return BREAKABLE;
|
||||
return NOTHING;
|
||||
}
|
||||
@@ -178,22 +240,32 @@ namespace BBM
|
||||
double rnd = static_cast<double>(std::rand()) / RAND_MAX;
|
||||
|
||||
if (rnd > 0.60) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int i = 0; i < width + 1; 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;
|
||||
map[std::make_tuple(i, 0, height)] = UPPERFLOOR;
|
||||
map[std::make_tuple(i, 1, 0)] = map[std::make_tuple(i, 0, 0)];
|
||||
map[std::make_tuple(i, 0, 0)] = UPPERFLOOR;
|
||||
}
|
||||
map[std::make_tuple(0, 0, height - 1)] = STAIRS;
|
||||
map[std::make_tuple(0, 0, 1)] = STAIRS;
|
||||
map[std::make_tuple(width, 0, height - 1)] = STAIRS;
|
||||
map[std::make_tuple(width, 0, 1)] = STAIRS;
|
||||
map[std::make_tuple(width / 2, -1, height - 1)] = BUMPER;
|
||||
map[std::make_tuple(width / 2, -1, 1)] = BUMPER;
|
||||
}
|
||||
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++) {
|
||||
for (int i = width / 2 - width / 4; i < width / 2 + width / 4 + 1; i++) {
|
||||
for (int j = height / 2 - height / 4; j < height / 2 + height / 4 + 1; j++) {
|
||||
if (map[std::make_tuple(i, 0, j)] == FLOOR)
|
||||
continue;
|
||||
map[std::make_tuple(i, 1, j)] = map[std::make_tuple(i, 0, j)];
|
||||
map[std::make_tuple(i, 0, j)] = FLOOR;
|
||||
map[std::make_tuple(i, 0, j)] = UPPERFLOOR;
|
||||
}
|
||||
}
|
||||
map[std::make_tuple(width / 2 - width / 8, 0, height / 2 + height / 4 + 1)] = STAIRS;
|
||||
map[std::make_tuple(width / 2 + width / 8, 0, height / 2 - height / 4 - 1)] = STAIRS;
|
||||
map[std::make_tuple(width / 2 - width / 4 - 1, 0, height / 2 - height / 8)] = STAIRS;
|
||||
map[std::make_tuple(width / 2 + width / 4 + 1, 0, height / 2 + height / 8)] = STAIRS;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@@ -208,50 +280,58 @@ namespace BBM
|
||||
return map;
|
||||
}
|
||||
|
||||
MapGenerator::MapBlock MapGenerator::cleanBreakable(MapBlock map, int width, int height)
|
||||
{
|
||||
for (int i = 0; i < width + 1; i++)
|
||||
for (int j = 0; j < height; j++) {
|
||||
if (map[std::make_tuple(i, 0, j)] == BREAKABLE && isCloseToBlockType(map, i, 0, j, STAIRS))
|
||||
map[std::make_tuple(i, 0, j)] = NOTHING;
|
||||
if (map[std::make_tuple(i, 0, j)] == BREAKABLE && map[std::make_tuple(i, -1, j)] == BUMPER)
|
||||
map[std::make_tuple(i, 0, j)] = NOTHING;
|
||||
}
|
||||
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 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))
|
||||
if (isCloseToBlockType(map, i, 0, j, SPAWNER)) {
|
||||
map[std::make_tuple(i, 0, j)] = NOTHING;
|
||||
else
|
||||
} 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++) {
|
||||
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);
|
||||
map = cleanBreakable(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)
|
||||
void MapGenerator::loadMap(int width, int height, MapBlock 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++)
|
||||
generateFloor(map, width, height, scene);
|
||||
for (int x = 0; x < width + 1; x++)
|
||||
for (int z = 0; z < height + 1; z++)
|
||||
for (int y = -1; y < 1 + 1; y++)
|
||||
createElement(Vector3f(x, y, z), scene, map[std::make_tuple(x, y, z)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace BBM
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "Component/Component.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Collision/CollisionComponent.hpp"
|
||||
#include "Component/Movable/MovableComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
@@ -32,6 +33,7 @@ namespace BBM
|
||||
NOTHING,
|
||||
BREAKABLE,
|
||||
HOLE,
|
||||
UPPERFLOOR,
|
||||
FLOOR,
|
||||
BUMPER,
|
||||
STAIRS,
|
||||
@@ -67,7 +69,7 @@ namespace BBM
|
||||
//! @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);
|
||||
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
|
||||
@@ -96,9 +98,14 @@ namespace BBM
|
||||
|
||||
//! @param coords coords of the element
|
||||
//! @param scene Scene where the map is instanced
|
||||
//! @brief Create bumper of the map
|
||||
//! @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
|
||||
@@ -117,6 +124,34 @@ namespace BBM
|
||||
//! @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 Clean breakable on stairs, bumpers, etc..
|
||||
static MapBlock cleanBreakable(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;
|
||||
|
||||
public:
|
||||
static void wallCollide(WAL::Entity &entity, const WAL::Entity &wall);
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace BBM
|
||||
.addComponent<Drawable3DComponent, RAY3D::Model>("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png"))
|
||||
.addComponent<ControllableComponent>()
|
||||
.addComponent<KeyboardComponent>()
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 1)
|
||||
.addComponent<AnimationsComponent>(RAY::ModelAnimations("assets/player/player.iqm"), 3)
|
||||
.addComponent<CollisionComponent>(1)
|
||||
.addComponent<MovableComponent>();
|
||||
|
||||
|
||||
@@ -8,16 +8,18 @@
|
||||
#include "Component/Renderer/CameraComponent.hpp"
|
||||
#include "Component/Position/PositionComponent.hpp"
|
||||
#include "Component/Renderer/Drawable2DComponent.hpp"
|
||||
#include "Drawables/ADrawable2D.hpp"
|
||||
#include "Drawables/ADrawable3D.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window)
|
||||
RenderSystem::RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode)
|
||||
: System(wal),
|
||||
_window(window),
|
||||
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE)
|
||||
{}
|
||||
_camera(Vector3f(), Vector3f(), Vector3f(0, 1, 0), 50, CAMERA_PERSPECTIVE),
|
||||
_debugMode(debugMode)
|
||||
{
|
||||
this->_window.setFPS(this->FPS);
|
||||
}
|
||||
|
||||
void RenderSystem::onSelfUpdate()
|
||||
{
|
||||
@@ -37,6 +39,8 @@ namespace BBM
|
||||
drawable.drawable->setPosition(Vector2f(pos.position.x, pos.position.y));
|
||||
drawable.drawable->drawOn(this->_window);
|
||||
}
|
||||
if (this->_debugMode)
|
||||
this->_window.drawFPS(Vector2f());
|
||||
this->_window.endDrawing();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace BBM
|
||||
|
||||
//! @brief The camera used to render.
|
||||
RAY::Camera::Camera3D _camera;
|
||||
|
||||
//! @brief Defines if the debug informations must be displayed or not
|
||||
bool _debugMode;
|
||||
|
||||
//! @brief Window framerate limit
|
||||
static constexpr short FPS = 60;
|
||||
|
||||
public:
|
||||
//! @brief A method called after all entities that this system manage has been updated.
|
||||
//! @note render on screen here
|
||||
@@ -30,7 +37,7 @@ namespace BBM
|
||||
void onUpdate(WAL::ViewEntity<CameraComponent, PositionComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
//! @brief ctor
|
||||
RenderSystem(WAL::Wal &wal, RAY::Window &window);
|
||||
RenderSystem(WAL::Wal &wal, RAY::Window &window, bool debugMode = true);
|
||||
//! @brief Default copy ctor
|
||||
RenderSystem(const RenderSystem &) = default;
|
||||
//! @brief Default dtor
|
||||
|
||||