summaryrefslogtreecommitdiff
path: root/src/level.hpp
blob: c5eb1eaaaf750cad6cf28fb1f0c61b867470e93d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#pragma once

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Vector2.hpp>
#include <memory>
#include <string>
#include <vector>

#include "tileset.hpp"

namespace silly::editor {
  struct Tile {
      std::shared_ptr<TilesetTile> tile;
      sf::Vector2i position;
      float rotation;
  };

  struct TileLayer {
      std::vector<Tile> tiles;
      TilesetTileType type;
  };

  class TileFloor {
    public:
      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;
      void place_tile(std::shared_ptr<TilesetTile> &tile,
                      const sf::Vector2i &position, const float &rotation);
      void remove_tile(TilesetTileType type, const sf::Vector2i &position);

      const int get_width() const;
      const int get_height() const;

    private:
      int width, height;
      int activeLayerIndex = 0;
      std::vector<TileLayer> layers;
  };

  class TileLevel {
    public:
      TileLevel(const std::string &name) : name(name) {}
      ~TileLevel() = default;

      void add_floor(TileFloor floor);
      void move_to_floor(int floor_id);

      TileFloor &get_current_floor();
      const std::vector<TileFloor> &get_floors() const;

      const std::string &get_name() const;

    private:
      const std::string name;

      int current_floor = 0;
      std::vector<TileFloor> floors;
  };
}