Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. //
  2. // MyRectangle.cpp
  3. // prak_13
  4. //
  5. // Created by Marcel Ochsendorf on 11.01.17.
  6. // Copyright © 2017 Marcel Ochsendorf. All rights reserved.
  7. //
  8. #include "MyRectangle.hpp"
  9.  
  10. MyRectangle::MyRectangle(const int _x,const int _y,const int _w,const int _h){
  11. x = _x;
  12. y = _y;
  13. w = _w;
  14. h = _h;
  15. }
  16. MyRectangle::MyRectangle(){
  17. x = 0;
  18. y = 0;
  19. w = 20;
  20. h = 20;
  21. }
  22.  
  23. MyRectangle::~MyRectangle(){
  24. }
  25. void MyRectangle::set_x(const int _val){
  26. x = _val;
  27. }
  28. void MyRectangle::set_y(const int _val){
  29. y = _val;
  30. }
  31. void MyRectangle::set_w(const int _val){
  32. w = _val;
  33. }
  34. void MyRectangle::set_h(const int _val){
  35. h = _val;
  36. }
  37. int MyRectangle::get_x(){return x;}
  38. int MyRectangle::get_y(){return y;}
  39. int MyRectangle::get_w(){return w;}
  40. int MyRectangle::get_h(){return h;}
  41. void MyRectangle::set(const int _x,const int _y,const int _w,const int _h){
  42. x = _x;
  43. y = _y;
  44. w = _w;
  45. h = _h;
  46. }
  47. void MyRectangle::draw(){
  48. #ifndef UNIT_TEST
  49. gip_stop_updates();
  50. #endif
  51. gip_draw_rectangle(x, y, x+w, y+h, blue);
  52. #ifndef UNIT_TEST
  53. gip_start_updates();
  54. #endif
  55. }
  56. bool MyRectangle::is_point_inside(const int _x, const int _y){
  57. if(_x > x && _x < x+w && _y > y && _y < y+h){
  58. return true;
  59. }
  60. return false;
  61. }
  62.  
  63.  
  64. bool MyRectangle::does_not_collide_with(const MyRectangle& other){
  65.  
  66. if(this->w < other.x){return true;}
  67. else if(other.w < this->x){return true;}
  68. else if(other.y > this->h){return true;}
  69. else if(this->y > other.h){return true;}
  70. return false;
  71. /*
  72. bool inter = true;
  73.  
  74. if(is_point_inside(other.x, other.y)){inter = false;}
  75. if(is_point_inside(other.x + other.w, other.y)){inter = false;}
  76. if(is_point_inside(other.x, other.y + other.h)){inter = false;}
  77. if(is_point_inside(other.x + other.w, other.y + other.h)){inter = false;}
  78.  
  79. if(x > other.x && x < other.x+other.w && y > other.y && y < other.y+other.h){inter = false;}
  80. if(x+w > other.x && x+w < other.x+other.w && y > other.y && y < other.y+other.h){inter = false;}
  81. if(x > other.x && x < other.x+other.w && y+h > other.y && y+h < other.y+other.h){inter = false;}
  82. if(x+w > other.x && x+w < other.x+other.w && y+h > other.y && y+h < other.y+other.h){inter = false;}
  83.  
  84. return inter;
  85. */
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement