-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeapon.cpp
More file actions
112 lines (94 loc) · 2.36 KB
/
Copy pathWeapon.cpp
File metadata and controls
112 lines (94 loc) · 2.36 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
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "src/Weapon.h"
namespace physics{
/*--------->BULLET IMPLEMENTATION<-----------*/
Bullet::Bullet() : _active(false)
{
_type = "";
initialize("Circle");
_radius= 0.25f;
}
Bullet::Bullet(Vector3f pos) : _active(false)
{
_type = "";
_position = pos;
initialize("Circle");
_radius = 0.25f;
}
/*--------->WEAPON IMPLEMENTATION<-----------*/
Weapon::Weapon() : _coolDown(4)
{
_reloading = false;
_clip = 0;
_maxClipSize = 64;
_magazine = new Bullet*[_maxClipSize];
for(unsigned int i = 0; i < _maxClipSize; ++i)
{
_magazine[i] = new Bullet();
}
}
//Overloaded constructor to give weapons more ammo
Weapon::Weapon(unsigned int clipSize) : _clip(0), _reloading(false), _coolDown(4)
{
_maxClipSize = clipSize;
_magazine = new Bullet*[_maxClipSize];
for(unsigned int i = 0; i < _maxClipSize; ++i)
{
_magazine[i] = new Bullet();
}
}
unsigned int Weapon::getClip()
{
return _clip;
}
void Weapon::fire(Vector3f pos, Vector3f target, bool npc)
{
if(_coolDown < 5)
{
Bullet* b = new Bullet(pos); //Create a bullet object
if(!npc)
{
_coolDown = 10;
b->_velocity=(target); //Fire it at the target from position
//b->_velocity.normalize();
}
else
{
_coolDown = 25;
b->_velocity=(target-pos);
b->_velocity.normalize();
//b->_velocity = b->_velocity * 0.25f;
}
++_clip; //If emptied clip reset to 0
if(_clip >= _maxClipSize)
{
_clip = 0;
if(npc)
reload();
}
b->_active = true;
_magazine[_clip] = b; //Place the bullet in _magazine i.e. fire away
//Call weapon iterate to update bullet positions
}
}
void Weapon::iterate()
{
if(_coolDown >= 5)
{
--_coolDown;
}
for(unsigned int i = 0; i < _clip ; ++i)
{
if(_magazine[i] != NULL && _magazine[i]->_active)
_magazine[i]->update();
}
}
void Weapon::reload()
{
for(unsigned int i = 0; i < _maxClipSize; ++i)
_magazine[i]->_active = false;
}
Bullet* Weapon::getBullet(unsigned int index)
{
return _magazine[index];
}
}// namespace physics