-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectile.cpp
108 lines (96 loc) · 3.5 KB
/
projectile.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "projectile.h"
#include "graphics.h"
#include "entityManager.h"
Projectile::Projectile() {
collider->type = ColliderType::TRIGGER;
collider->setExtents(glm::vec3(-0.5f), glm::vec3(0.5f));
transform->setVisibility(Visibility::HIDE_ALL);
transform->color = glm::vec3(1.0f, 0.2f, 0.0f);
transform->shape = Shape::CUBE_SOLID;
Physics::setCollisionCallback(this);
}
Projectile::~Projectile() {
}
void Projectile::activate(ProjectileType type, glm::vec3 pos, glm::vec3 vel) {
this->type = type;
transform->setPos(pos);
transform->setVisibility(Visibility::SHOW_SELF);
collider->vel = vel;
timer = 2.0f;
switch (type) {
case ProjectileType::BOSS_HOMING:
transform->color = glm::vec3(0.0f, 1.0f, 0.5f);
case ProjectileType::BOSS_CANNON:
transform->setScale(glm::vec3(5.0f));
collider->setExtents(glm::vec3(-2.5f), glm::vec3(2.5f));
timer = 4.0f;
case ProjectileType::ROCKET:
collider->gravityMultiplier = 0.0f;
break;
case ProjectileType::LASER:
collider->gravityMultiplier = 1.0f;
break;
default:
break;
}
}
void Projectile::update(GLfloat delta) {
timer -= delta;
if (timer <= 0.0f) {
onDeath();
return;
}
switch (type) {
case ProjectileType::ROCKET:
EntityManagerInstance->SpawnParticle(FIRE, transform->getWorldPos(), glm::vec3(0.0f), 3.0f);
break;
case ProjectileType::LASER:
for (int i = 0; i < 2; ++i) {
EntityManagerInstance->SpawnParticle(BEAM, transform->getWorldPos(), Mth::randInsideUnitCube(), 10.0f);
}
break;
case ProjectileType::BOSS_CANNON:
for (int i = 0; i < 1; ++i) {
EntityManagerInstance->SpawnParticle(BEAM, transform->getWorldPos(), glm::vec3(0.0f), 10.0f, glm::vec3(5.0f), false);
}
break;
case ProjectileType::BOSS_HOMING: {
glm::vec3 dir = EntityManagerInstance->getPlayerPosition() - transform->getWorldPos();
if (dir != glm::vec3(0.0f)) {
dir = glm::normalize(dir);
}
collider->vel = glm::normalize(collider->vel + dir*4.0f)*100.0f;
for (int i = 0; i < 1; ++i) {
EntityManagerInstance->SpawnParticle(BEAM_HOMING, transform->getWorldPos(), glm::vec3(0.0f), 10.0f, glm::vec3(5.0f), false);
}
}break;
default:
break;
}
}
void Projectile::onDeath() {
if (collider->tag == Tag::PLAYER_PROJECTILE) {
EntityManagerInstance->MakeExplosion(transform->getWorldPos(), 100, 16.0f, collider->vel);
glm::vec3 p = transform->getWorldPos();
glm::vec3 s = glm::vec3(20.0f) / 2.0f;
Physics::sendOverlapEvent(AABB(p - s, p + s), Tag::EXPLOSION, nullptr);
}
if (type == ProjectileType::BOSS_CANNON) {
for (int i = 0; i < 50; ++i) {
EntityManagerInstance->SpawnParticle(BEAM, transform->getWorldPos(), glm::vec3(0.0f), 100.0f, glm::vec3(8.0f), false);
}
}
if (type == ProjectileType::BOSS_HOMING) {
for (int i = 0; i < 50; ++i) {
EntityManagerInstance->SpawnParticle(BEAM_HOMING, transform->getWorldPos(), glm::vec3(0.0f), 100.0f, glm::vec3(8.0f), false);
}
}
EntityManagerInstance->ReturnProjectile(this);
}
void Projectile::onCollision(Tag tag, Entity* other) {
if ((tag == Tag::PLAYER && collider->tag != Tag::PLAYER_PROJECTILE) ||
(tag == Tag::ENEMY && collider->tag != Tag::ENEMY_PROJECTILE) ||
tag == Tag::BOSSBOY) {
timer = -1.0f;
}
}