-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGun.cpp
57 lines (46 loc) · 1.15 KB
/
Gun.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
#include "Gun.h"
#include <random>
#include <ctime>
#include <glm\gtx\rotate_vector.hpp>
Gun::Gun(std::string name,
int fireRate,
int bulletPerShot,
float spread,
float bulletDamage,
float bulletSpeed,
NeroEngine::SoundEffect fireEffect)
:_name(name),
_fireRate(fireRate),
_bulletPerShot(bulletPerShot),
_spread(spread),
_buletDamage(bulletDamage),
_bulletSpeed(bulletSpeed),
_frameCounter(0),
_fireEffect(fireEffect)
{
}
void Gun::update(bool isMouseDown,
const glm::vec2& position,
const glm::vec2& direction,
std::vector<Bullet>& bulltes,
float deltaTime){
_frameCounter += 1.0f*deltaTime;
if (_frameCounter>=_fireRate&&isMouseDown){
_fireEffect.play();
fire(direction,position,bulltes);//ÉäËÀTA
_frameCounter = 0;
}
}
void Gun::fire(const glm::vec2& direction, const glm::vec2& position, std::vector<Bullet>& bulltes){
static std::mt19937 randomEngine(time(nullptr));
std::uniform_real_distribution<float> randRotate(-_spread, _spread);
for (int i = 0; i < _bulletPerShot;i++){
bulltes.emplace_back(position,
glm::rotate(direction,randRotate(randomEngine)),
_buletDamage,
_bulletSpeed);
}
}
Gun::~Gun()
{
}