-
Notifications
You must be signed in to change notification settings - Fork 1
/
flyingObject.cpp
74 lines (62 loc) · 1.24 KB
/
flyingObject.cpp
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
72
73
74
#include "flyingObject.h"
// Put your FlyingObject method bodies here
FlyingObject :: FlyingObject() {
alive = true;
}
FlyingObject :: ~FlyingObject() {
alive = false;
}
void FlyingObject :: advance() {
addY(vel.getDy());
addX(vel.getDx());
}
void FlyingObject :: fire(Point point, float ang, float spd) {
setCoord(point.getX(), point.getY());
setVelSpeed(spd);
vel.setAngle(ang);
vel.calcAng();
alive = true;
}
void FlyingObject :: rotate(float rot, bool dir) {
if(dir) {
vel.setAngle(vel.getAngle() + rot);
} else {
vel.setAngle(vel.getAngle() - rot);
}
}
void FlyingObject :: move(bool dir) {
float x, y;
x = vel.getSpeed() * (-sin(M_PI / 180.0 * vel.getAngle()));
y = vel.getSpeed() * (cos(M_PI / 180.0 * vel.getAngle()));
if(dir) {
addY(y);
addX(x);
} else {
addY(-y);
addX(-x);
}
}
Point FlyingObject :: getPoint() {
Point r;
r.setCoord(getX(), getY());
return r;
}
void FlyingObject :: setPoint(Point p) {
setCoord(p.getX(), p.getX());
}
void FlyingObject :: wrap(Point tl, Point br) {
if(isWrapable()) {
if(getX() < tl.getX()) {
setX(br.getX());
}
if(getX() > br.getX()) {
setX(tl.getX());
}
if(getY() > tl.getY()) {
setY(br.getY());
}
if(getY() < br.getY()) {
setY(tl.getY());
}
}
}