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
| void anim() {
int continuer=1;
Uint32 tempsActuel=0, tempsPrecedent=0;
SDL_Event event;
while(continuer) {
tempsActuel=SDL_GetTicks();
if(tempsActuel-tempsPrecedent>=17)
{
printf("Delay : %d\n", tempsActuel-tempsPrecedent);
SDL_Flip(ecran);
tempsPrecedent=tempsActuel;
SDL_PollEvent(&event);
switch(event.type) {
case SDL_QUIT:
continuer=0;
break;
case SDL_KEYDOWN:
continuer=0;
break;
}
SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
int i=0, x=0, y=0;
for(i=0; i<NB_STARS; i++) {
x=stars1[i][0];
y=stars1[i][1];
x+=STEP1;
if(x>=WIDTH) {
x=0;
//y=(int)((double)rand()/(double)RAND_MAX*(HEIGHT-1));
}
//if(x>=0&&y>=0&&x<WIDTH&&y<HEIGHT) {
stars1[i][0]=x;
//stars1[i][1]=y;
//}
*((Uint32*)(ecran->pixels)+x+(y*ecran->w))=SDL_MapRGB(ecran->format, RGB1, RGB1, RGB1);
}
for(i=0; i<NB_STARS; i++) {
x=stars2[i][0];
y=stars2[i][1];
x+=STEP2;
if(x>=WIDTH) {
x=0;
//y=(int)((double)rand()/(double)RAND_MAX*(HEIGHT-1));
}
//if(x>=0&&y>=0&&x<WIDTH&&y<HEIGHT) {
stars2[i][0]=x;
//stars2[i][1]=y;
//}
*((Uint32*)(ecran->pixels)+x+(y*ecran->w))=SDL_MapRGB(ecran->format, RGB2, RGB2, RGB2);
}
for(i=0; i<NB_STARS; i++) {
x=stars3[i][0];
y=stars3[i][1];
x+=STEP3;
if(x>=WIDTH) {
x=0;
//y=(int)((double)rand()/(double)RAND_MAX*(HEIGHT-1));
}
//if(x>=0&&y>=0&&x<WIDTH&&y<HEIGHT) {
stars3[i][0]=x;
//stars3[i][1]=y;
//}
*((Uint32*)(ecran->pixels)+x+(y*ecran->w))=SDL_MapRGB(ecran->format, RGB3, RGB3, RGB3);
}
}
}
} |
Partager