GameObject.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. Richtung getRichtungFromString( Text str )
  15. {
  16. if( str.istGleich( "OBEN" ) )
  17. return OBEN;
  18. if( str.istGleich( "LINKS" ) )
  19. return LINKS;
  20. if( str.istGleich( "UNTEN" ) )
  21. return UNTEN;
  22. if( str.istGleich( "RECHTS" ) )
  23. return RECHTS;
  24. return MITTE;
  25. }
  26. GameObject::GameObject( VariableTyp typ, int x, int y, int width, int height )
  27. : Variable( typ )
  28. {
  29. this->x = (float)x;
  30. this->y = (float)y;
  31. w = (float)width;
  32. h = (float)height;
  33. }
  34. void GameObject::setX( float x )
  35. {
  36. this->x = x;
  37. }
  38. void GameObject::setY( float y )
  39. {
  40. this->y = y;
  41. }
  42. void GameObject::setWidth( float width )
  43. {
  44. w = width;
  45. }
  46. void GameObject::setHeight( float height )
  47. {
  48. h = height;
  49. }
  50. bool GameObject::intersectsWith( GameObject *zObj )
  51. {
  52. return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
  53. }
  54. float GameObject::getX() const
  55. {
  56. return x;
  57. }
  58. float GameObject::getY() const
  59. {
  60. return y;
  61. }
  62. float GameObject::getWidth() const
  63. {
  64. return w;
  65. }
  66. float GameObject::getHeight() const
  67. {
  68. return h;
  69. }