-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullet.cpp
More file actions
52 lines (41 loc) · 1.26 KB
/
bullet.cpp
File metadata and controls
52 lines (41 loc) · 1.26 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
#include "bullet.h"
#include "collision.h"
#include <iostream>
namespace game {
Bullet::Bullet(const glm::vec3& position, GLuint texture, GLint num_elements,Name firer, double spawnTime)
: GameObject(position, texture, num_elements, true, 0.5) {
initial_pos_ = position;
current_t_ = 0.0;
last_t_ = 0.0;
firer_ = firer;
name_ = bullet;
dead_ = false;
spawn_t_ = spawnTime;
}
void Bullet::Update(double delta_time) {
// Call the parent's update method to move the object in standard way, if desired
double radians = ((2 * 3.1415926536 / 360) * (rotation_ + 90));
velocity_[0] = cos(radians) * BULLET_SPEED;
velocity_[1] = sin(radians) * BULLET_SPEED;
GameObject::Update(delta_time);
// Update current and previous time
last_t_ = current_t_;
current_t_ += delta_time;
}
bool Bullet::ValidCollision(GameObject* other_game_object, double deltatime) {
switch (other_game_object->GetName()) {
default:
return Collision::RayCircleCollision(other_game_object, initial_pos_, velocity_, last_t_, current_t_);
}
}
bool Bullet::HandleCollision(GameObject* other_game_object, double deltatime) {
return true;
}
void Bullet::CheckLife(double delta_time)
{
if (delta_time - spawn_t_ >= 2.0f)
{
dead_ = true;
}
}
} // namespace game