Advertisement
Guest User

spaceObject.h

a guest
Apr 24th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. /**
  2. clock.h
  3. SpaceObject class definition.
  4. cs162-02, Assignment 2.1
  5.  
  6. @author: Eros
  7. @version: 1.0
  8. */
  9.  
  10. #ifndef SPACE_OBJECT_H
  11. #define SPACE_OBJECT_H
  12. /*
  13. Following are the definitions for Point, SpaceObjType,
  14. and SpaceObject, which you should put in
  15. spaceObject.h.Details about each of the
  16. SpaceObject functions are provided below the
  17. class definition.
  18. */
  19. const int SCREEN_WIDTH =  400;
  20. const int SCREEN_HEIGHT =  400;
  21.  
  22. struct Point {
  23.     double x;
  24.     double y;
  25. };
  26.  
  27. enum SpaceObjType { SHIP, ASTEROID, PHOTON_TORPEDO };
  28.  
  29.  
  30. class SpaceObject {
  31.  
  32. public:
  33.     /**
  34.     SpaceObject constructor
  35.  
  36.     initialize all member variables
  37.     type should be set to ASTEROID
  38.     radius should be set to 20.
  39.     Other member variables should be given some reasonable values.
  40.  
  41.     */
  42.     SpaceObject();
  43.     /**
  44.     Sets SpaceObject that accepts parameters to given values. Initialize all member
  45.     variables to the given
  46.     values.  If values are invalid, use reasonable default values.
  47.  
  48.     @param SpaceObjType type;     //type of object
  49.     @param Point location;    //current location (x,y)
  50.     @param Point velocity;    //current velocity (in pixels/frame)
  51.     @param double angleDeg;   //angle object is facing (in degrees)
  52.     @param double radius;  //gross radius of object (for collision detection)
  53.  
  54.  
  55.     @return true if successful(all given values were valid, clock was set).
  56.     False otherwise.
  57.     */
  58.     SpaceObject(SpaceObjType type, double radius,
  59.         Point location, Point velocity, double angle) {
  60.  
  61.         setRadius(radius);
  62.         setLocation(location.x, location.y);
  63.         setVelocity(velocity.x, velocity.y);
  64.         setAngle(angle);
  65.  
  66.     }
  67.     //=============================================
  68.     //mutators
  69.     /**
  70.     Validate values given and use them to set associated member variables.
  71. setRadius(r) - if given value is negative or > ½ screen height, ignore it.
  72. setLocation(x,y) - if given values are outside screen range (defined by constants),
  73. adjust them if necessary to remain in bounds by adding/subtracting screen size values
  74. from them. These “corrections” make the object reappear back on the opposite side of
  75. the window if it goes off the edge.
  76.     */
  77.     void setRadius(int radius);
  78.     void setLocation(double x, double y);
  79.     void setVelocity(double velocityX, double velocityY);
  80.     void setAngle(double angDeg);
  81.  
  82.     //change angle by given amount.
  83.     void changeAngle(double deltaDeg);
  84.  
  85.     //============================================
  86.     //accessors
  87.     double getRadius();
  88.     Point getLocation();
  89.     Point getVelocity();
  90.     double getAngle();
  91.  
  92.     //============================================
  93.     //others
  94.     void updatePosition();
  95.  
  96. private:
  97.     SpaceObjType type;    //type of object
  98.     Point location;   //current location (x,y)
  99.     Point velocity;   //current velocity (in pixels/frame)
  100.     double angleDeg;      //angle object is facing (in degrees)
  101.     double radius;        //gross radius of object (for collision detection)
  102. };
  103.  
  104. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement