-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRessource.cpp
93 lines (70 loc) · 1.86 KB
/
Ressource.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Ressource.h"
#include "Map.h"
Location * Ressource::spawnLoc(Location* location, Map* map)
{
glm::vec2 bias = locBias; //or location->getPos() should be same
//while the location this object was given was invalid
int tries = 0; //so that we don't loop for too long
while (!location->state) {
int dir = rand() % 5;
switch (dir) {
case 0:
bias += glm::vec2(1.0, 0.0);
location = map->getLoc(bias);
break;
case 1:
bias += glm::vec2(-1.0, 0.0);
location = map->getLoc(bias);
break;
case 2:
bias += glm::vec2(0.0, 1.0);
location = map->getLoc(bias);
break;
case 3:
bias += glm::vec2(0.0, -1.0);
location = map->getLoc(bias);
break;
default:
bias += glm::vec2(1.0, 1.0);
location = map->getLoc(bias);
break;
}
tries++;
if (tries > 20) {
location = map->getLoc(rand() % MAPSIZE, rand() % MAPSIZE);
}
} //now we know that location is free!
return location;
}
Ressource::Ressource()
{
}
Ressource::~Ressource()
{
}
void Ressource::destroy()
{
//particle effect?
//remove from gameMode, where is reference?
loc->release(this); //release lock
game->removeRessource(this);
this->~Ressource(); //currently destroys but doesn't remove the map reference. May free twice? But not big deal
}
void Ressource::draw(GLuint shaderprog)
{
//send some info about where you are
glUniform2f(glGetUniformLocation(shaderprog, "location"), loc->getPos().x, loc->getPos().y);
glUniform1f(glGetUniformLocation(shaderprog, "overlay"), 0.0f);
//std::cout << topLeft->getPos().x << " " << topLeft->getPos().y << std::endl;
//std::cout<< loc->getPos().x << " " << loc->getPos().y << std::endl;
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
}
void Ressource::draw(unsigned int, GLuint)
{
}
int Ressource::getTextLoc()
{
return 0;
}