GameObjekt.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. textur = 0;
  11. texturScale = 0;
  12. intersectable = 1;
  13. }
  14. GameObject::~GameObject()
  15. {
  16. if( textur )
  17. textur->release();
  18. }
  19. void GameObject::setX( float x )
  20. {
  21. this->x = x;
  22. }
  23. void GameObject::setY( float y )
  24. {
  25. this->y = y;
  26. }
  27. void GameObject::setWidth( float width )
  28. {
  29. w = width;
  30. }
  31. void GameObject::setHeight( float height )
  32. {
  33. h = height;
  34. }
  35. bool GameObject::intersectsWith( GameObject *zObj )
  36. {
  37. if( !intersectable || !zObj->intersectable )
  38. return 0;
  39. return x < zObj->x + zObj->w && x + w > zObj->x && y < zObj->y + zObj->h && y + h > zObj->y;
  40. }
  41. void GameObject::render( Bild &rObj )
  42. {
  43. if( textur )
  44. {
  45. if( rObj.setDrawOptions( (int)x, (int)y, (int)w, (int)h ) )
  46. {
  47. if( texturScale )
  48. rObj.alphaBildSkall( 0, 0, (int)w, (int)h, *textur );
  49. else
  50. {
  51. for( int xx = 0; xx < w; xx += textur->getBreite() )
  52. {
  53. for( int yy = 0; yy < h; yy += textur->getHeight() )
  54. rObj.alphaBild( xx, yy, textur->getBreite(), textur->getHeight(), *textur );
  55. }
  56. }
  57. rObj.releaseDrawOptions();
  58. }
  59. }
  60. }
  61. float GameObject::getX() const
  62. {
  63. return x;
  64. }
  65. float GameObject::getY() const
  66. {
  67. return y;
  68. }
  69. float GameObject::getWidth() const
  70. {
  71. return w;
  72. }
  73. float GameObject::getHeight() const
  74. {
  75. return h;
  76. }
  77. bool GameObject::isIntersectable() const
  78. {
  79. return intersectable;
  80. }
  81. float GameObject::abstandZu( GameObject *zObj )
  82. {
  83. return ( Vec2<float>( x + w / 2, y + h / 2 ) - Vec2<float>( zObj->x + zObj->w / 2, zObj->y + zObj->h / 2 ) ).getLength();
  84. }