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,6 +6,7 @@
*/
#include <math/GameMath.h>
#include <cmath>
namespace farmlands {
@@ -36,4 +37,16 @@ void translate(float x, float y, model::Direction direction, float distance, flo
*outY = y + dy * distance;
}
void moveTowards(float *x, float *y, float towardsX, float towardsY, float speed)
{
float angle = atan2f(towardsX - *x, towardsY - *y);
*x += cosf(angle) * speed;
*y += sinf(angle) * speed;
}
float distanceSq(float x0, float y0, float x1, float y1)
{
return (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);
}
}

View File

@@ -24,7 +24,9 @@ namespace farmlands {
return value;
}
void translate(float x, float y, model::Direction direction, float distance, float* outX, float *outY);
void translate(float x, float y, model::Direction direction, float distance, float* outX, float* outY);
void moveTowards(float *x, float *y, float towardsX, float towardsY, float speed);
float distanceSq(float x0, float y0, float x1, float y1);
}
#endif /* MATH_GAMEMATH_H_ */