Skip to content

Commit

Permalink
Merge pull request #100 from joeyshuttleworth/feature/stoneblocks
Browse files Browse the repository at this point in the history
Stone block level
  • Loading branch information
harveynw committed Feb 11, 2024
2 parents d38489b + ef216d6 commit a7edee1
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 23 deletions.
Binary file added assets/stone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cmake/assets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 43 additions & 11 deletions common/BomberBlokeScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include "bomberbloke.h"
#include "engine.hpp"
#include "scene.hpp"
#include "woodenCrate.hpp"
#include "WoodenCrate.hpp"
#include "StoneBlock.hpp"
#include <algorithm>
#include <functional>
#include <memory>
Expand Down Expand Up @@ -185,27 +186,54 @@ BomberBlokeScene::BomberBlokeScene(unsigned int size_x, unsigned int size_y)

std::vector<std::vector<int>> blocks{ size_x, std::vector<int>(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;
}
Expand All @@ -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<StoneBlock>(new StoneBlock(i, j)));
}
if (blocks[i][j] == EMPTY) {
blocks[i][j] = ACTOR_WOODEN_CRATE;
addActor(std::shared_ptr<woodenCrate>(new woodenCrate(i, j)));
addActor(std::shared_ptr<WoodenCrate>(new WoodenCrate(i, j)));
}
}
}
Expand Down
31 changes: 31 additions & 0 deletions common/StoneBlock.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <random>
#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<staticSprite>(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<class Archive>
void serialize(Archive &archive){
archive(cereal::base_class<actor>(this));
return;
}
};

CEREAL_REGISTER_TYPE(StoneBlock)
6 changes: 3 additions & 3 deletions common/woodenCrate.hpp → common/WoodenCrate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<staticSprite>(new staticSprite(double(x), double(y), 1.0, 1.0, "crate.png"));
return;
}
Expand Down Expand Up @@ -64,6 +64,6 @@ class woodenCrate : public actor{
}
};

CEREAL_REGISTER_TYPE(woodenCrate)
CEREAL_REGISTER_TYPE(WoodenCrate)

#endif
21 changes: 14 additions & 7 deletions common/bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Explosion>(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<actor>(coord.first, coord.second,
1, 1, false);
std::list<std::shared_ptr<actor>> actor_list =
_pScene->ActorsCollidingWith(square.get());
bool stopped = false;
for (std::shared_ptr<actor> pActor : actor_list) {
if (pActor.get() == this)
continue;
Expand All @@ -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<Explosion>(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;
}
}
Expand Down
6 changes: 4 additions & 2 deletions common/bomberbloke.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ enum block_types
EMPTY,
RESERVED,
SPAWN_POINT,
WOOD
WOOD,
STONE
};

#include "bomberbloke_actors.hpp"

/* 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"

Expand Down
1 change: 1 addition & 0 deletions common/bomberbloke_actors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

enum actor_types{
ACTOR_WOODEN_CRATE,
ACTOR_STONE_BLOCK,
ACTOR_METAL_CRATE,
ACTOR_EXPLOSIVE_CRATE,
ACTOR_DEATH_BLOCK,
Expand Down

0 comments on commit a7edee1

Please sign in to comment.