-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTower.cpp
73 lines (60 loc) · 1.66 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
64
65
66
67
68
69
70
71
72
73
#include "Tower.h"
#include "Bullet.h"
#include "Bullets.h"
#include "externs.h"
#include "GLManager.h"
#include <iostream>
using namespace std;
GLfloat Tower::_scale = 7.5;
float Tower::_max_dist;
float Tower::bullet_delay;
Tower::Tower(int id, const string &path) {
this->id = id;
coords = new Vertex(0, 0, 0);
_max_dist = conf.rfloat("game:tower_range");
can_fire = true;
dir_dist = 999999;
radius = 37;
}
void Tower::set_pos(Vertex *new_coords) {
coords->x = new_coords->x;
coords->y = new_coords->y;
coords->z = new_coords->z;
}
void Tower::update() {
//init_render();
direction = this->coords->directionVector(g_player->coords);
dir_dist = (sqrt(pow(direction->x, 2) + pow(direction->z, 2)));
if (dir_dist < _max_dist) {
ang_x = acos(direction->x / dir_dist);
if (g_player->coords->z > coords->z)
ang_x = -ang_x;
fire();
}
}
void Tower::render() {
if (g_frustum->sphereInFrustum(new Vertex(coords->x, coords->y + 36, coords->z), radius)) {
glPushMatrix();
glTranslatef(coords->x, coords->y, coords->z);
glRotatef(90 + (ang_x * 180) / M_PI, 0, 1, 0);
glCallList(g_towers->tower_list);
glTranslatef(0, 37, 0);
glPopMatrix();
}
}
void Tower::fire() {
if (canFire() && g_player->state == GAME_ON) {
disallowFire();
g_bullets->addBullet(coords, 90 + (ang_x * 180) / M_PI, -ang_x);
glutTimerFunc(Tower::bullet_delay, GLManager::allowTowerFire, this->id);
}
}
bool Tower::canFire() {
return can_fire;
}
void Tower::allowFire() {
can_fire = true;
}
void Tower::disallowFire() {
can_fire = false;
}