Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- clock.h
- SpaceObject class definition.
- cs162-02, Assignment 2.1
- @author: Eros
- @version: 1.0
- */
- #ifndef SPACE_OBJECT_H
- #define SPACE_OBJECT_H
- /*
- Following are the definitions for Point, SpaceObjType,
- and SpaceObject, which you should put in
- spaceObject.h.Details about each of the
- SpaceObject functions are provided below the
- class definition.
- */
- const int SCREEN_WIDTH = 400;
- const int SCREEN_HEIGHT = 400;
- struct Point {
- double x;
- double y;
- };
- enum SpaceObjType { SHIP, ASTEROID, PHOTON_TORPEDO };
- class SpaceObject {
- public:
- /**
- SpaceObject constructor
- initialize all member variables
- type should be set to ASTEROID
- radius should be set to 20.
- Other member variables should be given some reasonable values.
- */
- SpaceObject();
- /**
- Sets SpaceObject that accepts parameters to given values. Initialize all member
- variables to the given
- values. If values are invalid, use reasonable default values.
- @param SpaceObjType type; //type of object
- @param Point location; //current location (x,y)
- @param Point velocity; //current velocity (in pixels/frame)
- @param double angleDeg; //angle object is facing (in degrees)
- @param double radius; //gross radius of object (for collision detection)
- @return true if successful(all given values were valid, clock was set).
- False otherwise.
- */
- SpaceObject(SpaceObjType type, double radius,
- Point location, Point velocity, double angle) {
- setRadius(radius);
- setLocation(location.x, location.y);
- setVelocity(velocity.x, velocity.y);
- setAngle(angle);
- }
- //=============================================
- //mutators
- /**
- Validate values given and use them to set associated member variables.
- setRadius(r) - if given value is negative or > ½ screen height, ignore it.
- setLocation(x,y) - if given values are outside screen range (defined by constants),
- adjust them if necessary to remain in bounds by adding/subtracting screen size values
- from them. These “corrections” make the object reappear back on the opposite side of
- the window if it goes off the edge.
- */
- void setRadius(int radius);
- void setLocation(double x, double y);
- void setVelocity(double velocityX, double velocityY);
- void setAngle(double angDeg);
- //change angle by given amount.
- void changeAngle(double deltaDeg);
- //============================================
- //accessors
- double getRadius();
- Point getLocation();
- Point getVelocity();
- double getAngle();
- //============================================
- //others
- void updatePosition();
- private:
- SpaceObjType type; //type of object
- Point location; //current location (x,y)
- Point velocity; //current velocity (in pixels/frame)
- double angleDeg; //angle object is facing (in degrees)
- double radius; //gross radius of object (for collision detection)
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement