Add TriggerCell for more in-game fun
This commit is contained in:
parent
fbf18501d7
commit
0037de691f
28
src/cell.cpp
28
src/cell.cpp
|
@ -131,3 +131,31 @@ bool TeleportCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
|||
hero->setPosition(new_x, new_y);
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
TriggerCell::TriggerCell(coordinate cell_x, coordinate cell_y, const std::vector<CellPtr> &cells_to_change, const sf::Color &color) :
|
||||
Cell(cell_x, cell_y, color)
|
||||
{
|
||||
cells.assign(std::move(cells_to_change));
|
||||
}
|
||||
|
||||
TriggerCell::~TriggerCell()
|
||||
{}
|
||||
|
||||
bool TriggerCell::onMovingTo(HeroPtr &hero, LevelPtr &level)
|
||||
{
|
||||
UNUSED(hero)
|
||||
|
||||
Map &map = level->mapArray();
|
||||
|
||||
// We replace needed cells with the ones that the trigger provides.
|
||||
for (const &cell : cells)
|
||||
map[cell->x()][cell->y()].reset(cell.release());
|
||||
|
||||
// Trigger works only once.
|
||||
cells.clear();
|
||||
|
||||
// It's an impassable object, so player can't move to here.
|
||||
return false;
|
||||
}
|
||||
|
|
21
src/cell.h
21
src/cell.h
|
@ -10,6 +10,7 @@ class Level;
|
|||
|
||||
using HeroPtr = std::unique_ptr<Hero>;
|
||||
using LevelPtr = std::unique_ptr<Level>;
|
||||
using CellPtr = std::unique_ptr<Cell>;
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
|
@ -131,4 +132,24 @@ public:
|
|||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
/// A cell which replaces and changes other map cells when activated
|
||||
class TriggerCell : public Cell
|
||||
{
|
||||
private:
|
||||
// Vector of cells to place on map
|
||||
std::vector<CellPtr> cells;
|
||||
|
||||
public:
|
||||
TriggerCell(coordinate cell_x = 0,
|
||||
coordinate cell_y = 0,
|
||||
const std::vector<CellPtr> &cells_to_change = std::vector<CellPtr>(), // Pink
|
||||
const sf::Color &color = sf::Color(255, 192, 203));
|
||||
|
||||
virtual ~TriggerCell() override;
|
||||
|
||||
virtual bool onMovingTo(HeroPtr &hero, LevelPtr &level) override;
|
||||
};
|
||||
|
||||
#endif // CELL_H
|
||||
|
|
Loading…
Reference in New Issue