-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.cpp
77 lines (59 loc) · 1.48 KB
/
main.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
/*
<kattMickisShooter>
Bubble Shooter clone for kattMickis
By: Erik Andersson
*/
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "SDL.h"
#include "SDL_image.h"
#include "SDL/SDL_ttf.h"
#include "SDL_mixer.h"
#include "unicode.h"
#include "game.h"
const int SCREEN_WIDTH = 403;
const int SCREEN_HEIGHT = 405;
const int SCREEN_BPP = 32;
extern "C" int main(int argc, char *argv[])
{
// Seed random number generator
srand(time(NULL));
// Init SDL
Uint32 init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO;
Uint32 screen_flags = SDL_HWSURFACE;
if ( SDL_Init(init_flags) < 0 )
{
std::cout << "Error initializing SDL: " << SDL_GetError();
return 1;
}
SDL_EnableUNICODE(1);
if ( TTF_Init() < 0 )
{
std::cout << "Error initializing TTF: " << TTF_GetError();
return 2;
}
int audio_rate = 22050;
Uint16 audio_format = AUDIO_S16SYS;
int audio_channels = 2;
int audio_buffers = 1024;
if ( Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers) != 0 )
{
std::cout << "Error initialize audio: " << Mix_GetError();
return 3;
}
// Enable key repeat
SDL_EnableKeyRepeat(250, 100);
SDL_Surface *screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, screen_flags);
if ( screen == NULL )
{
std::cout << "Error creating screen: " << SDL_GetError();
return 4;
}
SDL_WM_SetCaption("kattMickis Bubble Shooter", NULL);
Game game = Game(screen);
game.setWidth(SCREEN_WIDTH);
game.setHeight(SCREEN_HEIGHT);
game.loop();
return 0;
}