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
|
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
int main(int argc, char *argv[])
{
// declaration de la surface
SDL_Surface *palet = NULL;
int done = 0;
SDL_Event event;
SDL_Surface *ecran = NULL;
SDL_Rect position;
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK);
SDL_WM_SetIcon(SDL_LoadBMP("images/sdl_icone.bmp"), NULL);
ecran = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
// mise en mémoire de la surface
palet = SDL_CreateRGBSurface(SDL_HWSURFACE, 100, 20, 32, 0, 0, 0, 0);
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
// couleur du palet
SDL_FillRect(palet, NULL, SDL_MapRGB(ecran->format, 255, 255, 255));
position.x = 250;
position.y = 450;
SDL_BlitSurface(palet, NULL, ecran, &position);
if (ecran == NULL)
{
fprintf(stderr, "impossible de charger le mode vidéo : %s\nq", SDL_GetError());
exit(EXIT_FAILURE);
}
SDL_WM_SetCaption("Casse Brique", NULL);
while (!done)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
done = 1;
break;
case SDL_KEYUP:
if(event.key.keysym.sym == SDLK_ESCAPE)
{
done = 1;
}
break;
case SDL_KEYDOWN:
if(event.key.keysym.sym == SDLK_f)
{
position.x = position.x + 5;
SDL_BlitSurface(palet, NULL, ecran, &position);
SDL_Flip(palet);
}
break;
default:
break;
}
}
}
SDL_FreeSurface(palet);
SDL_Quit();
return EXIT_SUCCESS;
} |
Partager