#ifdef WIN32 #pragma comment(lib, "SDL.lib") #pragma comment(lib, "SDLmain.lib") #endif #include #include #include #include #include SDL_Surface *screen = NULL; SDL_Surface *image = NULL; SDL_Surface *background = NULL; SDL_Rect redy; SDL_Rect grid; SDL_Joystick *joy = NULL; int x, y; Sint16 xpos, ypos; bool init() { //Initialize all SDL subsystems if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ) { return false; } joy = SDL_JoystickOpen(0); if (SDL_Init (SDL_INIT_VIDEO) < 0) atexit (SDL_Quit); screen = SDL_SetVideoMode (1600, 1200, 16, SDL_SWSURFACE | SDL_FULLSCREEN); SDL_WM_SetCaption ("EVM-3015", NULL); image = SDL_LoadBMP("ship.bmp"); redy.x = 800; redy.y = 600; SDL_EnableKeyRepeat(2, 1); background = SDL_LoadBMP("grid.bmp"); grid.x = 800; grid.y = 600; return true; } void draw () { Uint32 color; color = SDL_MapRGB (screen->format, 0, 0, 0); SDL_FillRect (screen, NULL, color); SDL_BlitSurface(background, NULL, screen, &grid); SDL_BlitSurface(image, NULL, screen, &redy); SDL_Flip (screen); } int main (int argc, char *argv[]) { int done = 0; Uint8 *keys; init(); while (!done) { SDL_Event event; while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: keys = SDL_GetKeyState(NULL); if ( keys[SDLK_ESCAPE] ) { done = 1;} break; case SDL_JOYAXISMOTION: xpos = SDL_JoystickGetAxis(joy, 0); ypos = SDL_JoystickGetAxis(joy, 1); xpos = xpos / 1000; ypos = ypos / 1000; redy.x = redy.x + xpos; redy.y = redy.y + ypos; break; case SDL_QUIT: done = 1; break; default: break; } } draw (); } return 0; }