Refactored sprite & transform. Replaced distance with collider when picking objects up.

This commit is contained in:
2016-12-15 22:52:36 +02:00
parent ddae4934ef
commit 42f0d4125b
20 changed files with 273 additions and 208 deletions

View File

@@ -14,14 +14,10 @@ namespace model {
enum Direction
{
None = 0,
East = 1,
North = 2,
West = 4,
South = 8,
NorthEast = North | East,
NorthWest = North | West,
SouthWest = South | West,
SouthEast = South | East
East = 0,
North = 90,
West = 180,
South = 270
};
}

View File

@@ -8,7 +8,7 @@
#include <GameState.h>
#include <model/GameObject.h>
#include <model/Component.h>
#include <model/Transform.h>
#include <iostream>
namespace farmlands {

View File

@@ -1,58 +1,71 @@
/*
* Transform.cpp
*
* Created on: Dec 2, 2016
* Author: tibi
*/
#include <model/GameObject.h>
#include <model/Transform.h>
#include <iostream>
namespace farmlands {
namespace model {
Transform::Transform(GameObject* obj)
: x(0), y(0),
w(0), h(0),
scaleX(1), scaleY(1),
gameObject(obj)
{
}
float Transform::globalX() const
{
if (gameObject->parent())
return gameObject->parent()->transform.globalX() + x;
return x;
return (gameObject->parent())
? x + gameObject->parent()->transform.globalX()
: x;
}
float Transform::globalY() const
{
if (gameObject->parent())
return gameObject->parent()->transform.globalY() + y;
return y;
return (gameObject->parent())
? y + gameObject->parent()->transform.globalY()
: y;
}
void Transform::setGlobalX(float x)
void Transform::setGlobalX(float gx)
{
if (gameObject->parent())
this->x = x - gameObject->parent()->transform.globalX();
this->x = x;
x = (gameObject->parent())
? gx - gameObject->parent()->transform.globalX()
: gx;
}
void Transform::setGlobalY(float y)
void Transform::setGlobalY(float gy)
{
if (gameObject->parent())
this->y = y - gameObject->parent()->transform.globalY();
y = (gameObject->parent())
? gy - gameObject->parent()->transform.globalY()
: gy;
}
this->y = y;
float Transform::globalScaleX() const
{
return (gameObject->parent())
? scaleX * gameObject->parent()->transform.globalScaleX()
: scaleX;
}
float Transform::globalScaleY() const
{
return (gameObject->parent())
? scaleY * gameObject->parent()->transform.globalScaleY()
: scaleY;
}
void Transform::setGlobalScaleX(float gscaleX)
{
scaleX = (gameObject->parent())
? gscaleX / gameObject->parent()->transform.globalScaleX()
: gscaleX;
}
void Transform::setGlobalScaleY(float gscaleY)
{
scaleY = (gameObject->parent())
? gscaleY / gameObject->parent()->transform.globalScaleY()
: gscaleY;
}
}
} /* namespace farmlands */

View File

@@ -21,15 +21,20 @@ namespace model {
// Getters
float globalX() const;
float globalY() const;
float globalScaleX() const;
float globalScaleY() const;
// Setters
void setGlobalX(float x);
void setGlobalY(float y);
void setGlobalX(float gx);
void setGlobalY(float gy);
void setGlobalScaleX(float gscaleX);
void setGlobalScaleY(float gscaleY);
// Local coordinates (relative to parent)
float x, y;
float w, h;
float scaleX, scaleY;
// Parent object
GameObject* gameObject;
};