X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=bot.c;fp=bot.c;h=b9631a9814cbcd2315bb0057d7c47c7f2bef0370;hp=ef93b046ad758ad83889a29f623272b97445a098;hb=1be6de5da72b6218e87c20e29782ce6f9d99196e;hpb=ee6ec6d95d78f74973a2ba97077cc94709bb6c61 diff --git a/bot.c b/bot.c index ef93b04..b9631a9 100644 --- a/bot.c +++ b/bot.c @@ -60,9 +60,9 @@ void zeRace_init() /* robot configuration */ sprintf(config.pseudo,"\"%s\" bot(%d)",bot_name(),aleas); - config.color=rand()%12; + config.color=rand()%16; - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) + if (SDL_Init(0)<0) { fprintf(stderr,"could not initialize SDL : %s\n",SDL_GetError()); zeRace_exit(); @@ -134,6 +134,9 @@ void zeRace_launch(int alltime,int go) net.keys[net.time+1]='\0'; } + /* move the car */ + move_car(&car,(ku<<3 | kd<<2 | kl<<1 | kr),fun); + delay=DELAY; /* if we are in network mode */ if (udpsock!=NULL) @@ -155,6 +158,16 @@ void zeRace_launch(int alltime,int go) lastack=clienttime; } } + else if (strcmp(packet->data,"collision")==0) + { + net.time=-1; + net.keys[0]='\0'; + lastack=SDLNet_Read32(packet->data+strlen("collision")+1); + car.x=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4)/65536-100; + car.y=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4)/65536-100; + car.speed=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4+4)/65536-100; + car.angle=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4+4+4)/65536-100; + } else /* end of this network race */ { SDL_FreeSurface(cir); @@ -168,6 +181,10 @@ void zeRace_launch(int alltime,int go) tmp+=strlen(tmp)+1; SDLNet_Write32(lastack,tmp); tmp+=4; + SDLNet_Write32(car.x,tmp); + tmp+=4; + SDLNet_Write32(car.y,tmp); + tmp+=4; strcpy(tmp,net.keys); tmp+=strlen(tmp)+1; packet->len=(void *)tmp-(void *)packet->data+10; @@ -179,9 +196,6 @@ void zeRace_launch(int alltime,int go) } } - /* move the car */ - move_car(&car,(ku<<3 | kd<<2 | kl<<1 | kr),fun); - /* let the system breath */ SDL_Delay(delay); @@ -232,7 +246,7 @@ void zeRace_connect(char *host,int port) tmp+=strlen(tmp)+1; go=*tmp++; printf("server asked for track : %s\n",tmp); - while (tracklist->next!=loopcheck) if (strcmp(tracklist->name,tmp)==0) break; else tracklist=tracklist->next; + do if (strcmp(tracklist->name,tmp)==0) break; else tracklist=tracklist->next; while (tracklist!=loopcheck); if (strcmp(tracklist->name,tmp)!=0) { fprintf(stderr,"unknown track : %s\n",tmp);