GameObject.cpp 1.0 KB

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