-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplash.cpp
141 lines (115 loc) · 3.44 KB
/
Splash.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*******************************************************************************
CommanderTux
Penguin In Space
Released under the GNU Public License
2005 by Andr� Schnabel ([email protected])
*******************************************************************************/
// Splash.cpp
#include "Splash.h"
//
// CSplash
// Constructor
//
CSplash::CSplash() : CState()
{
DEBUG( "Setting up the splashscreen..." );
// Set maximal framerate per second
m_max_fps = 80;
// Load splash surface
m_splash_surf = g_framework->LoadImage( splash_filenames[SPL_SPLASH] );
#ifndef NO_SOUND
// Load splash sound and play it
m_splash_sound = Mix_LoadWAV( splash_filenames[SPL_SOUND] );
Mix_PlayChannel( -1, m_splash_sound, 0 );
#endif
int m_splash_surf_w = g_framework->GetTextureWidth(m_splash_surf);
int m_splash_surf_h = g_framework->GetTextureHeight(m_splash_surf);
// Init splash surface rectangle for fade in
m_splash_rect.w = m_splash_surf_w;
m_splash_rect.h = m_splash_surf_h;
m_splash_rect.x = 0;
m_splash_surf_roll = -m_splash_surf_h;
// Init var for fading
m_splash_surf_fade = 0;
// Load version surface based upon text drawed on surface by the framework
m_version_surf = g_framework->DrawTextOnSurface( VERSION_C, g_framework->GetColorSDLColor( COLOR_GREEN ),F_SIZE_MEDIUM );
DEBUG( "Splashscreen is working!" );
}
//
// CSplash
// Destructor
//
CSplash::~CSplash()
{
DEBUG( "Shutting down the splashscreen..." );
#ifndef NO_SOUND
// Delete splash sound
Mix_FreeChunk( m_splash_sound );
#endif
// Free version surface
SDL_DestroyTexture( m_version_surf );
// Free splash surface
SDL_DestroyTexture( m_splash_surf );
DEBUG( "Splashscreen is shutdown!" );
}
//
// Input
// Splash specific input processing.
//
void CSplash::Input()
{
// Standard state input
CState::Input();
// Get to the game state when esc or return is pressed
// Check wheter escape was released because you will jump in here
// when you exit the editor or duel mode
if( m_keys[SDL_SCANCODE_ESCAPE] )
{
if( m_released.key_escape )
{
m_released.key_escape = false;
m_done = true;
}
}
else
m_released.key_escape = true;
if( m_keys[SDL_SCANCODE_RETURN] )
m_done = true;
}
//
// Update
// Splash specific update function.
//
void CSplash::Update()
{
// Fade if neccessary
if( m_splash_surf_fade < SDL_ALPHA_OPAQUE - FADE_SPEED )
m_splash_surf_fade += FADE_SPEED;
if( m_splash_surf_roll < 0 )
{
m_splash_surf_roll += ROLL_SPEED;
m_splash_rect.y = m_splash_surf_roll;
}
}
//
// Draw
// Splash specific drawing stuff.
//
void CSplash::Draw()
{
// Because this is too slow in fullscreen
// don't fade...
if( !g_framework->GetSetup()->fullscreen )
{
g_framework->FillRect( g_framework->GetScreen(),
NULL, COLOR_BLACK );
g_framework->SetAlpha( m_splash_surf, m_splash_surf_fade );
// We want to draw outside the screen so we can't use any
// drawing function of the framework
SDL_RenderCopy(g_framework->GetRenderer(), m_splash_surf, nullptr, &m_splash_rect );
}
else
g_framework->Draw( m_splash_surf );
// Draw version
g_framework->Draw( m_version_surf, 10, SCR_H - 20 );
}