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
|
class cGame
{
private:
SDL_Event event;
public:
static SDL_Surface * screen;
cGame()
{
SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(640,480,24,SDL_SWSURFACE);
}
cGame(int window_width,int window_height,int window_bpp,bool full_screen = false)
{
SDL_Init(SDL_INIT_EVERYTHING);
if(full_screen == false)
screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_SWSURFACE);
else
screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_FULLSCREEN);
}
~cGame()
{
SDL_Quit();
}
void SetResolution(int window_width,int window_height,int window_bpp)
{
//SDL_Init(SDL_INIT_EVERYTHING);
screen = SDL_SetVideoMode(window_width,window_height,window_bpp,SDL_SWSURFACE);
}
void UpdateScreen()
{
SDL_Flip(screen);
}
void SetCaption(char *caption)
{
SDL_WM_SetCaption(caption,NULL);
}
void SleepMiliSeconds(int miliseconds)
{
SDL_Delay(miliseconds);
}
void SleepSeconds(int seconds)
{
SDL_Delay(seconds * 1000);
}
int HandleEvents()
{
int key=NULL;
if( SDL_PollEvent(&event) )
{
if( event.type == SDL_QUIT )
{
return -99; //QUIT
}
if( event.type == SDL_KEYUP )
{
switch( event.key.keysym.sym )
{
case SDLK_UP : key = -1; return key; break; //UP Arrow
case SDLK_DOWN : key = -2; return key; break; //DOWN Arrow
case SDLK_RIGHT : key = -3; return key; break; //RIGHT Arrow
case SDLK_LEFT : key = -4; return key; break; //LEFT Arrow
case SDLK_RCTRL : key = -5; return key; break; //CTRL
case SDLK_LCTRL : key = -5; return key; break; //CTRL
case SDLK_RALT : key = -6; return key; break; //ALT
case SDLK_LALT : key = -6; return key; break; //ALT
case SDLK_RSHIFT: key = -7; return key; break; //SHIFT
case SDLK_LSHIFT: key = -7; return key; break; //SHIFT
case SDLK_SPACE : key = -8; return key; break; //SPACE
case SDLK_RETURN: key = -9; return key; break; //ENTER
//default : return 0; break; //NO KEY
}
}
if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_UP : key = 1; return key; break; //UP Arrow
case SDLK_DOWN : key = 2; return key; break; //DOWN Arrow
case SDLK_RIGHT : key = 3; return key; break; //RIGHT Arrow
case SDLK_LEFT : key = 4; return key; break; //LEFT Arrow
case SDLK_RCTRL : key = 5; return key; break; //CTRL
case SDLK_LCTRL : key = 5; return key; break; //CTRL
case SDLK_RALT : key = 6; return key; break; //ALT
case SDLK_LALT : key = 6; return key; break; //ALT
case SDLK_RSHIFT: key = 7; return key; break; //SHIFT
case SDLK_LSHIFT: key = 7; return key; break; //SHIFT
case SDLK_SPACE : key = 8; return key; break; //SPACE
case SDLK_RETURN: key = 9; return key; break; //ENTER
//default : return 0; break; //NO KEY
}
}
}
return key;
}
} game;
|