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
| void animation(SDL_Surface *ecran)
{
SDL_Surface *robot=NULL,*mur=NULL;
robot=SDL_LoadBMP("robot aspi.bmp");
mur=SDL_LoadBMP("rocher.bmp");
SDL_Rect position ,position2;
position.x=0;
position.y=0;
int continu=1;
int direction[4]={2,3,1,0};
int tab[4]={0};
int taille=4;
int *contacteZone=&tab[0];
int i=0,j=0,m,n;
int carte[NB_BLOC_LARGEUR][NB_BLOC_LONGEUR]={0};
SDL_Event event;
if (!chargerNiveau(carte))
{
exit(EXIT_FAILURE);
}
while (continu)
{
deplacerROBOT(direction[j],&position,&position2,tab);
for (i=0;i<taille;i++)
{
if (tab[i]==1)
{
tab[i]=0;
j++;
}
}
SDL_PollEvent(&event);
switch (event.type)
{
case SDL_QUIT:
continu=0;
break;
}
SDL_FillRect(ecran,NULL,SDL_MapRGB((*ecran).format,255,255,255));
SDL_BlitSurface(robot,NULL,ecran,&position);
for (m=0;m<NB_BLOC_LARGEUR;m++)
{
for (n=0;n<NB_BLOC_LONGEUR;n++)
{
position2.x=m * TAILLE_BLOC;
position2.y=n * TAILLE_BLOC;
switch (carte[m][n])
{
case ROCHER:
SDL_BlitSurface(mur,NULL,ecran,&position2);
break;
}
}
}
SDL_Flip(ecran);
}
SDL_FreeSurface(robot);
SDL_FreeSurface(mur);
}
void deplacerROBOT(int direction,SDL_Rect *position,SDL_Rect *position2,int *contacteZone)
{
switch (direction)
{
case HAUT:
if ((*position).y<0)
{
contacteZone[0]=1;
}
(*position).y--;
break;
case BAS:
if ((*position).y+50>=LARGEUR_FENETRE)
{
contacteZone[1]=1;
}
(*position).y++;
break;
case DROIT:
if ((*position).x+50>=LONGEUR_FENETRE )
{
contacteZone[2]=1;
}
(*position).x++;
break;
case GAUCHE:
if ((*position).x<0)
{
contacteZone[3]=1;
}
(*position).x--;
break;
}
} |
Partager