1 #include "fx_moving_text.h"
2 #include "resources.h"
3 #include "snoutlib/timer.h"
4 #include "snoutlib/mfont.h"
5 #include "snoutlib/misc.h"
6
FX_Moving_Text(const string & text,const vec2 & startpos,const vec2 & dir,const vec2 & speed)7 FX_Moving_Text::FX_Moving_Text(const string &text, const vec2& startpos, const vec2& dir, const vec2& speed) :
8 m_text(text),m_startpos(startpos),m_dir(dir),m_speed(speed),m_pos(m_startpos)
9 {
10 m_start_time = g_timer->now();
11 m_duration = 1.3;
12 m_textsize = 0.5;
13 m_textcolor = vec4(0,1,0,0);
14 m_running = true;
15 }
16
~FX_Moving_Text()17 FX_Moving_Text::~FX_Moving_Text()
18 {}
19
update(void)20 void FX_Moving_Text::update(void)
21 {
22 if (!m_running) return;
23
24 float fx_time = g_timer->now() - m_start_time;
25
26 if (fx_time > m_duration) {
27 m_running = false;
28 return;
29 }
30
31 m_pos = m_startpos + (normalized(m_dir) * m_speed * fx_time);
32 m_textcolor[3] = fade_out(0.3,m_duration,fx_time);
33 }
34
draw(void)35 void FX_Moving_Text::draw(void)
36 {
37 if (!m_running) return;
38
39 g_resources.font->print_text_with_shadow(m_text.c_str(),m_pos, m_textsize, false, m_textcolor);
40 }
41
finished(void)42 bool FX_Moving_Text::finished(void) { return !m_running; }
running(void)43 bool FX_Moving_Text::running(void) { return m_running; }
44