void move_car(struct _car *car,int keys,SDL_Surface *fun)
{
- int c,r,g,b;
+ Uint32 c;
+ Uint8 r,g,b;
/* reset flags */
- car->lapflag=0;
car->crashflag=0;
/* get the pixel color under the center of car in the function map */
c=getpixel(fun,car->x,car->y);
/* red layer (checkpoints) */
- r=(c )&0xff;
/* green layer (road quality) */
- g=(c>>8 )&0xff;
- /* blue layer (unused) */
- b=(c>>16)&0xff;
+ /* blue layer (grip) */
+ SDL_GetRGB(c,fun->format,&r,&g,&b);
if (keys & 8) /* up */
car->speed+=0.01*2*COEFF;
car->crashflag=1;
}
- /* if we are on the next checkpoint, validate it (no missing allowed) */
- if (r/8==car->lastcheck+1) car->lastcheck++;
+ /* if we are on the next checkpoint, validate it */
+ if (r/8==car->lastcheck+1)
+ {
+ /* If we validate a missed checkpoint */
+ if (car->lapflag==3) car->lapflag=4;
+ car->lastcheck++;
+ }
+
+ /* if we missed a checkpoint */
+ if ((r/8>car->lastcheck+1) && (car->lastcheck!=0)) car->lapflag=3;
+
/* if we validate all and start over, we complete a turn */
if (r/8==0 && car->lastcheck==31)
{
car->lapflag=1;
}
+ /* if we are at the start but not each checkpoint validate, it's an incomplete lap */
+ if (r/8==0 && r!=0 && car->lastcheck!=31 && car->lastcheck>0)
+ {
+ car->lastcheck=0;
+ car->lapflag=2;
+ }
+
+ /* if the car is braking, display red lights */
+ if (keys & 4 && car->speed>0.1) car->lights_brake=1; else car->lights_brake=0;
+
+ /* if the car is going backwards, display white lights */
+ if (car->speed<-0.1) car->lights_backwards=1; else car->lights_backwards=0;
+
+ /* if the car is stopped, then warning */
+ if (car->speed>=-0.1 && car->speed<=0.1)
+ car->lights_warning=1;
+ else
+ car->lights_warning=0;
+
return;
}