该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include #include #include
int main() {
SDL_Surface *screen = NULL; SDL_Surface *tank = NULL; SDL_Rect tankPosition; SDL_Event event; int wantsToQuit = 0;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE ); SDL_WM_SetCaption("SDL events handling", NULL);
tank = SDL_LoadBMP("tank.bmp"); SDL_SetColorKey( tank, SDL_SRCCOLORKEY, SDL_MapRGB(tank->format, 255, 19, 255) ); tankPosition.x = 0; tankPosition.y = 0;
while (!wantsToQuit) { SDL_WaitEvent(&event); switch(event.type) { case SDL_QUIT: wantsToQuit = 0; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case SDLK_UP: tankPosition.y--; break; case SDLK_DOWN: tankPosition.y++; break; case SDLK_RIGHT: tankPosition.x++; break; case SDLK_LEFT: tankPosition.x--; break; } break; }
// we clean the screen SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 255)); // we draw GMH at the new position SDL_BlitSurface(tank, NULL, screen, &tankPosition); // we update what the user see SDL_Flip(screen); }
SDL_FreeSurface(tank); SDL_Quit();
return EXIT_SUCCESS;}