-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectile.cpp
More file actions
99 lines (78 loc) · 1.74 KB
/
projectile.cpp
File metadata and controls
99 lines (78 loc) · 1.74 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
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
#include "projectile.h"
#include <cstdlib>
Projectile::Projectile()
{
float x_side = rand() % 2;
float y_side = rand() % 2;
GLfloat x,y;
if(x_side == 0)
x = -1.0 + static_cast <GLfloat>(rand()) /( static_cast <GLfloat>(RAND_MAX/(-0.2 - (-1.0))));
else
x = 0.2 + static_cast <GLfloat>(rand()) /( static_cast <GLfloat>(RAND_MAX/(1.0-(0.2))));
if(y_side == 0)
y = -1.0 + static_cast <GLfloat>(rand()) /( static_cast <GLfloat>(RAND_MAX/(-0.2 - (-1.0))));
else
y = 0.2 + static_cast <GLfloat>(rand()) /( static_cast <GLfloat>(RAND_MAX/(1.0-(0.2))));
position.x = x;
position.y = y;
angle = rand()/(RAND_MAX/360);
}
Projectile::Projectile(GLfloat x, GLfloat y)
{
position.x = x;
position.y = y;
}
GLfloat Projectile::get_x() const
{
return position.x;
}
GLfloat Projectile::get_y() const
{
return position.y;
}
glm::vec3 Projectile::get_position() const
{
return position;
}
void Projectile::set_position(glm::vec3 new_position)
{
position = new_position;
}
GLfloat Projectile::get_angle() const
{
return angle;
}
void Projectile::check_position()
{
if(position.x < -1.0)
position.x += 2.0;
else if(position.x > 1.0)
position.x -= 2.0;
if(position.y < -1.0)
position.y += 2.0;
else if(position.y > 1.0)
position.y -= 2.0;
}
void Projectile::move(GLfloat delta)
{
GLfloat radians = glm::radians(angle);
position.x += delta*cos(radians);
position.y += delta*sin(radians);
}
GLboolean Projectile::get_active() const
{
return active;
}
void Projectile::activate()
{
active = GL_TRUE;
}
void Projectile::deactivate()
{
active = GL_FALSE;
}
std::ostream& operator<<(std::ostream& os, const Projectile& position)
{
os << position.get_x() << ", " << position.get_y();
return os;
}