-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetinitial.cpp
More file actions
168 lines (149 loc) · 4.25 KB
/
Copy pathsetinitial.cpp
File metadata and controls
168 lines (149 loc) · 4.25 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <SDL_mixer.h>
#include "setinitial.hpp"
#include "getinput.hpp"
extern LTexture Inputtexture;
extern LTexture Outputtexture;
extern LTexture Scoretexture;
extern Mix_Music *gMusic;
extern Mix_Chunk *wrong;
extern Mix_Chunk *rightanswer;
extern Mix_Chunk *click;
extern SDL_Window* gWindow;
extern SDL_Renderer* gRenderer;
extern TTF_Font *gFont;
extern const int SCREEN_WIDTH = 1024;
extern const int SCREEN_HEIGHT = 768;
bool init()
{
bool success = true;
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
}
gWindow = SDL_CreateWindow( "HarryPotter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
int imgFlags2 = IMG_INIT_JPG;
if( !( IMG_Init( imgFlags2 ) & imgFlags2 ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
success = false;
}
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 )
{
printf( "SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
}
}
}
return success;
}
bool loadMedia()
{
bool success = true;
gFont = TTF_OpenFont( "resource/lazy.ttf", 44 );
if( gFont == NULL )
{
printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Render the prompt
SDL_Color textColor = { 0xFF, 0xFF, 0xFF, 0xFF };
if( !Inputtexture.loadFromRenderedText( "V:", textColor ) )
{
printf( "Failed to render prompt text!\n" );
success = false;
}
if( !Outputtexture.loadFromRenderedText( "V:", textColor ) )
{
printf( "Failed to render prompt text!\n" );
success = false;
}
if( !Scoretexture.loadFromRenderedText( "00000000", textColor ) )
{
printf( "Failed to render prompt text!\n" );
success = false;
}
gMusic = Mix_LoadMUS( "resource/bgmusic.mp3" );
if( gMusic == NULL )
{
printf( "Failed to load beat music! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
rightanswer = Mix_LoadWAV( "resource/right.wav" );
if( rightanswer == NULL )
{
printf( "Failed to load right sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
wrong = Mix_LoadWAV( "resource/wrong.wav" );
if( wrong == NULL )
{
printf( "Failed to load wrong sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
click = Mix_LoadWAV( "resource/click.wav" );
if( click == NULL )
{
printf( "Failed to load wrong sound effect! SDL_mixer Error: %s\n", Mix_GetError() );
success = false;
}
}
return success;
}
void close()
{
Mix_FreeMusic( gMusic );
gMusic = NULL;
TTF_CloseFont( gFont );
gFont = NULL;
SDL_DestroyRenderer( gRenderer );
SDL_DestroyWindow( gWindow );
gWindow = NULL;
gRenderer = NULL;
TTF_Quit();
IMG_Quit();
SDL_Quit();
Mix_Quit();
}