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
|
void c_Fiyus_Abilities::v_FiyusInput(){
//If a key was pressed
if( keys.type == SDL_KEYDOWN )
{
//Adjust the velocity
switch(keys.key.keysym.sym )
{
case SDLK_UP: dYVel += dWalkSpeed; break;
case SDLK_DOWN: dYVel -= dWalkSpeed; break;
case SDLK_LEFT: dXVel += dWalkSpeed; break;
case SDLK_RIGHT: dXVel -= dWalkSpeed; break;
case SDLK_LSHIFT:; break;
}
}
//If a key was released
else if( keys.type == SDL_KEYUP )
{
//Adjust the velocity
switch( keys.key.keysym.sym )
{
case SDLK_UP: dYVel = 0; break;
case SDLK_DOWN: dYVel = 0; break;
case SDLK_LEFT: dXVel = 0; break;
case SDLK_RIGHT: dXVel = 0; break;
case SDLK_LSHIFT:; break;
}
}
int main(int argc, char* args[])
{
SDL_Surface *screen = NULL;
c_Fiyus_Abilities fiyus;
SDL_Event event;
bool quit = false;
SDL_Init(SDL_INIT_EVERYTHING);
//Set up the screen
screen = SDL_SetVideoMode(400, 400, 32,SDL_SWSURFACE);
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
//Set the window caption
SDL_WM_SetCaption( "Project ignition", NULL );
while( quit == false )
{
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
fiyus.v_FiyusInput();
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
fiyus.v_FiyusMove();
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 250,
200, 200 ) );
fiyus.v_FiyusInit(fiyus.v_FiyusGetX(),fiyus.v_FiyusGetY(),screen,"man.bmp");
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}
|