-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tower.cpp
63 lines (55 loc) · 1.13 KB
/
Tower.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
#include "Tower.h"
#include "GameSounds.h"
Tower::Tower(float inx, float iny, float inz, int gx, int gy):
GameObject(inx, iny, inz), grid_x(gx), grid_y(gy), ai(x, y, z)
{
}
Tower::~Tower(void)
{
}
void Tower::draw(void)
{
this->draw(-1,GL_RENDER);
}
bool Tower::shoot(){
bool ret = ai.shoot();
if(ret){
gamesounds::playSound(sound, x, y, z);
}
return ret;
}
bool Tower::operator==(const Tower& other){
return (this->grid_x == other.grid_x) && (this->grid_y == other.grid_y);
}
bool Tower::operator==(const g_elem& other){
return (this->grid_x == other.x) && (this->grid_y == other.y);
}
void Tower::step(int dt){
if(ai.last_atk <= ai.atk_dt){
ai.last_atk += dt;
}
if(ai.atk_dt < ai.last_atk){
if(shoot()){
ai.last_atk = 0;
if(ai.hasTarget)
projectiles->addProjectile(weapon, ai.target, x, y, z);
}
}
}
int Tower::getKill(){
if(ai.hasKill){
ai.hasKill = false;
return ai.target->getValue();
}
return 0;
}
int Tower::takeDamage(int damage)
{
hp = hp - damage;
if(hp <= 0)
{
return 0;
}
else
return hp;
}