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
| #include <stdlib.h>
#include <stdio.h>
#include <sdl/SDL.h>
#include <time.h>
void pause();
int main(int argc, char *argv[])
{
int i;
SDL_Surface *ecran = NULL, *image = NULL;
SDL_Rect position;
SDL_Init(SDL_INIT_VIDEO); // Initialisation de la SDL
ecran = SDL_SetVideoMode(800, 480, 32, SDL_HWSURFACE); // Ouverture de la fenêtre
SDL_WM_SetCaption("Ma fenetre SDL", NULL);
// Coloration de la surface ecran en bleu-vert
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 17, 206, 112));
srand(time(NULL));
i = (rand()%6);
position.x = 0;
position.y = 0;
/* Chargement d'une image Bitmap dans une surface */
switch(i)
{
case 1:
printf("omg");
image = SDL_LoadBMP("jeton1.bmp"); //ok
position.x = 0;
position.y = 0;
break;
case 2:
image = SDL_LoadBMP("jeton5.bmp"); //ok
position.x = 0;
position.y = 0;
break;
case 3:
image = SDL_LoadBMP("jeton10.bmp"); //ok
position.x = 0;
position.y = 0;
break;
case 4:
image = SDL_LoadBMP("jeton20.bmp"); //ok
position.x = 0;
position.y = 0;
break;
case 5:
image = SDL_LoadBMP("jeton100.bmp"); //ok
position.x = 0;
position.y = 0;
break;
}
SDL_SetColorKey(image, SDL_SRCCOLORKEY, SDL_MapRGB(image->format, 255, 0, 255));
SDL_BlitSurface(image, NULL, ecran, &position); // Collage de la surface sur l'écran
SDL_Flip(ecran); /* Mise à jour de l'écran avec sa nouvelle couleur */
pause(); // Mise en pause du programme
SDL_FreeSurface(image); // Libération de la surface
SDL_Quit(); // Arrêt de la SDL
return EXIT_SUCCESS; // Fermeture du programme
}
void pause()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
} |
Partager