X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=car.c;h=9caf3bd8206e098a8a4b9f0b6da12ecd6e5fd9a4;hp=e7695679378fdea163073f0450659411494c28ff;hb=master;hpb=dde2df6289f6daf23ee1632560c4c89061ef2f4a diff --git a/car.c b/car.c index e769567..9caf3bd 100644 --- a/car.c +++ b/car.c @@ -4,20 +4,18 @@ 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; @@ -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; }