-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathcharacter.hpp
104 lines (99 loc) · 1.91 KB
/
character.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "projectile.hpp"
#include <cstdlib>
const int fov = 90;
const int spread = 10;
const int hitDamage = 10;
const int hitDamagePlayer = 7;
clock_t timeDamage = clock();
class Character
{
protected:
int type;
int health;
int aim;
int score;
Point location;
vector<Projectile *> activeProjectiles;
public:
void draw()
{
imgv = Scalar(0);
for(float t = aim - fov/2; t <= aim + fov/2;t+=0.1)
castRay(location,t,type);
if(type == 0)
circle(img, location, 7, Scalar(0,255,0),CV_FILLED);
else if(type == 1)
circle(img, location, 7, Scalar(0,0,255),CV_FILLED);
circle(img, location, 7, Scalar(0,0,0), 1);
imshow("Game",img);
}
Point getLocation()
{
return location;
}
void setAim(float theta)
{
aim = 180*theta/CV_PI;
}
void shoot()
{
Projectile *newProjectile = new Projectile(location, aim + (rand()%spread)*pow(-1,rand()));
activeProjectiles.push_back(newProjectile);
}
template <class T>
void updateProjectiles(vector<T> charVec, int creater)
{
for(int i=activeProjectiles.size()-1;i>=0;--i)
{
if(!activeProjectiles[i]->update(charVec, creater))
{
Projectile *tempProj = activeProjectiles[i];
activeProjectiles[i] = activeProjectiles.back();
activeProjectiles.pop_back();
delete tempProj;
}
}
}
void damage()
{
if(type == 1)
health -= hitDamage;
else
{
health -= hitDamagePlayer;
timeDamage = clock();
}
if(health < 0)
{
health = 0;
}
circle(img, location, 7, Scalar(153,255,255), CV_FILLED);
imshow("Game",img);
waitKey(1);
}
virtual void think()
{
return;
}
virtual int checkLife()
{
return true;
}
virtual void givepoints()
{
return;
}
virtual void healthboost()
{
return;
}
virtual int gethealth()
{
return 0;
}
virtual int getscore()
{
return 0;
}
};
vector<Character *> activeChars;