diff --git a/build-debug/sfml-test b/build-debug/sfml-test index 8ebb7db..1e3af72 100755 Binary files a/build-debug/sfml-test and b/build-debug/sfml-test differ diff --git a/build-release/sfml-test b/build-release/sfml-test index c77b482..ce6901d 100755 Binary files a/build-release/sfml-test and b/build-release/sfml-test differ diff --git a/src/cell.cpp b/src/cell.cpp index b0b4908..7f362bd 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -134,10 +134,10 @@ bool TeleportCell::onMovingTo(HeroPtr &hero, LevelPtr &level) /////////////////////////////////////// -TriggerCell::TriggerCell(coordinate cell_x, coordinate cell_y, const std::vector &cells_to_change, const sf::Color &color) : +TriggerCell::TriggerCell(std::vector &&cells_to_change, coordinate cell_x, coordinate cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color) { - cells.assign(std::move(cells_to_change)); + cells = std::move(cells_to_change); } TriggerCell::~TriggerCell() @@ -150,11 +150,14 @@ bool TriggerCell::onMovingTo(HeroPtr &hero, LevelPtr &level) 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(); + for (CellPtr &cell : cells) + { + const coordinate &y = cell->y(); + const coordinate &x = cell->x(); + + map[x][y].release(); + map[x][y] = std::move(cell); + } // It's an impassable object, so player can't move to here. return false; diff --git a/src/cell.h b/src/cell.h index bc68aef..8f79d14 100644 --- a/src/cell.h +++ b/src/cell.h @@ -1,12 +1,16 @@ #ifndef CELL_H #define CELL_H -#include "entity.h" #include +#include + #include +#include "entity.h" + class Hero; class Level; +class Cell; using HeroPtr = std::unique_ptr; using LevelPtr = std::unique_ptr; @@ -142,9 +146,9 @@ private: std::vector cells; public: - TriggerCell(coordinate cell_x = 0, - coordinate cell_y = 0, - const std::vector &cells_to_change = std::vector(), // Pink + TriggerCell(std::vector &&cells_to_change, + coordinate cell_x = 0, + coordinate cell_y = 0, // Pink const sf::Color &color = sf::Color(255, 192, 203)); virtual ~TriggerCell() override; diff --git a/src/game.cpp b/src/game.cpp index 4e63e0d..d68f903 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -171,6 +171,12 @@ void Game::loadLevel(int level_index) for (coordinate y = 0; y < side; ++y) map[x][y] = std::make_unique(x, y); + std::vector trigger_cells; + + trigger_cells.emplace_back(std::make_unique(0, 0)); + trigger_cells.emplace_back(std::make_unique(1, 0)); + trigger_cells.emplace_back(std::make_unique(0, 1)); + switch (level_index) { case 1: @@ -197,6 +203,7 @@ void Game::loadLevel(int level_index) map[9][6] = std::make_unique(9, 6); map[8][7] = std::make_unique(8, 7); map[2][3] = std::make_unique(2, 3, 5); + map[3][3] = std::make_unique(std::move(trigger_cells), 3, 3); break; default: main_window.close(); diff --git a/src/level.h b/src/level.h index 6fa26f2..dc7ea05 100644 --- a/src/level.h +++ b/src/level.h @@ -1,12 +1,12 @@ #ifndef LEVEL_H #define LEVEL_H -#include "cell.h" #include +#include "cell.h" constexpr coordinate side = 32; -using Row = std::array, side>; +using Row = std::array; using Map = std::array; /// Abstraction over 2D array to quickly get access to level cells