-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissile.cpp
More file actions
58 lines (50 loc) · 1.58 KB
/
missile.cpp
File metadata and controls
58 lines (50 loc) · 1.58 KB
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
#pragma once
#include "missile.h"
#include "collision.h"
#include <iostream>
namespace game {
Missile::Missile(const glm::vec3& position, GLuint texture, GLint num_elements, double spawntime, GLuint explo)
: GameObject(position, texture, num_elements, true, 0.1) {
initial_pos_ = position;
current_t_ = 0.0;
last_t_ = 0.0;
name_ = missile;
dead_ = false;
spawn_t_ = spawntime;
explosion_ = explo;
exploded_ = false;
}
void Missile::Update(double delta_time) {
// Call the parent's update method to move the object in standard way, if desired
if (!exploded_) {
double radians = ((2 * 3.1415926536 / 360) * (rotation_ + 90));
velocity_[0] = cos(radians) * MISSILE_SPEED * current_t_;
velocity_[1] = sin(radians) * MISSILE_SPEED * current_t_;
GameObject::Update(delta_time);
// Update current and previous time
last_t_ = current_t_;
current_t_ += delta_time;
}
}
bool Missile::ValidCollision(GameObject* other_game_object, double deltatime) {
switch (other_game_object->GetName()) {
case enemy:
//return Collision::RayCircleCollision(other_game_object, initial_pos_, velocity_, last_t_, current_t_);
return Collision::CircleCircleCollision(other_game_object, position_, radius_);
break;
}
}
bool Missile::HandleCollision(GameObject* other_game_object, double deltatime) {
collidable_ = false;
texture_ = explosion_;
exploded_ = true;
return true;
}
void Missile::CheckLife(double delta_time)
{
if (delta_time - spawn_t_ >= 2.0f)
{
dead_ = true;
}
}
} // namespace game