-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshot.h
65 lines (56 loc) · 1.36 KB
/
shot.h
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
#ifndef SHOT_H_
#define SHOT_H_
#include "lozobj.h"
#include <cmath>
class Shot : public LoZObject { //A projectile "fired" by enemies
private:
double xx, yy, dx, dy;
bool active;
public:
Shot(int x, int y) : LoZObject(x, y) {
id = '.';
active = false;
}
void draw(QPainter& g) {
if (active) {
g.setPen(QPen(QColor(255,255,255)));
g.setBrush(QBrush(QColor(255,255,255), Qt::SolidPattern));
g.drawEllipse(x, y, 10, 10);
g.setPen(QPen(QColor(255,171,15)));
g.setBrush(QBrush(QColor(255,171,15), Qt::SolidPattern));
g.drawEllipse(x+1, y+1, 8, 8);
g.setPen(QPen(QColor(255,33,33)));
g.setBrush(QBrush(QColor(255,33,33), Qt::SolidPattern));
g.drawEllipse(x+3, y+3, 4, 4);
}
}
void repos(int m, int n) { //Moves projectile to provided space
xx = m;
yy = n;
}
void stop() { //Stops the projectile from moving
dx = 0;
dy = 0;
active = false;
}
void move() { //Moves projectile along its course
xx += dx;
yy += dy;
x = xx;
y = yy;
}
void tick() { //Essentially move()
move();
}
void target(int m, int n) { //Uses *Advanced Calculus* to calcualte the path to take to get to Link
active = true;
double dix = m - xx;
double diy = n - yy;
double hyp = sqrt(dix * dix + diy * diy);
dx = dix / hyp;
dy = diy / hyp;
dx *= 10;
dy *= 10;
}
};
#endif