-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathText.cpp
98 lines (85 loc) · 2.35 KB
/
Text.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
/*******************************************************************************
CommanderTux
Penguin In Space
Released under the GNU Public License
2005 by André Schnabel ([email protected])
*******************************************************************************/
// Text.cpp
#include "Text.h"
//
// CFlyingText
// Constructor
//
CFlyingText::CFlyingText( const char *text,
int s_pos_x, int s_pos_y,
Direction dir, Uint32 duration,
Color color )
{
// Copy func parameters to member vars
m_dir = dir;
m_duration = duration;
m_rect.x = s_pos_x;
m_rect.y = s_pos_y;
// Create surface
m_surface = g_framework->DrawTextOnSurface( text,
g_framework->GetColorSDLColor( color ),
F_SIZE_MEDIUM );
m_rect.w = g_framework->GetTextureWidth(m_surface);
m_rect.h = g_framework->GetTextureHeight(m_surface);
// Init start time
m_start = g_framework->GetTicks();
}
//
// ~CFlyingText
// Destructor
//
CFlyingText::~CFlyingText()
{
// Free surface
SDL_DestroyTexture( m_surface );
}
//
// Update
// Returns whether still alive
//
bool CFlyingText::Update( int *scroll_x, int *scroll_y )
{
// Is time not exceeded?
if( g_framework->GetTicks() - m_start < m_duration )
{
// Only draw when still in the screen
if( m_rect.y - *scroll_y - FLYING_SPEED > 0 &&
m_rect.y - *scroll_y + m_rect.h < SCR_H &&
m_rect.x - *scroll_x > 0 &&
m_rect.x - *scroll_x + m_rect.w < SCR_W )
{
switch( m_dir )
{
case DIR_LEFT:
m_rect.x-=FLYING_SPEED;
break;
case DIR_RIGHT:
m_rect.x+=FLYING_SPEED;
break;
case DIR_UP:
m_rect.y-=FLYING_SPEED;
break;
case DIR_DOWN:
m_rect.y+=FLYING_SPEED;
break;
}
return true;
}
else // Otherwise kill it
return false;
}
else
return false;
}
//
// Draw
//
void CFlyingText::Draw( int *scroll_x, int *scroll_y )
{
g_framework->Draw( m_surface, m_rect.x - *scroll_x, m_rect.y - *scroll_y );
}