-
Notifications
You must be signed in to change notification settings - Fork 1
/
Mine.cpp
72 lines (63 loc) · 2.1 KB
/
Mine.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
#include "Mine.h"
#include "config.h"
#include "util.h"
#include <algorithm>
#include <vector>
#include <stdlib.h>
extern std::vector<GameObject*> allUpdateObjects;
extern std::vector<GameObject*> allRenderObjects;
extern std::vector<Player*> allPlayers;
extern Lights allLightSources;
float randf(float min, float max) {
return (float)((double)(rand()) / (double)(RAND_MAX) * ((double)max - (double)min) + (double)min);
}
glm::vec3 spawn() {
glm::vec3 cand;
do {
cand = glm::vec3(randf(-10.0f, 10.0f), 2.0f, randf(-10.0f, 10.0f));
} while (glm::length(circleCollision(cand, MINE_RADIUS, 4, true, true)) > 0.0f);
return cand;
}
Mine::Mine() : GameObject(MINE_MODEL) {
mModel.position = spawn();
mModel.rotation.y = MINE_BASE_ROTATION;
mModel.scaling = glm::vec3(MINE_SCALING, MINE_SCALING, MINE_SCALING);
mModel.diffuseTexture = new Texture(MINE_TEXTURE);
mModel.normalTexture = new Texture(MINE_TEXTURE_NORMAL);
radius = MINE_RADIUS;
allUpdateObjects.push_back(this);
allRenderObjects.push_back(this);
sight = new PointLight();
sight->lightColor = glm::vec3(1.0f, 0.0f, 0.0f);
sight->intensity = 30.0f;
sight->position = this->mModel.position;
sight->position.y += 1.5f;
sight->falloff.linear = 0.2f;
sight->falloff.exponential = 0.5f;
sight->specular.intensity = 0.0f;
allLightSources.pointLights.push_back(sight);
}
void Mine::update() {
if (exists) {
for (auto o : allUpdateObjects) {
if (o != (GameObject*)this && isColliding(*(GameObject*)this, *o)) {
explode();
if( std::find(allPlayers.begin(), allPlayers.end(), (Player*)o) != allPlayers.end() ) {
((Player*) o)->hit();
}
}
}
sight->position = this->mModel.position;
sight->position.y += 1.5f;
} else {
if (glfwGetTime() > respawntime) {
mModel.position = spawn();
exists = true;
}
}
}
void Mine::explode() {
mModel.position.y = -1000.0f;
exists = false;
respawntime = glfwGetTime() + MINE_RESPAWN_TIME;
}