diff --git a/assets/scenes/Game.scene b/assets/scenes/Game.scene
index f10be84..87c5bdf 100644
--- a/assets/scenes/Game.scene
+++ b/assets/scenes/Game.scene
@@ -32,6 +32,10 @@
money="50" />
+
+
+
+
diff --git a/src/components/basic/Grid.cpp b/src/components/basic/Grid.cpp
index 78292b4..17c80fc 100644
--- a/src/components/basic/Grid.cpp
+++ b/src/components/basic/Grid.cpp
@@ -6,7 +6,6 @@
*/
#include
-#include
#include
#include
@@ -60,16 +59,8 @@ void Grid::onInitialize()
{
GameObject* obj = *it;
- // Get transform
- Transform* tr = obj->component();
- if (tr == nullptr)
- {
- std::cerr << "Grid: ignoring object " << obj->name << ": object has no transform.";
- continue;
- }
-
// Compute grid position(s)
- Rect bounds(tr->x, tr->y, roundf(tr->w), roundf(tr->h));
+ Rect bounds(obj->transform.x, obj->transform.y, roundf(obj->transform.w), roundf(obj->transform.h));
if (!bounds.intersects(m_bounds))
{
std::cerr << "Grid: ignoring object " << obj->name << ": object outside allowed bounds.";
@@ -139,11 +130,8 @@ void Grid::set(model::GameObject* obj, int x, int y, bool throwOnOverwrite)
}
m_grid[index] = obj;
-
- // Set transform as well
- Transform* transf = obj->component();
- transf->x = x;
- transf->y = y;
+ obj->transform.x = x;
+ obj->transform.y = y;
}
} /* namespace basic */
diff --git a/src/components/basic/Inventory.cpp b/src/components/basic/Inventory.cpp
index 6bb68c9..8fa4aff 100644
--- a/src/components/basic/Inventory.cpp
+++ b/src/components/basic/Inventory.cpp
@@ -142,7 +142,17 @@ void Inventory::setCapacity(size_t capacity)
m_capacity = capacity;
}
+size_t Inventory::emptySlots() const
+{
+ size_t count = 0;
+
+ for (size_t i = 0; i < m_capacity; i++)
+ if (m_items[i] == nullptr)
+ ++count;
+
+ return count;
+}
+
} /* namespace basic */
} /* namespace components */
} /* namespace farmlands */
-
diff --git a/src/components/basic/Inventory.h b/src/components/basic/Inventory.h
index b363388..a0c691e 100644
--- a/src/components/basic/Inventory.h
+++ b/src/components/basic/Inventory.h
@@ -65,6 +65,11 @@ namespace basic {
*/
size_t capacity() const { return m_capacity; }
+ /**
+ * Gets the number of empty slots.
+ */
+ size_t emptySlots() const;
+
private:
size_t m_capacity;
model::GameObject** m_items;
diff --git a/src/components/basic/Sprite.cpp b/src/components/basic/Sprite.cpp
index 5f5588a..f50e3f3 100644
--- a/src/components/basic/Sprite.cpp
+++ b/src/components/basic/Sprite.cpp
@@ -6,7 +6,6 @@
*/
#include
-#include
#include
#include
diff --git a/src/components/basic/Transform.cpp b/src/components/basic/Transform.cpp
deleted file mode 100644
index 9e1886d..0000000
--- a/src/components/basic/Transform.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Transform.cpp
- *
- * Created on: Dec 2, 2016
- * Author: tibi
- */
-
-#include
-#include
-
-#include
-
-namespace farmlands {
-namespace components {
-namespace basic {
-
-Transform::Transform()
- : x(0), y(0),
- w(0), h(0),
- m_parent(nullptr)
-{
-}
-
-Transform::~Transform()
-{
-}
-
-model::Component* Transform::clone()
-{
- Transform* clone = new Transform();
- clone->x = x;
- clone->y = y;
- clone->w = w;
- clone->h = h;
- return clone;
-}
-
-void Transform::onCreate()
-{
- if (gameObject->parent() != nullptr)
- m_parent = gameObject->parent()->component();
-}
-
-float Transform::globalX() const
-{
- return (m_parent) ? m_parent->globalX() + x : x;
-}
-
-float Transform::globalY() const
-{
- return (m_parent) ? m_parent->globalY() + y : y;
-}
-
-void Transform::setGlobalX(float x)
-{
- this->x = (m_parent) ? x - m_parent->globalX() : x;
-}
-
-void Transform::setGlobalY(float y)
-{
- this->y = (m_parent) ? y - m_parent->globalY() : y;
-}
-
-void Transform::dump(unsigned level)
-{
- for (unsigned i = 0; i < level; i++)
- std::cout<<" ";
-
- std::cout << " .Component: Transform ";
- std::cout << "x="<
+#include
#include
#include
#include