diff --git a/CMakeLists.txt b/CMakeLists.txt index 45d0247d..7a6f85c7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,8 @@ set(SOURCES sources/Models/GameState.hpp sources/Runner/Runner.cpp sources/Runner/Runner.hpp + sources/Map/Map.cpp + sources/Map/Map.hpp sources/Component/Position/PositionComponent.cpp sources/Component/Position/PositionComponent.hpp sources/Component/Movable/MovableComponent.cpp diff --git a/assets/wall/breakable_wall.mtl b/assets/wall/breakable_wall.mtl index 7925a729..86d5a0cf 100644 --- a/assets/wall/breakable_wall.mtl +++ b/assets/wall/breakable_wall.mtl @@ -1,12 +1,54 @@ -# 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 +# 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 diff --git a/assets/wall/breakable_wall.obj b/assets/wall/breakable_wall.obj index 320cb55e..144c9997 100644 --- a/assets/wall/breakable_wall.obj +++ b/assets/wall/breakable_wall.obj @@ -1,338 +1,61 @@ -# Blender v2.92.0 OBJ File: '' -# www.blender.org -mtllib breakable_wall.mtl -o Cube.002 -v 0.404250 -0.428000 -0.404250 -v 0.404250 -0.428000 0.404250 -v -0.404250 -0.428000 0.404250 -v -0.404250 -0.428000 -0.404250 -v -0.404250 0.436000 0.404250 -v 0.404250 0.436000 0.404250 -v 0.404250 0.436000 -0.404250 -v -0.404250 0.436000 -0.404250 -v 0.432000 0.408250 -0.404250 -v 0.432000 0.408250 0.404250 -v 0.432000 -0.400250 0.404250 -v 0.432000 -0.400250 -0.404250 -v 0.404250 -0.500000 -0.404250 -v -0.404250 -0.500000 -0.404250 -v -0.404250 -0.500000 -0.504000 -v 0.404250 -0.500000 -0.504000 -v -0.404250 -0.500000 0.404250 -v 0.404250 -0.500000 0.404250 -v 0.404250 -0.500000 0.504000 -v -0.404250 -0.500000 0.504000 -v -0.404250 0.508000 -0.404250 -v 0.404250 0.508000 -0.404250 -v 0.404250 0.508000 -0.504000 -v -0.404250 0.508000 -0.504000 -v 0.404250 0.508000 0.404250 -v -0.404250 0.508000 0.404250 -v -0.404250 0.508000 0.504000 -v 0.404250 0.508000 0.504000 -v 0.504000 0.408250 -0.404250 -v 0.504000 -0.400250 -0.404250 -v 0.504000 -0.400250 -0.504000 -v 0.504000 0.408250 -0.504000 -v 0.504000 -0.400250 0.404250 -v 0.504000 0.408250 0.404250 -v 0.504000 0.408250 0.504000 -v 0.504000 -0.400250 0.504000 -v -0.504000 0.408250 0.404250 -v -0.504000 -0.400250 0.404250 -v -0.504000 -0.400250 0.504000 -v -0.504000 0.408250 0.504000 -v -0.504000 -0.400250 -0.404250 -v -0.504000 0.408250 -0.404250 -v -0.504000 0.408250 -0.504000 -v -0.504000 -0.400250 -0.504000 -v 0.404250 0.408250 0.504000 -v -0.404250 0.408250 0.504000 -v -0.404250 -0.400250 0.504000 -v 0.404250 -0.400250 0.504000 -v 0.504000 0.508000 -0.404250 -v 0.504000 0.508000 0.404250 -v 0.504000 -0.500000 0.404250 -v 0.504000 -0.500000 -0.404250 -v 0.404250 0.408250 -0.504000 -v -0.404250 0.408250 -0.504000 -v -0.404250 -0.400250 -0.504000 -v 0.404250 -0.400250 -0.504000 -v -0.504000 0.508000 -0.404250 -v -0.504000 0.508000 0.404250 -v -0.504000 -0.500000 0.404250 -v -0.504000 -0.500000 -0.404250 -v 0.504000 0.508000 -0.504000 -v 0.504000 -0.500000 -0.504000 -v 0.504000 -0.500000 0.504000 -v 0.504000 0.508000 0.504000 -v -0.504000 0.508000 0.504000 -v -0.504000 -0.500000 0.504000 -v -0.504000 -0.500000 -0.504000 -v -0.504000 0.508000 -0.504000 -v -0.404250 0.408250 0.432000 -v 0.404250 0.408250 0.432000 -v -0.404250 -0.400250 0.432000 -v 0.404250 -0.400250 0.432000 -v 0.404250 0.408250 -0.432000 -v -0.404250 0.408250 -0.432000 -v 0.404250 -0.400250 -0.432000 -v -0.404250 -0.400250 -0.432000 -v -0.432000 0.408250 0.404250 -v -0.432000 -0.400250 0.404250 -v -0.432000 0.408250 -0.404250 -v -0.432000 -0.400250 -0.404250 -vt 0.287300 0.056300 -vt 0.287300 0.282400 -vt 0.061200 0.282400 -vt 0.061200 0.056300 -vt 0.621800 0.620900 -vt 0.395400 0.620900 -vt 0.395400 0.394400 -vt 0.621800 0.394400 -vt 0.299200 0.394400 -vt 0.299200 0.620900 -vt 0.072700 0.620900 -vt 0.072700 0.394400 -vt 0.287300 0.036100 -vt 0.061200 0.036100 -vt 0.061200 0.008200 -vt 0.287300 0.008200 -vt 0.061200 0.302500 -vt 0.287300 0.302500 -vt 0.287300 0.330400 -vt 0.061200 0.330400 -vt 0.621800 0.374200 -vt 0.395400 0.374200 -vt 0.395400 0.346300 -vt 0.621800 0.346300 -vt 0.395400 0.641000 -vt 0.621800 0.641000 -vt 0.621800 0.669000 -vt 0.395400 0.669000 -vt 0.299200 0.374200 -vt 0.072700 0.374200 -vt 0.072700 0.346300 -vt 0.299200 0.346300 -vt 0.072700 0.641000 -vt 0.299200 0.641000 -vt 0.299200 0.669000 -vt 0.072700 0.669000 -vt 0.718100 0.641000 -vt 0.944500 0.641000 -vt 0.944500 0.669000 -vt 0.718100 0.669000 -vt 0.944500 0.374200 -vt 0.718100 0.374200 -vt 0.718100 0.346300 -vt 0.944500 0.346300 -vt 0.395400 0.696900 -vt 0.621800 0.696900 -vt 0.621800 0.963700 -vt 0.621800 0.991700 -vt 0.395400 0.991700 -vt 0.395400 0.963700 -vt 0.347300 0.394400 -vt 0.347300 0.620900 -vt 0.319300 0.620900 -vt 0.319300 0.394400 -vt 0.052500 0.394400 -vt 0.052500 0.620900 -vt 0.024600 0.620600 -vt 0.024600 0.394300 -vt 0.395400 0.318300 -vt 0.621800 0.318300 -vt 0.621800 0.051500 -vt 0.395400 0.051500 -vt 0.395400 0.023600 -vt 0.621800 0.023600 -vt 0.670000 0.394400 -vt 0.697900 0.394400 -vt 0.697900 0.620900 -vt 0.670000 0.620900 -vt 0.992600 0.620900 -vt 0.964700 0.620900 -vt 0.964700 0.394400 -vt 0.992600 0.394400 -vt 0.319300 0.366500 -vt 0.347300 0.366500 -vt 0.052500 0.366500 -vt 0.024600 0.366500 -vt 0.052500 0.648800 -vt 0.024600 0.648800 -vt 0.319300 0.648800 -vt 0.347300 0.648800 -vt 0.697900 0.648800 -vt 0.670000 0.648800 -vt 0.964700 0.648800 -vt 0.992600 0.648800 -vt 0.964700 0.366500 -vt 0.992600 0.366500 -vt 0.697900 0.366500 -vt 0.670000 0.366500 -vt 0.335400 0.282600 -vt 0.307500 0.282400 -vt 0.307500 0.056300 -vt 0.335400 0.056300 -vt 0.013200 0.282400 -vt 0.013200 0.056300 -vt 0.041100 0.056300 -vt 0.041100 0.282400 -vt 0.642000 0.620900 -vt 0.642000 0.394400 -vt 0.375200 0.394400 -vt 0.375200 0.620900 -vt 0.670000 0.717100 -vt 0.670000 0.943500 -vt 0.642000 0.943500 -vt 0.642000 0.717100 -vt 0.347300 0.717100 -vt 0.375200 0.717100 -vt 0.375200 0.943500 -vt 0.347300 0.943500 -vt 0.347300 0.298200 -vt 0.347300 0.071700 -vt 0.375200 0.071700 -vt 0.375200 0.298200 -vt 0.670000 0.071700 -vt 0.670000 0.298200 -vt 0.642000 0.298200 -vt 0.642000 0.071700 -vt 0.315200 0.008200 -vt 0.315200 0.036100 -vt 0.033300 0.008200 -vt 0.033300 0.036100 -vt 0.033300 0.302500 -vt 0.033300 0.330400 -vt 0.315200 0.302500 -vt 0.315200 0.330400 -vt 0.649800 0.374200 -vt 0.649800 0.346300 -vt 0.367400 0.374200 -vt 0.367400 0.346300 -vt 0.367400 0.669000 -vt 0.367400 0.641000 -vt 0.649800 0.669000 -vt 0.649800 0.641000 -vt 0.649800 0.696900 -vt 0.367400 0.696900 -vt 0.367400 0.991700 -vt 0.367400 0.963700 -vt 0.649800 0.963700 -vt 0.649800 0.991700 -vt 0.367400 0.318300 -vt 0.649800 0.318300 -vt 0.649800 0.023600 -vt 0.649800 0.051500 -vt 0.367400 0.051500 -vt 0.367400 0.023600 -vt 0.621800 0.717100 -vt 0.395400 0.717100 -vt 0.621800 0.943500 -vt 0.395400 0.943500 -vt 0.395400 0.298200 -vt 0.621800 0.298200 -vt 0.395400 0.071700 -vt 0.621800 0.071700 -vt 0.718100 0.620900 -vt 0.944500 0.620900 -vt 0.718100 0.394400 -vt 0.944500 0.394400 -vn 0.0000 -1.0000 -0.0000 -vn 0.0000 1.0000 0.0000 -vn 1.0000 0.0000 0.0000 -vn -1.0000 0.0000 0.0000 -vn 0.0000 0.0000 1.0000 -vn 0.0000 0.0000 -1.0000 -vn -0.7071 0.0000 0.7071 -vn 0.7071 0.0000 0.7071 -vn -0.7071 0.0000 -0.7071 -vn 0.7071 0.0000 -0.7071 -vn 0.7071 -0.7071 0.0000 -vn -0.7071 -0.7071 0.0000 -vn 0.7071 0.7071 0.0000 -vn -0.7071 0.7071 0.0000 -vn 0.0000 -0.7071 0.7071 -vn 0.0000 0.7071 0.7071 -vn 0.0000 -0.7071 -0.7071 -vn 0.0000 0.7071 -0.7071 -usemtl Cube.001 +# 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/2/1 3/3/1 4/4/1 -f 5/5/2 6/6/2 7/7/2 8/8/2 -f 9/9/3 10/10/3 11/11/3 12/12/3 -f 13/13/1 14/14/1 15/15/1 16/16/1 -f 17/17/1 18/18/1 19/19/1 20/20/1 -f 21/21/2 22/22/2 23/23/2 24/24/2 -f 25/25/2 26/26/2 27/27/2 28/28/2 -f 29/29/3 30/30/3 31/31/3 32/32/3 -f 33/33/3 34/34/3 35/35/3 36/36/3 -f 37/37/4 38/38/4 39/39/4 40/40/4 -f 41/41/4 42/42/4 43/43/4 44/44/4 -f 45/45/5 28/28/5 27/27/5 46/46/5 -f 47/47/5 20/48/5 19/49/5 48/50/5 -f 49/51/3 50/52/3 34/53/3 29/54/3 -f 30/55/3 33/56/3 51/57/3 52/58/3 -f 53/59/6 54/60/6 24/24/6 23/23/6 -f 55/61/6 56/62/6 16/63/6 15/64/6 -f 57/65/4 42/66/4 37/67/4 58/68/4 -f 59/69/4 38/70/4 41/71/4 60/72/4 -f 29/54/3 32/73/3 61/74/3 49/51/3 -f 31/75/3 30/55/3 52/58/3 62/76/3 -f 33/56/3 36/77/3 63/78/3 51/57/3 -f 35/79/3 34/53/3 50/52/3 64/80/3 -f 37/67/4 40/81/4 65/82/4 58/68/4 -f 39/83/4 38/70/4 59/69/4 66/84/4 -f 41/71/4 44/85/4 67/86/4 60/72/4 -f 43/87/4 42/66/4 57/65/4 68/88/4 -f 51/89/1 18/90/1 13/91/1 52/92/1 -f 59/93/1 60/94/1 14/95/1 17/96/1 -f 57/65/2 58/68/2 26/97/2 21/98/2 -f 50/52/2 49/51/2 22/99/2 25/100/2 -f 40/101/5 39/102/5 47/103/5 46/104/5 -f 35/105/5 45/106/5 48/107/5 36/108/5 -f 32/109/6 31/110/6 56/111/6 53/112/6 -f 44/113/6 43/114/6 54/115/6 55/116/6 -f 16/16/1 62/117/1 52/118/1 13/13/1 -f 67/119/1 15/15/1 14/14/1 60/120/1 -f 59/121/1 17/17/1 20/20/1 66/122/1 -f 18/18/1 51/123/1 63/124/1 19/19/1 -f 57/125/2 21/21/2 24/24/2 68/126/2 -f 22/22/2 49/127/2 61/128/2 23/23/2 -f 28/28/2 64/129/2 50/130/2 25/25/2 -f 65/131/2 27/27/2 26/26/2 58/132/2 -f 65/131/5 40/133/5 46/46/5 27/27/5 -f 45/45/5 35/134/5 64/129/5 28/28/5 -f 19/49/5 63/135/5 36/136/5 48/50/5 -f 39/137/5 66/138/5 20/48/5 47/47/5 -f 53/59/6 23/23/6 61/128/6 32/139/6 -f 43/140/6 68/126/6 24/24/6 54/60/6 -f 67/141/6 44/142/6 55/61/6 15/64/6 -f 16/63/6 56/62/6 31/143/6 62/144/6 -f 13/13/7 1/1/7 4/4/8 14/14/8 -f 18/90/9 2/2/9 1/1/7 13/91/7 -f 17/17/10 3/3/10 2/2/9 18/18/9 -f 14/95/8 4/4/8 3/3/10 17/96/10 -f 21/21/8 8/8/8 7/7/7 22/22/7 -f 26/97/10 5/5/10 8/8/8 21/98/8 -f 25/25/9 6/6/9 5/5/10 26/26/10 -f 22/99/7 7/7/7 6/6/9 25/100/9 -f 46/46/11 69/145/11 70/146/12 45/45/12 -f 47/103/13 71/147/13 69/145/11 46/104/11 -f 48/50/14 72/148/14 71/147/13 47/47/13 -f 45/106/12 70/146/12 72/148/14 48/107/14 -f 29/29/15 9/9/15 12/12/16 30/30/16 -f 34/53/17 10/10/17 9/9/15 29/54/15 -f 33/33/18 11/11/18 10/10/17 34/34/17 -f 30/55/16 12/12/16 11/11/18 33/56/18 -f 53/59/12 73/149/12 74/150/11 54/60/11 -f 56/111/14 75/151/14 73/149/12 53/112/12 -f 55/61/13 76/152/13 75/151/14 56/62/14 -f 54/115/11 74/150/11 76/152/13 55/116/13 -f 37/37/17 77/153/17 78/154/18 38/38/18 -f 42/66/15 79/155/15 77/153/17 37/67/17 -f 41/41/16 80/156/16 79/155/15 42/42/15 -f 38/70/18 78/154/18 80/156/16 41/71/16 -f 76/152/6 74/150/6 73/149/6 75/151/6 -f 78/154/4 77/153/4 79/155/4 80/156/4 -f 72/148/5 70/146/5 69/145/5 71/147/5 +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 \ No newline at end of file diff --git a/assets/wall/breakable_wall.png b/assets/wall/breakable_wall.png index bdbc5fda..8e18cca8 100644 Binary files a/assets/wall/breakable_wall.png and b/assets/wall/breakable_wall.png differ diff --git a/assets/wall/floor.mtl b/assets/wall/floor.mtl new file mode 100644 index 00000000..7925a729 --- /dev/null +++ b/assets/wall/floor.mtl @@ -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 diff --git a/assets/wall/floor.obj b/assets/wall/floor.obj new file mode 100644 index 00000000..144c9997 --- /dev/null +++ b/assets/wall/floor.obj @@ -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 \ No newline at end of file diff --git a/assets/wall/floor.png b/assets/wall/floor.png new file mode 100644 index 00000000..74624ea9 Binary files /dev/null and b/assets/wall/floor.png differ diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 79018043..8b49b805 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -5,133 +5,159 @@ #include "Map.hpp" #include +#include + +namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { - void Map::generateWall(int width, int height, WAL::Scene &scene) + void Map::generateWall(int width, int height, std::shared_ptr scene) { - WAL::Entity entity("Unbreakable Block"); - - entity.addComponent(Vector3f(0,0,0)); - scene.addEntity(entity); + for (int i = 0; i < width; i++) { + scene->addEntity("Width Wall") + .addComponent(Vector3f(i,0,height)) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); + scene->addEntity("Width Wall") + .addComponent(Vector3f(i,0,0)) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); + } + for (int i = 0; i < height; i++) { + scene->addEntity("Height Wall") + .addComponent(Vector3f(width,0,i)) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); + scene->addEntity("Height Wall") + .addComponent(Vector3f(0,0,i)) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); + } + scene->addEntity("Width Wall") + .addComponent(Vector3f(width, 0,height)) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); } - void Map::generateFloor(int width, int height, WAL::Scene &scene) + void Map::generateFloor(int width, int height, std::shared_ptr scene) { - WAL::Entity entity("Unbreakable Block"); + /* RAY3D::Model model = RAY3D::Model("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); - entity.addComponent(Vector3f(0,0,0)); - scene.addEntity(entity); + model.setScale(RAY::Vector3(width, 0, height)); */ + for (int i = 1; i < width; i++) { + for (int j = 1; j < height; j++) { + scene->addEntity("Floor") + .addComponent(Vector3f(i,-1,j)) + .addComponent>("assets/wall/floor.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/floor.png")); + } + } + //.addComponent>(model); } - void Map::createElement(Vector3f coords, Vector3f size, WAL::Scene &scene, BlockType blockType) + void Map::createElement(Vector3f coords, Vector3f size, std::shared_ptr scene, BlockType blockType) { - std::map> elements = { - {BREAKABLE, &createBreakable}, - {UNBREAKABLE, &createUnbreakable}, - {HOLE, &createHole}, - {BUMPER, &createBumper}, - {STAIRS, &createStairs} + if (blockType == BREAKABLE) { + createBreakable(coords, size, scene); + } else if (blockType == UNBREAKABLE) { + createUnbreakable(coords, size, scene); + } + /* std::map )>> elements = { + {BREAKABLE, &Map::createBreakable}, + {UNBREAKABLE, &Map::createUnbreakable}, + {HOLE, &Map::createHole}, + {BUMPER, &Map::createBumper}, + {STAIRS, &Map::createStairs} }; auto element = std::find(elements.begin(), elements.end(), blockType); if (element == elements.end()) return; - element->second(coords, size, scene); + element->second(coords, size, scene); */ } - void Map::createBreakable(Vector3f coords, Vector3f size, WAL::Scene &scene) + void Map::createBreakable(Vector3f coords, Vector3f size, std::shared_ptr scene) { - WAL::Entity entity("Breakable Block"); - - entity.addComponent(coords); - //entity.addComponent(1); - scene.addEntity(entity); + scene->addEntity("Breakable Block") + .addComponent(coords) + //.addComponent(1) + .addComponent>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png")); + //.addComponent>("assets/wall/breakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/breakable_wall.png")); } - void Map::createUnbreakable(Vector3f coords, Vector3f size, WAL::Scene &scene) + void Map::createUnbreakable(Vector3f coords, Vector3f size, std::shared_ptr scene) { - WAL::Entity entity("Unbreakable Block"); - - entity.addComponent(coords); - scene.addEntity(entity); + scene->addEntity("Unbreakable Block") + .addComponent(coords) + .addComponent>("assets/wall/unbreakable_wall.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/unbreakable_wall.png")); } - void Map::createHole(Vector3f coords, Vector3f size, WAL::Scene &scene) + void Map::createHole(Vector3f coords, Vector3f size, std::shared_ptr scene) { - WAL::Entity entity("Hole Block"); - - entity.addComponent(coords); - /* entity.addComponent([](const WAL::Entity &entity, WAL::Entity &other) { - //En commentaire car manque le HealthComponent sur la branche (pour pas gĂȘner au niveau des erreurs) - if (other.hasComponent()) { - auto &health = other.getComponent(); - health.takeDmg(health.getHealthPoint()); - } - }); */ - scene.addEntity(entity); + scene->addEntity("Hole Block") + .addComponent(coords) + .addComponent>("assets/wall/hole_block.obj", std::make_pair(MAP_DIFFUSE, "assets/wall/hole_block.png")); + /* .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { + if (other.hasComponent()) { + auto &health = other.getComponent(); + health.takeDmg(health.getHealthPoint()); + } + }); */ + WAL::Entity entity(""); } - void Map::createBumper(Vector3f coords, Vector3f size, WAL::Scene &scene) + void Map::createBumper(Vector3f coords, Vector3f size, std::shared_ptr scene) { - WAL::Entity entity("Bumper Block"); - - entity.addComponent(coords); - /* entity.addComponent([](const WAL::Entity &entity, WAL::Entity &other) { + scene->addEntity("Bumper Block") + .addComponent(coords); + /* .addComponent([](const WAL::Entity &entity, WAL::Entity &other) { if (other.hasComponent()) { auto &movable = other.getComponent(); movable.addForce(Vector3f(0, 0, 5)); } } */ - scene.addEntity(entity); } - bool Map::isBlockCloseToPlayer(std::map, BlockType> map, int x, int y) + void Map::createStairs(Vector3f coords, Vector3f size, std::shared_ptr scene) { - if (map[std::make_tuple(x - 1, y)] == '*' || - map[std::make_tuple(x + 1, y)] == '*' || - map[std::make_tuple(x, y + 1)] == '*' || - map[std::make_tuple(x, y - 1)] == '*') + scene->addEntity("Stairs Block") + .addComponent(coords); + } + + bool Map::isBlockCloseToBlockType(std::map, BlockType> map, int x, int y, BlockType blockType) + { + if (map[std::make_tuple(x - 1, y)] == blockType || + map[std::make_tuple(x + 1, y)] == blockType || + map[std::make_tuple(x, y + 1)] == blockType || + map[std::make_tuple(x, y - 1)] == blockType) return (true); return (false); } - - void Map::createStairs(Vector3f coords, Vector3f size, WAL::Scene &scene) - { - WAL::Entity entity("Stairs Block"); - - entity.addComponent(coords); - scene.addEntity(entity); - } Map::BlockType Map::getRandomBlockType(int seed, int blockCreated) { - return BlockType((seed * blockCreated) % (END - 1)); - //! @brief Which one is better ? - //return static_cast((seed * blockCreated) % (END - 1)); - + return static_cast((seed * blockCreated * rand()) % (HOLE)); } - void Map::generateMap(int width, int height, int seed, WAL::Scene &scene) + void Map::generateMap(int width, int height, int seed, std::shared_ptr scene) { std::map, BlockType> map; for (int i = 0; i < width; i++) for (int j = 0; j < height; j++) map[std::make_tuple(i, j)] = NOTHING; - for (int i = 0; i < 4; i++) { - map[std::make_tuple(static_cast(std::pow(seed, i)) % (width - 1) + 1, \ - static_cast(std::pow(seed * 0.7, i)) % (height - 1) + 1)] = SPAWNER; - } + map[std::make_tuple(1, 1)] = SPAWNER; + map[std::make_tuple(width - 1, 1)] = SPAWNER; + map[std::make_tuple(1, height - 2)] = SPAWNER; + map[std::make_tuple(width - 1, height - 1)] = SPAWNER; for (int i = 1; i < width - 1; i++) { for (int j = 1; j < height - 1; j++) { - if (isBlockCloseToPlayer(map, i , j)) { + if (isBlockCloseToBlockType(map, i , j, SPAWNER)) { map[std::make_tuple(i, j)] = NOTHING; } else { map[std::make_tuple(i, j)] = getRandomBlockType(seed, i * width + j); } + if (isBlockCloseToBlockType(map, i , j, UNBREAKABLE) && !isBlockCloseToBlockType(map, i , j, SPAWNER)) { + map[std::make_tuple(i, j)] = BREAKABLE; + } } } + generateWall(width, height, scene); + generateFloor(width, height, scene); for (int i = 1; i < width - 1; i++) { for (int j = 1; j < height - 1; j++) { createElement(Vector3f(i, 0, j), Vector3f(50,50,50), scene, map[std::make_tuple(i, j)]); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 68b2c57f..688708ac 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -3,16 +3,20 @@ // Edited by Benjamin Henry on 5/26/21. // + #pragma once #include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +//#include "Component/Collider/ColliderComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Movable/MovableComponent.hpp" namespace BBM { @@ -40,61 +44,63 @@ namespace BBM //! @param map ASCII map //! @param x x index on the block //! @param y y index on the block - static bool isBlockCloseToPlayer(std::map, BlockType> map, int x, int y); + //! @param blockType blockType to compare with position + static bool isBlockCloseToBlockType(std::map, BlockType> map, int x, int y, 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 wall of the map - static void generateWall(int width, int height, WAL::Scene &scene); + static void generateWall(int width, int height, std::shared_ptr 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, WAL::Scene &scene); + static void generateFloor(int width, int height, std::shared_ptr scene); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create element of the map - static void createElement(Vector3f coords, Vector3f size, WAL::Scene &scene, BlockType blockType); + static void createElement(Vector3f coords, Vector3f size, std::shared_ptr scene, BlockType blockType); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create breakable of the map - static void createBreakable(Vector3f coords, Vector3f size, WAL::Scene &scene); + static void createBreakable(Vector3f coords, Vector3f size, std::shared_ptr scene); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create unbreakable of the map - static void createUnbreakable(Vector3f coords, Vector3f size, WAL::Scene &scene); + static void createUnbreakable(Vector3f coords, Vector3f size, std::shared_ptr scene); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create hole of the map - static void createHole(Vector3f coords, Vector3f size, WAL::Scene &scene); + static void createHole(Vector3f coords, Vector3f size, std::shared_ptr scene); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create bumper of the map - static void createBumper(Vector3f coords, Vector3f size, WAL::Scene &scene); + static void createBumper(Vector3f coords, Vector3f size, std::shared_ptr scene); //! @param coords coords of the element //! @param size size of the element //! @param scene Scene where the map is instanced //! @brief Create stair of the map - static void createStairs(Vector3f coords, Vector3f size, WAL::Scene &scene); + static void createStairs(Vector3f coords, Vector3f size, std::shared_ptr scene); public: //! @param width Width of the map //! @param height Height of the map //! @param scene Scene where the map is instanced //! @brief Generate the map - static void generateMap(int width, int height, int seed, WAL::Scene &scene); + static void generateMap(int width, int height, int seed, std::shared_ptr scene); }; -} // namespace BBM +} // namespace BBM \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 9e256b05..f5796916 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -16,6 +16,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; @@ -56,6 +57,7 @@ namespace BBM scene->addEntity("camera") .addComponent(10, 10, 10) .addComponent(); + Map::generateMap(15, 15, rand(), scene); return scene; } diff --git a/sources/main.cpp b/sources/main.cpp index 43dccd7d..890553c1 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -22,8 +22,14 @@ #include "Drawables/3D/Sphere.hpp" #include "Model/Model.hpp" #include "Model/ModelAnimations.hpp" -#include "System/Renderer/Renderer3DSystem.hpp" -#include "System/Renderer/Renderer2DSystem.hpp" +#include +#include +#include "Component/Renderer/CameraComponent.hpp" +#include +#include +#include +#include +#include #include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include "System/Renderer/RenderScreenSystem.hpp" @@ -31,6 +37,11 @@ #include "Window.hpp" #include "TraceLog.hpp" #include "Wal.hpp" +#include "Map/Map.hpp" +#include "Models/GameState.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; +namespace RAY3D = RAY::Drawables::Drawables3D; const std::vectortextures = { "blue", "cyan", "green", "purple", "red", "yellow" @@ -45,8 +56,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 +76,6 @@ int main(int argc, char **argv) usage(argv[0]); return 1; } -// return demo(); + //return demo(); return BBM::run(); }