GameObject.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "GameObject.h"
  2. #include "Punkt.h"
  3. GameObject::GameObject( VariableTyp typ, int x, int y, int width, int height )
  4. : Variable( typ )
  5. {
  6. this->x = (float)x;
  7. this->y = (float)y;
  8. w = (float)width;
  9. h = (float)height;
  10. intersectable = 1;
  11. }
  12. void GameObject::setX( float x )
  13. {
  14. this->x = x;
  15. }
  16. void GameObject::setY( float y )
  17. {
  18. this->y = y;
  19. }
  20. void GameObject::setWidth( float width )
  21. {
  22. w = width;
  23. }
  24. void GameObject::setHeight( float height )
  25. {
  26. h = height;
  27. }
  28. bool GameObject::intersectsWith( GameObject *zObj )
  29. {
  30. if( !intersectable || !zObj->intersectable )
  31. return 0;
  32. return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
  33. }
  34. float GameObject::getX() const
  35. {
  36. return x;
  37. }
  38. float GameObject::getY() const
  39. {
  40. return y;
  41. }
  42. float GameObject::getWidth() const
  43. {
  44. return w;
  45. }
  46. float GameObject::getHeight() const
  47. {
  48. return h;
  49. }
  50. bool GameObject::isIntersectable() const
  51. {
  52. return intersectable;
  53. }
  54. float GameObject::abstandZu( GameObject *zObj )
  55. {
  56. return ( Vec2<float>( x + w / 2, y + h / 2 ) - Vec2<float>( zObj->x + zObj->w / 2, zObj->y + zObj->h / 2 ) ).getLength();
  57. }