diff --git a/assets/stone.png b/assets/stone.png new file mode 100644 index 0000000..81e1341 Binary files /dev/null and b/assets/stone.png differ diff --git a/cmake/assets.cmake b/cmake/assets.cmake index d0a5a79..d3de89c 100644 --- a/cmake/assets.cmake +++ b/cmake/assets.cmake @@ -36,6 +36,7 @@ assets/bomb.png assets/bomb_pickup.png assets/crate.png assets/crate.svg +assets/stone.png assets/flames.png assets/lightning.png assets/explosion_frame_1.png diff --git a/common/BomberBlokeScene.cpp b/common/BomberBlokeScene.cpp index 2a59044..0c9b3d2 100644 --- a/common/BomberBlokeScene.cpp +++ b/common/BomberBlokeScene.cpp @@ -14,7 +14,8 @@ #include "bomberbloke.h" #include "engine.hpp" #include "scene.hpp" -#include "woodenCrate.hpp" +#include "WoodenCrate.hpp" +#include "StoneBlock.hpp" #include #include #include @@ -185,27 +186,54 @@ BomberBlokeScene::BomberBlokeScene(unsigned int size_x, unsigned int size_y) std::vector> blocks{ size_x, std::vector(size_y, 0) }; + /* Lay down stone blocks */ + int mapType = distrib(gen); + std::string mapTypeName; + if(mapType < 6) + mapTypeName = "Clear"; + else if(mapType < 8) { + mapTypeName = "Walls"; + + // Top and bottom + for(int i = 2; i <= 7; i++) { + blocks[i][2] = STONE; + blocks[i][7] = STONE; + } + // Gates + blocks[2][3] = STONE; + blocks[7][3] = STONE; + blocks[2][6] = STONE; + blocks[7][6] = STONE; + + } else { + mapTypeName = "Grid"; + + for(int i = 1; i < 9; i += 2) + for(int j = 1; j < 9; j += 2) + blocks[i][j] = STONE; + } + log_message(INFO, "Map type: " + mapTypeName); + + /* Generate spawn points */ for (unsigned int i = 0; i < 16; i++) { bool set = false; for (int j = 0; j < 10000; j++) { unsigned int xpos = distrib(gen); unsigned int ypos = distrib(gen); - if (blocks[xpos][ypos] != SPAWN_POINT) { + if (blocks[xpos][ypos] != SPAWN_POINT && blocks[xpos][ypos] != STONE) { blocks[xpos][ypos] = SPAWN_POINT; spawn_points.push_back({ xpos, ypos }); + /* make space around the spawn point */ - if (xpos + 1 < size_x) { + if (xpos + 1 < size_x && blocks[xpos + 1][ypos] == EMPTY) blocks[xpos + 1][ypos] = RESERVED; - } - if (xpos >= 1) { + if (xpos >= 1 && blocks[xpos - 1][ypos] == EMPTY) blocks[xpos - 1][ypos] = RESERVED; - } - if (ypos + 1 < size_y) { + if (ypos + 1 < size_y && blocks[xpos][ypos + 1] == EMPTY) blocks[xpos][ypos + 1] = RESERVED; - } - if (ypos >= 1) { + if (ypos >= 1 && blocks[xpos][ypos - 1] == EMPTY) blocks[xpos][ypos - 1] = RESERVED; - } + set = true; break; } @@ -218,9 +246,13 @@ BomberBlokeScene::BomberBlokeScene(unsigned int size_x, unsigned int size_y) /* Fill in the other blocks - could be wooden crates or other types*/ for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { + if (blocks[i][j] == STONE) { + blocks[i][j] = ACTOR_STONE_BLOCK; + addActor(std::shared_ptr(new StoneBlock(i, j))); + } if (blocks[i][j] == EMPTY) { blocks[i][j] = ACTOR_WOODEN_CRATE; - addActor(std::shared_ptr(new woodenCrate(i, j))); + addActor(std::shared_ptr(new WoodenCrate(i, j))); } } } diff --git a/common/StoneBlock.hpp b/common/StoneBlock.hpp new file mode 100644 index 0000000..d2c1e86 --- /dev/null +++ b/common/StoneBlock.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "staticSprite.hpp" +#include "bomberbloke.h" + +class StoneBlock : public actor{ +public: + + int getType() const{ + return ACTOR_STONE_BLOCK; + } + + StoneBlock(int x=0, int y=0) : actor(double(x), double(y), true){ + mpSpriteHandler = std::shared_ptr(new staticSprite(double(x), double(y), 1.0, 1.0, "stone.png")); + return; + } + + void handleCommand(std::string command){ + (void) command; + return; // Stone blocks are unbreakable + } + + template + void serialize(Archive &archive){ + archive(cereal::base_class(this)); + return; + } +}; + +CEREAL_REGISTER_TYPE(StoneBlock) diff --git a/common/woodenCrate.hpp b/common/WoodenCrate.hpp similarity index 93% rename from common/woodenCrate.hpp rename to common/WoodenCrate.hpp index 521dc11..53ef415 100644 --- a/common/woodenCrate.hpp +++ b/common/WoodenCrate.hpp @@ -9,14 +9,14 @@ #include "BombPickup.hpp" #include "BigBombPickup.hpp" -class woodenCrate : public actor{ +class WoodenCrate : public actor{ public: int getType() const{ return ACTOR_WOODEN_CRATE; } - woodenCrate(int x=0, int y=0) : actor(double(x), double(y), true){ + WoodenCrate(int x=0, int y=0) : actor(double(x), double(y), true){ mpSpriteHandler = std::shared_ptr(new staticSprite(double(x), double(y), 1.0, 1.0, "crate.png")); return; } @@ -64,6 +64,6 @@ class woodenCrate : public actor{ } }; -CEREAL_REGISTER_TYPE(woodenCrate) +CEREAL_REGISTER_TYPE(WoodenCrate) #endif diff --git a/common/bomb.cpp b/common/bomb.cpp index f2c09fe..68be521 100644 --- a/common/bomb.cpp +++ b/common/bomb.cpp @@ -112,17 +112,13 @@ bomb::explode() bool withSound = true; for(const auto& path : targets) { for(const auto& coord : path.squares) { - explosionEffects.push_back( - std::make_shared(coord.first, coord.second, 1, 1, false, 30, 64, 0, withSound) - ); - if(withSound) - withSound = false; // Only one explosion needs to generate a sound effect + bool stopped = false; // Do not continue along blast path past this one + bool blocked = false; // Do not explode on current square auto square = std::make_shared(coord.first, coord.second, 1, 1, false); std::list> actor_list = _pScene->ActorsCollidingWith(square.get()); - bool stopped = false; for (std::shared_ptr pActor : actor_list) { if (pActor.get() == this) continue; @@ -134,12 +130,23 @@ bomb::explode() case ACTOR_BOMB: stopped = true; break; + case ACTOR_STONE_BLOCK: + blocked = true; + break; default: break; } } } - if (stopped) + + if(blocked) + break; + explosionEffects.push_back( + std::make_shared(coord.first, coord.second, 1, 1, false, 30, 64, 0, withSound) + ); + if(withSound) + withSound = false; // Only one explosion needs to generate a sound effect + if(stopped) break; } } diff --git a/common/bomberbloke.h b/common/bomberbloke.h index 6759941..d1a49b2 100644 --- a/common/bomberbloke.h +++ b/common/bomberbloke.h @@ -37,7 +37,8 @@ enum block_types EMPTY, RESERVED, SPAWN_POINT, - WOOD + WOOD, + STONE }; #include "bomberbloke_actors.hpp" @@ -45,7 +46,8 @@ enum block_types /* Cereal magic: include all actor types here so cereal knows about them */ #include "bloke.hpp" #include "bomb.hpp" -#include "woodenCrate.hpp" +#include "WoodenCrate.hpp" +#include "StoneBlock.hpp" #include "BomberBlokeScene.hpp" diff --git a/common/bomberbloke_actors.hpp b/common/bomberbloke_actors.hpp index 009808a..ad99c4c 100644 --- a/common/bomberbloke_actors.hpp +++ b/common/bomberbloke_actors.hpp @@ -3,6 +3,7 @@ enum actor_types{ ACTOR_WOODEN_CRATE, + ACTOR_STONE_BLOCK, ACTOR_METAL_CRATE, ACTOR_EXPLOSIVE_CRATE, ACTOR_DEATH_BLOCK,