diff --git a/assets/scenes/Game.scene b/assets/scenes/Game.scene
index 1188e7f..6aa92f4 100644
--- a/assets/scenes/Game.scene
+++ b/assets/scenes/Game.scene
@@ -14,6 +14,10 @@
+
+
+
+
@@ -32,4 +36,10 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/build/prepareAssets.py b/build/prepareAssets.py
index dab3d4f..2bc6011 100755
--- a/build/prepareAssets.py
+++ b/build/prepareAssets.py
@@ -49,8 +49,8 @@ FILE_TYPES = [
([".sprite"], "Sprite"),
([".config"], "Configuration"),
([".scene"], "Scene"),
- ([".back"], "Background"),
- ([".csv"], "BackgroundLayer"),
+ ([".back"], "Map"),
+ ([".csv"], "MapLayer"),
([".item"], "Item"),
([".items"], "ItemCollection"),
]
diff --git a/src/GameState.cpp b/src/GameState.cpp
index 396e567..02112b2 100644
--- a/src/GameState.cpp
+++ b/src/GameState.cpp
@@ -11,9 +11,10 @@ namespace farmlands {
GameState GameState::s_current;
GameState::GameState()
- : renderContext(),
+ : config(nullptr),
+ renderContext(),
scene(nullptr),
- config(nullptr),
+ itemPrefabs(),
elapsedTime(0),
gameInitialized(false)
{
diff --git a/src/components/Background.cpp b/src/components/Background.cpp
deleted file mode 100644
index a62ee30..0000000
--- a/src/components/Background.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Background.cpp
- *
- * Created on: Dec 1, 2016
- * Author: tibi
- */
-
-#include
-#include
-
-#include
-
-namespace farmlands {
-namespace components {
-
-
-Background::Background(size_t layerCount, size_t rowCount, size_t columnCount)
- : m_cells(new Cell[layerCount * rowCount * columnCount]),
- m_textures(new resources::ResourceId[layerCount]),
- m_layers(layerCount),
- m_rows(rowCount),
- m_columns(columnCount)
-{
-}
-
-Background::~Background()
-{
- delete[] m_cells;
- delete[] m_textures;
-}
-
-model::Component* Background::clone()
-{
- Background* clone = new Background(m_layers, m_rows, m_columns);
- memcpy(clone->m_cells, m_cells, sizeof(Cell) * m_layers * m_rows * m_columns);
- memcpy(clone->m_textures, m_textures, sizeof(resources::ResourceId) * m_layers);
-
- return clone;
-}
-
-Cell Background::cell(size_t layer, size_t row, size_t col) const
-{
- Assert(layer < m_layers, "Layer out of bounds.");
- Assert(row < m_rows, "Row out of bounds.");
- Assert(col < m_columns, "Column out of bounds.");
-
- return m_cells[layer * m_rows * m_columns + row * m_columns + col];
-}
-
-void Background::setCell(size_t layer, size_t row, size_t col, Cell value)
-{
- Assert(layer < m_layers, "Layer out of bounds.");
- Assert(row < m_rows, "Row out of bounds.");
- Assert(col < m_columns, "Column out of bounds.");
-
- m_cells[layer * m_rows * m_columns + row * m_columns + col] = value;
-}
-
-resources::ResourceId Background::texture(size_t layer) const
-{
- Assert(layer < m_layers, "Layer out of bounds.");
- return m_textures[layer];
-}
-
-void Background::setTexture(size_t layer, resources::ResourceId textureId) const
-{
- Assert(layer < m_layers, "Layer out of bounds.");
- m_textures[layer] = textureId;
-}
-
-void Background::dump(unsigned level)
-{
- for (unsigned i = 0; i < level; i++)
- std::cout<<" ";
-
- std::cout << " .Component: Background\n";
-}
-
-} /* namespace model */
-} /* namespace farmlands */
diff --git a/src/components/Background.h b/src/components/Background.h
deleted file mode 100644
index fae8795..0000000
--- a/src/components/Background.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Background.h
- *
- * Created on: Dec 1, 2016
- * Author: tibi
- */
-
-#ifndef MODEL_BACKGROUND_H_
-#define MODEL_BACKGROUND_H_
-
-#include
-#include
-
-namespace farmlands {
-namespace components {
-
- typedef int16_t Cell;
-
- class Background: public model::Component
- {
- public:
- Background(size_t layerCount, size_t rowCount, size_t columnCount);
- virtual ~Background();
-
- virtual model::Component* clone() override;
- virtual void dump(unsigned level) override;
-
- inline size_t layerCount() const { return m_layers; }
- inline size_t rowCount() const { return m_rows; }
- inline size_t columnCount() const { return m_columns; }
-
- Cell cell(size_t layer, size_t row, size_t col) const;
- void setCell(size_t layer, size_t row, size_t col, Cell value);
-
- resources::ResourceId texture(size_t layer) const;
- void setTexture(size_t layer, resources::ResourceId textureId) const;
-
- private:
- Cell* m_cells;
- resources::ResourceId* m_textures;
- size_t m_layers;
- size_t m_rows;
- size_t m_columns;
- };
-
-} /* namespace model */
-} /* namespace farmlands */
-
-#endif /* MODEL_BACKGROUND_H_ */
diff --git a/src/components/Map.cpp b/src/components/Map.cpp
new file mode 100644
index 0000000..2947032
--- /dev/null
+++ b/src/components/Map.cpp
@@ -0,0 +1,113 @@
+/*
+ * Background.cpp
+ *
+ * Created on: Dec 1, 2016
+ * Author: tibi
+ */
+
+#include
+#include
+
+#include
+
+namespace farmlands {
+namespace components {
+
+/****** MapLayer implementation ******/
+
+MapLayer::MapLayer(size_t w, size_t h)
+ : name(),
+ tileSet(),
+ m_cells(new Cell[w * h]),
+ m_w(w), m_h(h)
+{
+}
+
+MapLayer* MapLayer::clone()
+{
+ auto clone = new MapLayer(m_w, m_h);
+ clone->name = name;
+ clone->tileSet = tileSet;
+ memcpy(clone->m_cells, m_cells, sizeof(Cell) * m_w * m_h);
+
+ return clone;
+}
+
+Cell MapLayer::get(size_t row, size_t col) const
+{
+ Assert(row < m_w && col < m_h, "Index out of bounds.");
+
+ return m_cells[row * m_w + col];
+}
+
+Cell* MapLayer::operator [](size_t row)
+{
+ Assert(row < m_w, "Index out of bounds.");
+
+ return m_cells + (row * m_w);
+}
+
+void MapLayer::set(size_t row, size_t col, Cell value)
+{
+ m_cells[row * m_w + col] = value;
+}
+
+
+/****** Map implementation ******/
+
+Map::~Map()
+{
+ for (MapLayer* layer : m_layers)
+ delete layer;
+}
+
+model::Component* Map::clone()
+{
+ Map* clone = new Map();
+ clone->width = width;
+ clone->height = height;
+
+ for (MapLayer* layer : m_layers)
+ {
+ MapLayer* layerClone = layer->clone();
+ clone->m_layers.push_back(layerClone);
+ clone->m_layersStr.emplace(layerClone->name, clone);
+ }
+
+ return clone;
+}
+
+void Map::dump(unsigned level)
+{
+ for (unsigned i = 0; i < level; i++)
+ std::cout<<" ";
+
+ std::cout << " .Component: Background\n";
+}
+
+
+MapLayer& Map::addLayer(std::string name)
+{
+ Assert(m_layersStr.count(name) == 0, "Layer with same name already exists!");
+
+ MapLayer* layer = new MapLayer(width, height);
+ layer->name = name;
+ m_layers.push_back(layer);
+ m_layersStr.emplace(name, layer);
+
+ return *layer;
+}
+
+MapLayer& Map::layer(size_t index)
+{
+ return *m_layers.at(index);
+}
+
+MapLayer& Map::layer(std::string name)
+{
+ return *(MapLayer*)m_layersStr.at(name);
+}
+
+} /* namespace model */
+} /* namespace farmlands */
+
diff --git a/src/components/Map.h b/src/components/Map.h
new file mode 100644
index 0000000..2bdd9da
--- /dev/null
+++ b/src/components/Map.h
@@ -0,0 +1,73 @@
+/*
+ * Map.h
+ *
+ * Created on: Dec 1, 2016
+ * Author: tibi
+ */
+
+#ifndef MODEL_MAP_H_
+#define MODEL_MAP_H_
+
+#include
+#include
+#include
+
+#include
+#include