Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1.  
  2. #include "spaceObject.h"
  3.  
  4. /**
  5. Validate values given and use them to set associated member variables.
  6. setRadius(r) - if given value is negative or > ½ screen height, ignore it.
  7. setLocation(x,y) - if given values are outside screen range (defined by constants),
  8. adjust them if necessary to remain in bounds by adding/subtracting screen size values
  9. from them. These “corrections” make the object reappear back on the opposite side of
  10. the window if it goes off the edge.
  11. */
  12.  
  13. SpaceObject::SpaceObject() {
  14.  
  15.     location.x = (0);     //current location (x,y)
  16.     location.y = (0);
  17.     velocity.x = (0);
  18.     velocity.y = (0);//current velocity (in pixels/frame)
  19.     angleDeg = (0);   //angle object is facing (in degrees)
  20.     radius = (1);
  21.     type = ASTEROID;
  22.  
  23. }
  24.  
  25.  
  26. /**
  27. Validate values given and use them to set radius member variable. if given value is
  28. negative or > ½ screen height, ignore it.
  29.  
  30. @param int radius - gross radius of object (for collision detection)
  31.  
  32. @return none
  33. */
  34. void SpaceObject::setRadius(int radius) {
  35.  
  36.     if (radius < 0 || radius > .5*SCREEN_HEIGHT);
  37.     else
  38.         this->radius = radius;
  39.  
  40. };
  41. /**
  42. Returns member variable representing gross radius of
  43. object (for collision detection)
  44.  
  45. @param none
  46.  
  47. @return radius - member variable representing gross radius of object
  48.                  (for collision detection)
  49. */
  50. double SpaceObject::getRadius() {
  51.  
  52.     return radius;
  53.  
  54. };
  55.  
  56.  
  57. /**
  58. Validate values given and use them to set location member variable. if given values are
  59. outside screen range (defined by constants),
  60. adjust them if necessary to remain in bounds by adding/subtracting screen size values from
  61. them. These “corrections” make the object reappear back on the opposite side of the window
  62. if it goes off the edge.
  63.  
  64. @param double x - current location (in pixels/frame) in x direction(ie. horizontally/columns)
  65. @param double y - current location (in pixels/frame) in y direction(ie. vertically/rows)
  66.  
  67. @return none
  68. */
  69. void SpaceObject::setLocation(double x, double y) {
  70.  
  71.         location.x = x % SCREEN_WIDTH;
  72.    
  73.         location.y = y % SCREEN_HEIGHT;
  74.  
  75. };
  76. /**
  77. Returns member variable location x and y coordinates
  78.  
  79. @param none
  80.  
  81. @return Point location - member variable structure representing x and y coordinate
  82. */
  83. Point SpaceObject::getLocation() {
  84.    
  85.     return location;
  86.  
  87. };
  88.  
  89. /**
  90. Set velocity.x and velocity.y of velocity member variable
  91.  
  92. @param double velocityX - current velocity (in pixels/frame) in x direction(ie. horizontally/columns)
  93. @param double velocityY - current velocity (in pixels/frame) in y direction(ie. vertically/rows)
  94.  
  95. @return none
  96. */
  97. void SpaceObject::setVelocity(double velocityX, double velocityY) {
  98.  
  99.     velocity.x = velocityX;
  100.     velocity.y = velocityY;
  101.  
  102. };
  103. /**
  104. returns velocity member variable structure
  105.  
  106. @param none
  107.  
  108. @return none
  109. */
  110. Point SpaceObject::getVelocity() {
  111.  
  112.     return velocity;
  113.  
  114. };
  115.  
  116. /**
  117. Sets angleDeg member variable to user inputted double. If the
  118. inputted angle is grater than 360 degrees it rolls back over to 0
  119.  
  120. @param double angDeg - angle object is facing (in degrees) with 0 degrees being east
  121.  
  122. @return none
  123. */
  124. void SpaceObject::setAngle(double angDeg) {
  125.  
  126.     angleDeg = angDeg % 360;
  127.  
  128. };
  129. /**
  130. Returns copy of angleDeg member variable
  131.  
  132. @param double angDeg - angle object is facing (in degrees) with 0 degrees being east
  133.  
  134. @return none
  135. */
  136. double SpaceObject::getAngle() {
  137.  
  138.     return angleDeg;
  139.  
  140. };
  141. /**
  142. Adds user inputted degree to member variable angleDeg. If the
  143. inputted angle is greater than 360 degrees it rolls back over to 0
  144.  
  145. @param double deltaDeg - change in degree
  146.  
  147. @return none
  148. */
  149. void SpaceObject::changeAngle(double deltaDeg) {
  150.  
  151.     angleDeg += deltaDeg % 360;
  152.  
  153. };
  154. /**
  155. Updates the location based on the current velocity.  
  156. (adds the velocity vector values (x,y) to the location).  Make sure resulting location
  157. is within screen range (rather than repeat the validation here, you should call
  158. setLocation() and pass it the new computed values.
  159.  
  160. @param none
  161.  
  162. @return none
  163. */
  164. void SpaceObject::updatePosition() {
  165.  
  166.     location.x += velocity.x % SCREEN_WIDTH;
  167.     location.y += velocity.y % SCREEN_HEIGHT;
  168.  
  169. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement