forked from arnav-t/Shooting-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectile.hpp
69 lines (64 loc) · 1.32 KB
/
projectile.hpp
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
#include "raycasting.hpp"
const int pStep = 12;
class Projectile
{
private:
int aim;
Point location;
float pStepX, pStepY;
public:
Projectile(Point l, int a)
{
location = l;
aim = a;
pStepX = pStep*cos(aim*CV_PI/180);
pStepY = pStep*sin(aim*CV_PI/180);
}
~Projectile()
{
imgv = Scalar(0);
for(float t = 0; t < 360; t+=0.1)
castRay(location,t,3);
imshow("Game", img);
}
void draw()
{
imgv = Scalar(0);
for(float t = 0; t < 360; t+=0.1)
castRay(location,t,2);
circle(img, location, 4, Scalar(255,0,0),CV_FILLED);
imshow("Game",img);
}
template <class T>
bool update(vector<T> charVec, int creater)
{
location.x += pStepX;
location.y += pStepY;
for(int i=0; i<charVec.size();++i)
{
if(i == creater)
{
continue;
}
Point charLoc = charVec[i]->getLocation();
if(abs(charLoc.x - location.x) + abs(charLoc.y - location.y) < 15)
{ charVec[creater]->givepoints();
charVec[i]->damage();
location.x -= pStepX;
location.y -= pStepY;
return false;
}
}
if(isValid(location.y,location.x) && imgg.at<uchar>(location.y,location.x) < 128)
{
draw();
return true;
}
else
{
location.x -= pStepX;
location.y -= pStepY;
return false;
}
}
};