X-Git-Url: http://royale.zerezo.com/git/?p=zeRace;a=blobdiff_plain;f=zeRace.c;h=9277dd3b74bf5935dd74b00a43745bec15f3afbf;hp=a4f5252267711f23f6c768d5502fd21c07c808b9;hb=HEAD;hpb=1be6de5da72b6218e87c20e29782ce6f9d99196e diff --git a/zeRace.c b/zeRace.c index a4f5252..9277dd3 100644 --- a/zeRace.c +++ b/zeRace.c @@ -1,5 +1,5 @@ /* - * zeRace 0.5, a funny retro racing game + * zeRace 0.7, 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; @@ -68,7 +69,8 @@ struct _config int color; SDLKey boss; int bynight; -} config = {"anonymous","",0,0,1,SDLK_UP,SDLK_DOWN,SDLK_LEFT,SDLK_RIGHT,6,SDLK_b,0}; + int internet; +} config = {"anonymous","",0,0,1,SDLK_UP,SDLK_DOWN,SDLK_LEFT,SDLK_RIGHT,6,SDLK_b,0,1}; /* full script for a lap */ struct _record @@ -141,6 +143,8 @@ void zeRace_check_version() char response[1024],*tmp,*version; int len,result; + if (!config.internet) return; + printf("checking version... "); fflush(stdout); @@ -197,6 +201,8 @@ void zeRace_update_tracks() int len,result; FILE *fic; + if (!config.internet) return; + printf("checking version and updating tracks... "); fflush(stdout); @@ -248,6 +254,8 @@ void zeRace_download_file(char *file) FILE *fic; struct stat buf; + if (!config.internet) return; + if (stat(file,&buf)<0) { printf("downloading file \"%s\" : ",file); @@ -344,6 +352,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 +390,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 +424,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; @@ -437,8 +447,10 @@ void zeRace_send_time(struct _record record) char *msg9="&bkeys="; int len,result; + if (!config.internet) return; + /* 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 +468,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 +646,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 +739,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 +951,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 +977,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; } @@ -1292,6 +1304,8 @@ void zeRace_internet() int active=0; #define INTERNET_OPTIONS 11 + if (!config.internet) return; + printf("dowloading list of servers... "); fflush(stdout); @@ -1395,7 +1409,7 @@ void zeRace_config() { SDL_Event event; int active=0; - #define CONFIG_OPTIONS 13 + #define CONFIG_OPTIONS 14 void update() { @@ -1429,6 +1443,8 @@ void zeRace_config() print(screen,40+10*strlen("Boss key : "),HEIGHT/(CONFIG_OPTIONS+4)*13,config.boss?SDL_GetKeyName(config.boss):""); print(screen,40,HEIGHT/(CONFIG_OPTIONS+4)*14,"By night : "); print(screen,40+10*strlen("By night : "),HEIGHT/(CONFIG_OPTIONS+4)*14,config.bynight?"Yes":"No"); + print(screen,40,HEIGHT/(CONFIG_OPTIONS+4)*15,"Internet : "); + print(screen,40+10*strlen("Internet : "),HEIGHT/(CONFIG_OPTIONS+4)*15,config.internet?"Yes":"No"); print(screen,40,HEIGHT/(CONFIG_OPTIONS+4)*(CONFIG_OPTIONS+2),"Back to main menu"); SDL_Flip(screen); } @@ -1483,7 +1499,8 @@ void zeRace_config() break; case 10: config.boss=0; update(); config.boss=read_key(); break; case 11: config.bynight=!config.bynight; break; - case 12: + case 12: config.internet=!config.internet; break; + case 13: return; } update();