-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTowers.cpp
69 lines (58 loc) · 1.59 KB
/
Towers.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
/*
* File: Towers.cpp
* Author: gabriel
*
* Created on 14 de Abril de 2011, 17:53
*/
#include "Towers.h"
#include "externs.h"
#include "GLManager.h"
#include "Map.h"
Towers::Towers(const string &path) : Model_MD2(path) {
num_towers = conf.rint("game:num_towers");
float towers_min_distance = conf.rfloat("game:towers_min_distance");
towers = (Tower **) calloc(num_towers, sizeof (Tower*));
for (int i = 0; i < num_towers; i++) {
towers[i] = new Tower(i, path);
Vertex* pos = NULL;
do {
pos = GLManager::randomVertex();
g_map->adjustPlayableCoords(pos);
for(int j = 0; j < i && pos != NULL; j++) {
if (pos->distance(towers[j]->coords) < towers_min_distance) {
pos = NULL;
}
}
} while(pos == NULL);
pos->y = g_map->triangulateHeight(pos->x, pos->z);
towers[i]->set_pos(pos);
}
createTowerList();
}
void Towers::createTowerList() {
md2_rendermode = 0;
set_scale(conf.rfloat("game:tower_scale"));
tower_list = glGenLists(1);
glNewList(tower_list, GL_COMPILE);
md2_model->drawPlayerItp(true, static_cast<Md2Object::Md2RenderMode> (0));
glEndList();
}
int Towers::get_closest_distance() {
int distance = 9999999;
for (int i = 0; i < num_towers; i++) {
if (towers[i]->dir_dist < distance) {
distance = towers[i]->dir_dist;
}
}
return distance;
}
void Towers::render() {
for (int i = 0; i < num_towers; i++) {
towers[i]->render();
}
}
void Towers::update() {
for (int i = 0; i < num_towers; i++) {
towers[i]->update();
}
}