12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
#include <SDL/SDL.h> #include "SDL/SDL_image.h" int x = 100; int y = 100; void MoveBall(); int main (int argc, char *args[]) { SDL_Init(SDL_INIT_EVERYTHING); //initialize SDL_WM_SetCaption("Yay!", NULL); //set caption Uint8 *key; SDL_Event event; while (event.type != SDL_QUIT) { SDL_PollEvent(&event); MoveBall(); } //SDL_FreeSurface(buffer); - ikke nødvendig SDL_Quit(); return 0; } void MoveBall() { Uint8 *key; key = SDL_GetKeyState( NULL); if (key[SDLK_UP]) ++y; else if (key[SDLK_DOWN]) --y; if (key[SDLK_RIGHT]) ++x; else if (key[SDLK_LEFT]) --x; SDL_Rect tmp = {x, y, 40, 40}; SDL_Surface *buffer; buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE); SDL_Surface *ball; ball = IMG_Load("ball.png"); SDL_BlitSurface(ball, NULL, buffer, tmp); SDL_Flip (buffer); SDL_FreeSurface(buffer); SDL_FreeSurface(ball); }
SDL_BlitSurface(ball, NULL, buffer, &tmp);