-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.cpp
66 lines (55 loc) · 1.7 KB
/
item.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
#include "item.h"
#include "entityManager.h"
#include "graphics.h"
Item::Item() {
model = Graphics::registerTransform();
model->setVisibility(Visibility::SHOW_SELF);
model->setPos(0.0f, 1.0f, 0.0f);
model->setRot(glm::vec3(45.0f, 0.0f, 45.0f));
transform->setVisibility(Visibility::HIDE_ALL);
transform->parentAll(model);
collider->type = ColliderType::TRIGGER;
collider->setExtents(glm::vec3(-0.75f, 0.0f, -0.75f), glm::vec3(0.75f, 1.5f, 0.75f));
rotSpeed = 60.0f;
Physics::setCollisionCallback(this);
}
Item::~Item() {
Graphics::returnTransform(model);
}
void Item::update(GLfloat delta) {
if (shouldDestroy || !collider->awake) {
EntityManagerInstance->ReturnItem(this);
return;
}
timer += delta;
transform->rotate(rotSpeed*delta, glm::vec3(0.0f, 1.0f, 0.0f));
model->setPos(0.0f, 1.0f + sin(timer * 2.0f) * 0.5f, 0.0f);
}
void Item::onCollision(Tag tag, Entity* other) {
if (tag == Tag::PLAYER) {
shouldDestroy = true;
}
}
void Item::init(glm::vec3 pos, ItemType type) {
transform->setPos(pos);
transform->setVisibility(Visibility::HIDE_SELF);
this->type = type;
collider->tag = Tag::ITEM;
switch (type) {
case ItemType::HEAL:
model->color = glm::vec3(0.0, 1.0, 0.0); //green
break;
case ItemType::STAMINA:
model->color = glm::vec3(1.0, 0.0, 0.0); //red
break;
case ItemType::STRENGTH:
model->color = glm::vec3(0.0, 1.0, 1.0); //cyan
break;
case ItemType::AGILITY:
model->color = glm::vec3(1.0, 1.0, 0.0); //yellow
break;
case ItemType::DEXTERITY:
model->color = glm::vec3(1.0, 1.0, 1.0); //white
break;
}
}