Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "spaceObject.h"
- /**
- 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.
- */
- SpaceObject::SpaceObject() {
- location.x = (0); //current location (x,y)
- location.y = (0);
- velocity.x = (0);
- velocity.y = (0);//current velocity (in pixels/frame)
- angleDeg = (0); //angle object is facing (in degrees)
- radius = (1);
- type = ASTEROID;
- }
- /**
- Validate values given and use them to set radius member variable. if given value is
- negative or > ½ screen height, ignore it.
- @param int radius - gross radius of object (for collision detection)
- @return none
- */
- void SpaceObject::setRadius(int radius) {
- if (radius < 0 || radius > .5*SCREEN_HEIGHT);
- else
- this->radius = radius;
- };
- /**
- Returns member variable representing gross radius of
- object (for collision detection)
- @param none
- @return radius - member variable representing gross radius of object
- (for collision detection)
- */
- double SpaceObject::getRadius() {
- return radius;
- };
- /**
- Validate values given and use them to set location member variable. 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.
- @param double x - current location (in pixels/frame) in x direction(ie. horizontally/columns)
- @param double y - current location (in pixels/frame) in y direction(ie. vertically/rows)
- @return none
- */
- void SpaceObject::setLocation(double x, double y) {
- location.x = x % SCREEN_WIDTH;
- location.y = y % SCREEN_HEIGHT;
- };
- /**
- Returns member variable location x and y coordinates
- @param none
- @return Point location - member variable structure representing x and y coordinate
- */
- Point SpaceObject::getLocation() {
- return location;
- };
- /**
- Set velocity.x and velocity.y of velocity member variable
- @param double velocityX - current velocity (in pixels/frame) in x direction(ie. horizontally/columns)
- @param double velocityY - current velocity (in pixels/frame) in y direction(ie. vertically/rows)
- @return none
- */
- void SpaceObject::setVelocity(double velocityX, double velocityY) {
- velocity.x = velocityX;
- velocity.y = velocityY;
- };
- /**
- returns velocity member variable structure
- @param none
- @return none
- */
- Point SpaceObject::getVelocity() {
- return velocity;
- };
- /**
- Sets angleDeg member variable to user inputted double. If the
- inputted angle is grater than 360 degrees it rolls back over to 0
- @param double angDeg - angle object is facing (in degrees) with 0 degrees being east
- @return none
- */
- void SpaceObject::setAngle(double angDeg) {
- angleDeg = angDeg % 360;
- };
- /**
- Returns copy of angleDeg member variable
- @param double angDeg - angle object is facing (in degrees) with 0 degrees being east
- @return none
- */
- double SpaceObject::getAngle() {
- return angleDeg;
- };
- /**
- Adds user inputted degree to member variable angleDeg. If the
- inputted angle is greater than 360 degrees it rolls back over to 0
- @param double deltaDeg - change in degree
- @return none
- */
- void SpaceObject::changeAngle(double deltaDeg) {
- angleDeg += deltaDeg % 360;
- };
- /**
- Updates the location based on the current velocity.
- (adds the velocity vector values (x,y) to the location). Make sure resulting location
- is within screen range (rather than repeat the validation here, you should call
- setLocation() and pass it the new computed values.
- @param none
- @return none
- */
- void SpaceObject::updatePosition() {
- location.x += velocity.x % SCREEN_WIDTH;
- location.y += velocity.y % SCREEN_HEIGHT;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement