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
|
#ifdef __cplusplus
#include <cstdlib>
#else
#include <stdlib.h>
#endif
#include <SDL/SDL.h>
int main ( int argc, char** argv )
{
SDL_Event event;
int conti = 0;
SDL_Surface *boule, *barre, *fond;
SDL_Surface *ecran;
SDL_Rect pos0;
SDL_Rect posBo;
SDL_Rect posBa;
posBa.x = 70;
posBa.y = 460;
posBo.x = 320;
posBo.y = 160;
pos0.x = 0;
pos0.y = 0;
// initialize SDL video
SDL_Init( SDL_INIT_VIDEO );
// create a new window
ecran = SDL_SetVideoMode(800, 600, 16,SDL_HWSURFACE|SDL_DOUBLEBUF);
// load image
fond = SDL_LoadBMP("fond.bmp");
boule = SDL_LoadBMP("boule.bmp");
barre = SDL_LoadBMP("barre.bmp");
SDL_PollEvent(&event);
while (conti == 0)
{
switch (event.type)
{
case SDL_QUIT:
conti = 1;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_DOWN:
posBa.y ++;
break;
case SDLK_UP:
posBa.y --;
break;
} // end switch
}
// clear screen
SDL_FillRect(ecran, 0, SDL_MapRGB(ecran->format, 0, 0, 0));
// draw bitmap
SDL_BlitSurface(fond, NULL, ecran, &pos0);
SDL_BlitSurface(barre, NULL, ecran, &posBa);
SDL_BlitSurface(boule, NULL, ecran, &posBo);
SDL_Flip(ecran);
} // end of principale boucle
// free loaded bitmap
SDL_FreeSurface(boule);
SDL_FreeSurface(barre);
SDL_FreeSurface(fond);
return 0;
} |
Partager