Implemented picking up objects and dropping them. Also, made transform part of GameObject instead of a separate component.

This commit is contained in:
2016-12-14 23:32:39 +02:00
parent f8571b36bd
commit ddae4934ef
23 changed files with 237 additions and 180 deletions

View File

@ -6,7 +6,6 @@
*/
#include <components/basic/Grid.h>
#include <components/basic/Transform.h>
#include <utils/Assert.h>
#include <utils/Exceptions.h>
@ -60,16 +59,8 @@ void Grid::onInitialize()
{
GameObject* obj = *it;
// Get transform
Transform* tr = obj->component<Transform>();
if (tr == nullptr)
{
std::cerr << "Grid: ignoring object " << obj->name << ": object has no transform.";
continue;
}
// Compute grid position(s)
Rect<int> bounds(tr->x, tr->y, roundf(tr->w), roundf(tr->h));
Rect<int> 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<Transform>();
transf->x = x;
transf->y = y;
obj->transform.x = x;
obj->transform.y = y;
}
} /* namespace basic */