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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
int main(int argc, char *argv[])
{
SDL_Surface *ecran,*map,*perso;
SDL_Rect posmap,morceau,posperso;
SDL_Event event;
int continuer = 1;
SDL_Init(SDL_INIT_VIDEO);
ecran = SDL_SetVideoMode(400, 400, 32, SDL_HWSURFACE);
perso=SDL_LoadBMP("perso.bmp");
map=SDL_LoadBMP("5.bmp");
posmap.x=0;
posmap.y=0;
posperso.x=150;
posperso.y=150;
morceau.h=400;
morceau.w=400;
SDL_BlitSurface(map, &morceau, ecran, &posmap);
SDL_BlitSurface(perso, NULL, ecran, &posperso);
SDL_Flip(ecran);
SDL_EnableKeyRepeat(10, 10);
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_RIGHT: // Flèche droite
posperso.x++;
break;
case SDLK_LEFT: // Flèche gauche
posperso.x--;
break;
}
break;
}
morceau.x=posperso.x-150;
morceau.y=0;
if(morceau.x<0) morceau.x=0;
SDL_BlitSurface(map, &morceau, ecran, &posmap);
SDL_BlitSurface(perso, NULL, ecran, &posperso);
SDL_Flip(ecran);
}
SDL_FreeSurface(map);
SDL_FreeSurface(perso);
SDL_Quit();
return EXIT_SUCCESS; |
Partager