-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBulletObject.cpp
More file actions
51 lines (39 loc) · 1.1 KB
/
BulletObject.cpp
File metadata and controls
51 lines (39 loc) · 1.1 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
#include "BulletObject.h"
#include <GL/glfw3.h>
#include "Window.h"
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
/*
BulletObject inherits from GameObject
*/
BulletObject::BulletObject(glm::vec3 &entityPos, GLuint entityTexture, GLint entityNumElements)
: GameObject(entityPos, entityTexture, entityNumElements, true) {
orientation = 0.0f;
speed = 20.0f;
damage = 100.0f;
}
void BulletObject::update(double deltaTime, GameObject* target) {
// calculate orientation
float dx = target->getPosition().x - position.x;
float dy = position.y - target->getPosition().y;
float radians = atan2f(dy, dx);
if (radians < 0) {
radians = abs(radians);
}
else {
radians = 2 * M_PI - radians;
}
float degrees = glm::degrees(radians);
orientation = degrees;
GameObject::update(deltaTime);
}
bool BulletObject::hitsTarget(GameObject* target) {
float dx = position.x - target->getPosition().x;
float dy = position.y - target->getPosition().y;
float distance = sqrt(pow(dx, 2) + pow(dy, 2));
if (distance < (target->getScale() / 3.0f) + (scale / 30.0f)) {
return true;
}
return false;
}