GameObject.cpp 1020 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. }
  11. void GameObject::setX( float x )
  12. {
  13. this->x = x;
  14. }
  15. void GameObject::setY( float y )
  16. {
  17. this->y = y;
  18. }
  19. void GameObject::setWidth( float width )
  20. {
  21. w = width;
  22. }
  23. void GameObject::setHeight( float height )
  24. {
  25. h = height;
  26. }
  27. bool GameObject::intersectsWith( GameObject *zObj )
  28. {
  29. return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
  30. }
  31. float GameObject::getX() const
  32. {
  33. return x;
  34. }
  35. float GameObject::getY() const
  36. {
  37. return y;
  38. }
  39. float GameObject::getWidth() const
  40. {
  41. return w;
  42. }
  43. float GameObject::getHeight() const
  44. {
  45. return h;
  46. }
  47. float GameObject::abstandZu( GameObject *zObj )
  48. {
  49. return ( Vec2<float>( x + w / 2, y + h / 2 ) - Vec2<float>( zObj->x + zObj->w / 2, zObj->y + zObj->h / 2 ) ).getLength();
  50. }