-
Notifications
You must be signed in to change notification settings - Fork 1
/
Laser.cpp
49 lines (41 loc) · 1.04 KB
/
Laser.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
#include "Laser.h"
#include "Game.h"
#include "TextureManager.h"
#include "SoundManager.h"
#include "Utils.h"
namespace typing
{
const std::string Laser::LASER_SOUND("sounds/laser.wav");
const float Laser::LINE_DRAW_TIME = 0.0f;
const float Laser::LINE_FADE_TIME = 0.5f;
const float Laser::LIFETIME = LINE_DRAW_TIME + LINE_FADE_TIME;
void Laser::Init()
{
SOUNDS.Add(LASER_SOUND);
}
void Laser::Draw()
{
float alpha;
if (m_age < LINE_DRAW_TIME) {
alpha = 1.0f;
} else {
alpha = 1.0f - (m_age - LINE_DRAW_TIME) / LINE_FADE_TIME;
}
DrawLine(ColourRGBA(m_col, alpha), m_start, m_end);
glLineWidth(4.0f);
DrawLine(ColourRGBA(m_col, alpha / 2.0f), m_start, m_end);
glLineWidth(1.0f);
}
void Laser::Update()
{
m_age += GAME.GetFrameTime();
}
bool Laser::Unlink()
{
return (m_age >= LIFETIME);
}
void Laser::OnSpawn()
{
SOUNDS.Play(LASER_SOUND);
}
}