X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=zeRace.c;fp=zeRace.c;h=b371de40de478ed5dde3f1621d1545d603cb2884;hp=a4f5252267711f23f6c768d5502fd21c07c808b9;hb=a649266e00696290ecf09f15c9dfa09f1cd35244;hpb=1be6de5da72b6218e87c20e29782ce6f9d99196e diff --git a/zeRace.c b/zeRace.c index a4f5252..b371de4 100644 --- a/zeRace.c +++ b/zeRace.c @@ -1,5 +1,5 @@ /* - * zeRace 0.5, a funny retro racing game + * zeRace 0.6, a funny retro racing game * http://royale.zerezo.com/zerace/ * * Copyright (C) 2004 Antoine Jacquet @@ -49,6 +49,7 @@ #define C_RED SDL_MapRGB(screen->format,255,0,0) #define C_ORANGE SDL_MapRGB(screen->format,255,200,0) #define C_YELLOW SDL_MapRGB(screen->format,255,255,100) +#define T_BLACK SDL_MapRGB(cir->format,0,0,0) /* tracklist */ struct _tracklist *tracklist; @@ -344,6 +345,21 @@ void zeRace_init() signal(SIGINT,zeRace_exit); signal(SIGTERM,zeRace_exit); + /* initialize SDL */ + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) + { + fprintf(stderr,"could not initialize SDL : %s\n",SDL_GetError()); + zeRace_exit(); + } + atexit(SDL_Quit); + + /* initialize SDLNet */ + if (SDLNet_Init()==-1) + { + fprintf(stderr,"could not initialize SDLNet : %s\n",SDLNet_GetError()); + zeRace_exit(); + } + /* read the user configuration file */ zeRace_read_config(); @@ -367,19 +383,6 @@ void zeRace_init() srand(time(NULL)); - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) - { - fprintf(stderr,"could not initialize SDL : %s\n",SDL_GetError()); - zeRace_exit(); - } - atexit(SDL_Quit); - - if (SDLNet_Init()==-1) - { - fprintf(stderr,"could not initialize SDLNet : %s\n",SDLNet_GetError()); - zeRace_exit(); - } - packet=SDLNet_AllocPacket(1024); if (!packet) { @@ -414,7 +417,7 @@ void zeRace_init() /* send the best time for this race to the web server */ -void zeRace_send_time(struct _record record) +void zeRace_send_time(struct _record *record) { IPaddress ip; TCPsocket tcpsock; @@ -438,7 +441,7 @@ void zeRace_send_time(struct _record record) int len,result; /* if the best time is small enought to save all keys, send it */ - if (record.time>=MAXRECORDKEYS) return; + if (record->time>=MAXRECORDKEYS) return; printf("sending time... "); fflush(stdout); @@ -456,8 +459,8 @@ void zeRace_send_time(struct _record record) return; } - temp=(char *)malloc(strlen(msg1)+strlen(config.pseudo)+strlen(msg2)+strlen(config.url)+strlen(msg3)+strlen(tracklist->name)+strlen(msg4)+10+strlen(msg5)+10+strlen(msg6)+10+strlen(msg7)+10+strlen(msg8)+10+strlen(msg9)+strlen(record.keys)+100); - sprintf(temp,"%s%s%s%s%s%s%s%d%s%f%s%f%s%f%s%f%s%s\n",msg1,config.pseudo,msg2,config.url,msg3,tracklist->name,msg4,record.time,msg5,record.x,msg6,record.y,msg7,record.speed,msg8,record.angle,msg9,record.keys); + temp=(char *)malloc(strlen(msg1)+strlen(config.pseudo)+strlen(msg2)+strlen(config.url)+strlen(msg3)+strlen(tracklist->name)+strlen(msg4)+10+strlen(msg5)+10+strlen(msg6)+10+strlen(msg7)+10+strlen(msg8)+10+strlen(msg9)+strlen(record->keys)+100); + sprintf(temp,"%s%s%s%s%s%s%s%d%s%f%s%f%s%f%s%f%s%s\n",msg1,config.pseudo,msg2,config.url,msg3,tracklist->name,msg4,record->time,msg5,record->x,msg6,record->y,msg7,record->speed,msg8,record->angle,msg9,record->keys); len=strlen(temp); result=SDLNet_TCP_Send(tcpsock,temp,len); @@ -634,7 +637,7 @@ void zeRace_launch(int alltime,int go) SDLNet_UDP_Send(udpsock,-1,packet); SDL_Flip(screen); } - zeRace_send_time(best); + zeRace_send_time(&best); free_mem(); return; default: @@ -727,7 +730,7 @@ void zeRace_launch(int alltime,int go) } else /* end of this network race */ { - zeRace_send_time(best); + zeRace_send_time(&best); free_mem(); return; } @@ -939,13 +942,13 @@ void zeRace_launch(int alltime,int go) /* display tires slide */ if (config.tire) { - putpixel(cir,car.x+cos(car.angle)*car.w/3-sin(car.angle)*4,car.y+sin(car.angle)*car.h/3+cos(car.angle)*4,C_BLACK); - putpixel(cir,car.x+cos(car.angle)*car.w/3+sin(car.angle)*4,car.y+sin(car.angle)*car.h/3-cos(car.angle)*4,C_BLACK); + putpixel(cir,car.x+cos(car.angle)*car.w/3-sin(car.angle)*4,car.y+sin(car.angle)*car.h/3+cos(car.angle)*4,T_BLACK); + putpixel(cir,car.x+cos(car.angle)*car.w/3+sin(car.angle)*4,car.y+sin(car.angle)*car.h/3-cos(car.angle)*4,T_BLACK); /* if we are braking the slide is larger */ if (kd) { - putpixel(cir,car.x+cos(car.angle)*car.w/3-sin(car.angle)*3,car.y+sin(car.angle)*car.h/3+cos(car.angle)*3,C_BLACK); - putpixel(cir,car.x+cos(car.angle)*car.w/3+sin(car.angle)*3,car.y+sin(car.angle)*car.h/3-cos(car.angle)*3,C_BLACK); + putpixel(cir,car.x+cos(car.angle)*car.w/3-sin(car.angle)*3,car.y+sin(car.angle)*car.h/3+cos(car.angle)*3,T_BLACK); + putpixel(cir,car.x+cos(car.angle)*car.w/3+sin(car.angle)*3,car.y+sin(car.angle)*car.h/3-cos(car.angle)*3,T_BLACK); } } } @@ -965,7 +968,7 @@ void zeRace_launch(int alltime,int go) { print(screen,WIDTH/2-strlen("Timeout !")*5,HEIGHT/2-10,"Timeout !"); SDL_Flip(screen); - zeRace_send_time(best); + zeRace_send_time(&best); free_mem(); return; }