GameObjekt.cpp 1.7 KB

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