-
Notifications
You must be signed in to change notification settings - Fork 0
/
Key.cpp
54 lines (45 loc) · 1.3 KB
/
Key.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
/*
*
* File: Key.cpp
* Author: gabriel
*
* Created on 9 de Abril de 2011, 17:42
*/
#include "Key.h"
#include "externs.h"
#include <math.h>
using namespace std;
Key::Key(const string &path) : Model_MD2(path) {
coords = new Vertex(0, 0, 0);
md2_rendermode = 0;
catched = false;
}
void Key::set_pos(Vertex* new_coords) {
coords->x = new_coords->x;
coords->y = new_coords->y;
coords->z = new_coords->z;
}
void Key::render() {
if (g_frustum->sphereInFrustum(new Vertex(coords->x, coords->y + 4, coords->z), 4)) {
if (!catched) {
glPushMatrix();
glTranslatef(coords->x, coords->y, coords->z);
glRotatef(glutGet(GLUT_ELAPSED_TIME) * 0.1, 0, 1, 0);
md2_model->drawPlayerItp(true, static_cast<Md2Object::Md2RenderMode> (md2_rendermode));
// glTranslatef(0, 4, 0);
// glutSolidSphere(4,35,35);
glPopMatrix();
}
}
}
void Key::update() {
if (!catched) {
direction = this->coords->directionVector(g_player->coords);
dir_dist = (sqrt(pow(direction->x, 2) + pow(direction->z, 2)));
if (dir_dist < g_keys->catch_dist) {
catched = true;
g_keys->keys_left--;
Sound::play(SOUND_KEY_CATCH);
}
}
}