summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-02-01 22:51:37 +0500
committerilotterytea <iltsu@alright.party>2025-02-01 22:51:37 +0500
commit79c7edc335fc162e9d2ef9acc5cdf41fbd1bac76 (patch)
tree65decb4938ffd096ccdf7da5f26c2eee27818ac5 /src
parent2f54da5844b959c29788b2a0883ee5dae5bdbbd2 (diff)
feat: layers
Diffstat (limited to 'src')
-rw-r--r--src/floor.cpp31
-rw-r--r--src/floor.hpp16
2 files changed, 32 insertions, 15 deletions
diff --git a/src/floor.cpp b/src/floor.cpp
index 4365c73..8482b48 100644
--- a/src/floor.cpp
+++ b/src/floor.cpp
@@ -11,29 +11,34 @@
namespace silly::editor {
void TileFloor::render(sf::RenderWindow &window) const {
- std::for_each(this->tiles.begin(), this->tiles.end(),
- [&window](const Tile &t) {
- sf::Sprite s(t.tile->texture);
- s.setPosition({t.position.x * (float)TILE_WIDTH,
- t.position.y * (float)TILE_HEIGHT});
-
- window.draw(s);
- });
+ for (auto l = this->layers.begin(); l != this->layers.end(); ++l) {
+ for (auto t = l->tiles.begin(); t != l->tiles.end(); ++t) {
+ sf::Sprite s(t->tile->texture);
+ s.setPosition({t->position.x * (float)TILE_WIDTH,
+ t->position.y * (float)TILE_HEIGHT});
+
+ window.draw(s);
+ }
+ }
}
void TileFloor::place_tile(std::shared_ptr<TilesetTile> &tile,
const sf::Vector2i &position) {
+ TileLayer &layer = this->layers.at(tile->type);
+
if (!std::any_of(
- this->tiles.begin(), this->tiles.end(),
+ layer.tiles.begin(), layer.tiles.end(),
[&position](const Tile &t) { return t.position == position; })) {
- this->tiles.push_back({position, tile});
+ layer.tiles.push_back({position, tile});
}
}
void TileFloor::remove_tile(const sf::Vector2i &position) {
- this->tiles.resize(std::distance(
- this->tiles.begin(),
+ TileLayer &layer = this->layers.at(this->activeLayerIndex);
+
+ layer.tiles.resize(std::distance(
+ layer.tiles.begin(),
std::remove_if(
- this->tiles.begin(), this->tiles.end(),
+ layer.tiles.begin(), layer.tiles.end(),
[&position](const Tile &t) { return t.position == position; })));
}
diff --git a/src/floor.hpp b/src/floor.hpp
index a04fc4b..1a6fe47 100644
--- a/src/floor.hpp
+++ b/src/floor.hpp
@@ -13,9 +13,20 @@ namespace silly::editor {
std::shared_ptr<TilesetTile> tile;
};
+ struct TileLayer {
+ std::vector<Tile> tiles;
+ TilesetTileType type;
+ };
+
class TileFloor {
public:
- TileFloor(int width, int height) : width(width), height(height) {}
+ TileFloor(int width, int height) : width(width), height(height) {
+ // creating vectors for every tile type
+ for (int i = 0; i < 2; i++) {
+ this->layers.push_back({{}, (TilesetTileType)i});
+ }
+ }
+
~TileFloor() = default;
void render(sf::RenderWindow &window) const;
@@ -28,6 +39,7 @@ namespace silly::editor {
private:
int width, height;
- std::vector<Tile> tiles;
+ int activeLayerIndex;
+ std::vector<TileLayer> layers;
};
} \ No newline at end of file