X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=car.c;h=9caf3bd8206e098a8a4b9f0b6da12ecd6e5fd9a4;hp=3c9be9bfcb1fe1b27ce2e7b2f864bbff2079af4f;hb=HEAD;hpb=ee6ec6d95d78f74973a2ba97077cc94709bb6c61 diff --git a/car.c b/car.c index 3c9be9b..9caf3bd 100644 --- a/car.c +++ b/car.c @@ -4,20 +4,18 @@ void move_car(struct _car *car,int keys,SDL_Surface *fun) { - Uint32 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>>RSHIFT)&0xff; /* green layer (road quality) */ - g=(c>>GSHIFT)&0xff; /* blue layer (grip) */ - b=(c>>BSHIFT)&0xff; + SDL_GetRGB(c,fun->format,&r,&g,&b); if (keys & 8) /* up */ car->speed+=0.01*2*COEFF; @@ -69,8 +67,17 @@ void move_car(struct _car *car,int keys,SDL_Surface *fun) 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) { @@ -80,5 +87,24 @@ void move_car(struct _car *car,int keys,SDL_Surface *fun) 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; }