5 void move_car(struct _car *car,int keys,SDL_Surface *fun)
13 /* get the pixel color under the center of car in the function map */
14 c=getpixel(fun,car->x,car->y);
15 /* red layer (checkpoints) */
17 /* green layer (road quality) */
19 /* blue layer (unused) */
22 if (keys & 8) /* up */
23 car->speed+=0.01*2*COEFF;
24 if (keys & 4) /* down */
25 car->speed-=0.01*COEFF;
26 if (keys & 2) /* left */
29 car->angle+=0.01*(255-b)/255*COEFF;
31 car->angle-=0.01*(255-b)/255*COEFF;
33 if (keys & 1) /* right */
36 car->angle-=0.01*(255-b)/255*COEFF;
38 car->angle+=0.01*(255-b)/255*COEFF;
41 /* limit angle between 0 and 2*pi */
42 if (car->angle<0) car->angle+=2*M_PI;
43 if (car->angle>2*M_PI) car->angle-=2*M_PI;
45 /* update the speed depending on the road quality */
46 car->speed-=car->speed*(255-g)/1000;
48 /* if it is a wall we move back to the last position */
56 /* save the old position and compute the new one */
60 car->x-=cos(car->angle)*car->speed;
61 car->y-=sin(car->angle)*car->speed;
63 /* collision with the border of the screen */
64 if (car->x<car->w/2 || car->x>fun->w-car->w/2 || car->y<car->h/2 || car->y>fun->h-car->h/2)
72 /* if we are on the next checkpoint, validate it (no missing allowed) */
73 if (r/8==car->lastcheck+1) car->lastcheck++;
74 /* if we validate all and start over, we complete a turn */
75 if (r/8==0 && car->lastcheck==31)
77 /* reset turn variables */