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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| #include <SDL/SDL.h>
int main(int argc ,char **argv)
{
SDL_Surface *screen;
SDL_Surface *fond;
SDL_Surface *balle;
SDL_Surface *balle2;
SDL_Event event;
int continuer = 1,aller=0;
SDL_Init(SDL_INIT_VIDEO);
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf(stderr, "Erreur lors de l'initialisation de la SDL : %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_WM_SetCaption("Toujours des tests...",NULL);
screen = SDL_SetVideoMode(600, 300, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
if(screen==NULL)
{
fprintf(stderr, "Erreur lors de la creation de la surface screen : %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Rect posfond;
fond=SDL_LoadBMP("image.bmp");
if(fond==NULL)
{
fprintf(stderr,"Erreur dans le chargement de image.bmp\n");
return EXIT_FAILURE;
}
posfond.x=0;
posfond.y=0;
posfond.w=fond->w;
posfond.h=fond->h;
SDL_BlitSurface(fond,NULL,screen,&posfond);
SDL_Flip(screen);
SDL_ShowCursor(0);
balle=SDL_LoadBMP("balle.bmp");
if(balle==NULL)
{
fprintf(stderr,"Erreur dans le chargement de image.bmp\n");
return EXIT_FAILURE;
}
SDL_Rect posbal;
posbal.x=0;
posbal.y=100;
SDL_SetColorKey(balle,SDL_SRCCOLORKEY,SDL_MapRGB(balle->format,255,0,255));
balle2=balle;
SDL_Rect posbal2;
posbal2.x=100;
posbal2.y=200;
SDL_SetColorKey(balle2,SDL_SRCCOLORKEY,SDL_MapRGB(balle2->format,255,0,255));
SDL_BlitSurface(balle2,&posfond,screen,&posbal2);
SDL_Flip(screen);
SDL_Rect depposbal2; //je crois pas que ce soit ca
depposbal2.x=500;
depposbal2.y=0;
while (continuer)
{
SDL_PollEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
continuer = 0;
break;
default:
break;
}
break;
}
posbal.x+=aller;
posfond.x+=aller;
if (posbal.x<10) aller=1;
if (posbal.x>400) aller=-1;
/*On veut que la balle 2 soit toujours au meme endroit par
rapport au fond...*/
posbal2.x = posfond.x+depposbal2.x;
posbal2.y = depposbal2.y;
/*On met l'ecran en noir*/
SDL_FillRect(screen,NULL,0);
/*On dessine le fond*/
SDL_BlitSurface(fond,&posfond,screen,NULL);
SDL_BlitSurface(balle2,NULL,screen,&posbal2);
SDL_BlitSurface(balle,NULL,screen,&posbal);
SDL_Flip(screen);
}
SDL_ShowCursor(1); // reactive la souris
SDL_FreeSurface(fond); //on efface tout
SDL_FreeSurface(balle);// "
SDL_FreeSurface(balle2);// "
SDL_Quit(); // quitte SDL
return EXIT_SUCCESS; // quitte le programme
} |
Partager