-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.cpp
More file actions
executable file
·71 lines (59 loc) · 1.25 KB
/
Point.cpp
File metadata and controls
executable file
·71 lines (59 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* Point.cpp
*
* Created on: 23-Mar-2018
* Author: parkerqueen Raza
*/
#include "Point.h"
//Constructor, random position
Point::Point() {
setRandom();
}
//Constructor, given position
Point::Point(float x, float y) {
set(x, y);
}
//Sets the given values
void Point::set(float x, float y) {
this->x = x;
this->y = y;
}
//Sets X
void Point::setX(float x) {
this->x = x;
}
//Gets X
float Point::getX() const {
return x;
}
//Sets Y
void Point::setY(float y) {
this->y = y;
}
//Gets Y
float Point::getY() const {
return y;
}
//Sets random values excluding 200 px square area around center for the ship's first spawn
void Point::setRandom() {
x = GetRandInRange(50, BWIDTH - 50);
y = GetRandInRange(50, BHEIGHT - 50);
if (x > (BWIDTH / 2) - 200 && x < (BWIDTH / 2) + 200
&& y > (BHEIGHT / 2) - 200 && y < (BHEIGHT / 2) + 200)
setRandom();
}
//Subscript operator for non const Point
float & Point::operator[](int axis) {
if (axis == 0)
return x;
else
return y;
}
//Subscript operator for const Point
float Point::operator[](int axis) const {
return (axis == 0) ? x : y;
}
//Returns the distance between two Points
float Point::distance(Point & point) {
return sqrt((x - point[0]) * (x - point[0]) + (y - point[1]) * (y - point[1]));
}