-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.cpp
74 lines (56 loc) · 1.63 KB
/
bullet.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
/*
* File: bullet.cpp
* Author: gg
*
* Created on 7 de dezembro de 2019, 01:09
*/
#include <GL/freeglut_std.h>
#include "bullet.h"
#include "cube.h"
#include "flyingenemy.h"
#include "player.h"
wf_object_t* bullet_t::sModel = NULL;
bullet_t::bullet_t(const point3f& offset, const vector3f& velocity, bool enemy) :
projectile_t(offset, velocity), enemy(enemy) {
horizontal = atan2(velocity.y, velocity.x);
vertical = atan2(velocity.z, vector3f(velocity.x, velocity.y, 0).length());
}
void bullet_t::draw() const {
const float dr = 180 / M_PI;
glRotatef(horizontal * dr, 0, 0, 1);
glRotatef(-vertical * dr, 0, 1, 0);
//glutSolidSphere(1, 8, 8);
//const vector3f& v = getVelocity();
//glTranslatef(v.x, v.y, v.z);
//glutSolidSphere(1, 8, 8);
glRotatef(90, 1, 0, 0);
glRotatef(-90, 0, 0, 1);
glScalef(radius, radius, radius);
glScalef(10, 10, 10);
drawAxis(1);
if (sModel != NULL) {
sModel->draw();
} else {
drawCube();
}
}
void bullet_t::hit(obstacle_t* other) {
printf("A bullet hit an obstacle\n");
projectile_t::hit(other);
if (enemy) {
if (player_t * p = dynamic_cast<player_t*> (other)) {
printf("The bullet hit the player\n");
p->kill();
}
} else {
if (flying_enemy_t * base = dynamic_cast<flying_enemy_t*> (other)) {
printf("The bullet hit an enemy\n");
base->kill();
}
}
}
void bullet_t::init(wf_object_loader_t& loader) {
sModel = loader.loadRes("duende");
float length = loader.getMostDistantVertex().length();
sModel->scale(1 / length);
}