-
Notifications
You must be signed in to change notification settings - Fork 1
/
Award.cpp
112 lines (91 loc) · 3.38 KB
/
Award.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
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 "Award.h"
#include "FontManager.h"
#include "Game.h"
namespace typing
{
const std::string Award::AWARD_FONT("fonts/hudfont.fnt");
const float Award::AWARD_RISE_TIME = 0.2f;
const float Award::AWARD_FADE_TIME = 1.0f;
const float Award::AWARD_DISPLAY_TIME = AWARD_RISE_TIME + AWARD_FADE_TIME;
const float Award::AWARD_FONT_HEIGHT = 24.0f;
const float Award::AWARD_START_ALPHA = 0.0f;
const float Award::AWARD_PEAK_ALPHA = 1.0f;
const float Award::AWARD_END_ALPHA = 0.0f;
const std::string Award::AWARD_EXCELLENT_STRING("EXCELLENT");
const ColourRGB Award::AWARD_EXCELLENT_COLOUR(0.0f, 1.0f, 0.0f);
const std::string Award::AWARD_GOOD_STRING("GOOD");
const ColourRGB Award::AWARD_GOOD_COLOUR(0.0f, 1.0f, 1.0f);
const std::string Award::AWARD_OK_STRING("OK");
const ColourRGB Award::AWARD_OK_COLOUR(0.0f, 0.0f, 1.0f);
const std::string Award::AWARD_POOR_STRING("POOR");
const ColourRGB Award::AWARD_POOR_COLOUR(1.0f, 0.0f, 1.0f);
const std::string Award::AWARD_BAD_STRING("BAD");
const ColourRGB Award::AWARD_BAD_COLOUR(1.0f, 0.0f, 0.0f);
const std::string Award::AWARD_EXTRALIFE_STRING("EXTRA LIFE!");
const ColourRGB Award::AWARD_EXTRALIFE_COLOUR(0.0f, 1.0f, 0.0f);
const std::string Award::AWARD_SHORTEN_PHRASES_STRING("SHORTER PHRASES!");
const ColourRGB Award::AWARD_SHORTEN_PHRASES_COLOUR(0.0f, 1.0f, 0.0f);
void Award::Init()
{
FONTS.Add(AWARD_FONT);
}
bool Award::Unlink()
{
if (GAME.GetTime() - m_startTime > AWARD_DISPLAY_TIME)
{
return true;
}
else
{
return false;
}
}
void Award::Draw()
{
float y = m_origin.GetY() - AWARD_FONT_HEIGHT / 2.0f;
const ColourRGB *col;
const std::string *str;
float lifeTime = GAME.GetTime() - m_startTime;
float alpha = 0.0f;
if (lifeTime < AWARD_RISE_TIME)
{
alpha = (lifeTime / AWARD_RISE_TIME) * (AWARD_PEAK_ALPHA - AWARD_START_ALPHA);
}
else if (lifeTime < AWARD_RISE_TIME + AWARD_FADE_TIME)
{
alpha = ((lifeTime - AWARD_RISE_TIME) / AWARD_FADE_TIME) * (AWARD_PEAK_ALPHA - AWARD_END_ALPHA);
alpha = AWARD_PEAK_ALPHA - alpha;
}
switch (m_type)
{
case AWARD_EXCELLENT:
col = &AWARD_EXCELLENT_COLOUR;
str = &AWARD_EXCELLENT_STRING;
break;
case AWARD_GOOD:
col = &AWARD_GOOD_COLOUR;
str = &AWARD_GOOD_STRING;
break;
case AWARD_OK:
col = &AWARD_OK_COLOUR;
str = &AWARD_OK_STRING;
break;
case AWARD_POOR:
col = &AWARD_POOR_COLOUR;
str = &AWARD_POOR_STRING;
break;
case AWARD_BAD:
col = &AWARD_BAD_COLOUR;
str = &AWARD_BAD_STRING;
break;
case AWARD_EXTRALIFE:
col = &AWARD_EXTRALIFE_COLOUR;
str = &AWARD_EXTRALIFE_STRING;
break;
case AWARD_SHORTEN_PHRASES:
col = &AWARD_SHORTEN_PHRASES_COLOUR;
str = &AWARD_SHORTEN_PHRASES_STRING;
}
FONTS.Print(AWARD_FONT, m_origin.GetX(), y, AWARD_FONT_HEIGHT, ColourRGBA(*col, alpha), Font::ALIGN_CENTER, *str);
}
}