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 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| #include <stdio.h>
#include <cstdlib>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "main.h"
void animationRobot(int direction,int *contacteZone,SDL_Rect *position,int *n);
void animation(SDL_Surface *ecran);
int main(int argc,char *argv[])
{
int continu=1;
SDL_Init(SDL_INIT_VIDEO);
SDL_Event event;
SDL_Rect position;
position.x=0;
position.y=0;
SDL_Surface *ecran=NULL,*menu=NULL;
ecran=SDL_SetVideoMode(LONGEUR_FENETRE,LARGEUR_FENETRE,32,SDL_HWSURFACE);
menu=SDL_LoadBMP("menu.BMP");
while (continu)
{
SDL_WaitEvent(&event);
switch (event.type)
{
case SDL_QUIT:
continu=0;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_1:
animation(ecran);
break;
}
}
SDL_FillRect(ecran,NULL,SDL_MapRGB((*ecran).format,255,255,255));
SDL_BlitSurface(menu,NULL,ecran,&position);
SDL_Flip(ecran);
}
SDL_FreeSurface(menu);
}
void animation(SDL_Surface *ecran)
{
int continu=1,j=0,i=0,m=0,*n=NULL;
n=&m;
int direction[4]={2,3,1,0};
int tab[4]={0};
int *contacteZone=NULL;
contacteZone=&tab[0];
SDL_Surface *robot[4]={NULL},*RobotActuelle=NULL;
RobotActuelle=robot[DROIT];
SDL_Event event;
SDL_Rect position;
position.x=0;
position.y=0;
robot[DROIT]=SDL_LoadBMP("robotD.BMP");
robot[BAS]=SDL_LoadBMP("robotB.BMP");
robot[GAUCHE]=SDL_LoadBMP("robotG.BMP");
robot[HAUT]=SDL_LoadBMP("robotH.BMP");
while (continu)
{
SDL_PollEvent;
animationRobot(direction[j],tab,&position,n);
for (i=0;i<4;i++)
{
if (tab[i]==1)
{
tab[i]=0;
j++;
}
}
RobotActuelle=robot[m];
SDL_FillRect(ecran,NULL,SDL_MapRGB((*ecran).format,255,255,255));
SDL_BlitSurface(RobotActuelle,NULL,ecran,&position);
SDL_Flip(ecran);
}
SDL_FreeSurface(RobotActuelle);
for (m = 0 ; i < 4 ; m++)
{
SDL_FreeSurface(robot[m]);
}
}
void animationRobot(int direction,int *contacteZone,SDL_Rect *position,int *n)
{
int i;
for (i=0;i<4;i++)
{
switch (direction)
{
case HAUT:
if ((*position).y<0)
{
contacteZone[0]=1;
}
else (*position).y--;
*n=3;
break;
case BAS:
if ((*position).y+50>=LARGEUR_FENETRE)
{
contacteZone[1]=1;
}
else (*position).y++;
*n=1;
break;
case DROIT:
if ((*position).x+50>=LONGEUR_FENETRE)
{
contacteZone[2]=1;
}
else (*position).x++;
*n=0;
break;
case GAUCHE:
if ((*position).x<0)
{
contacteZone[3]=1;
}
else (*position).x--;
*n=2;
break;
}
}
} |