GameObjekt.cpp 1.7 KB

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