/*
- * 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 <royale@zerezo.com>
#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;
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
char response[1024],*tmp,*version;
int len,result;
+ if (!config.internet) return;
+
printf("checking version... ");
fflush(stdout);
int len,result;
FILE *fic;
+ if (!config.internet) return;
+
printf("checking version and updating tracks... ");
fflush(stdout);
FILE *fic;
struct stat buf;
+ if (!config.internet) return;
+
if (stat(file,&buf)<0)
{
printf("downloading file \"%s\" : ",file);
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();
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)
{
/* 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;
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);
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);
SDLNet_UDP_Send(udpsock,-1,packet);
SDL_Flip(screen);
}
- zeRace_send_time(best);
+ zeRace_send_time(&best);
free_mem();
return;
default:
}
else /* end of this network race */
{
- zeRace_send_time(best);
+ zeRace_send_time(&best);
free_mem();
return;
}
/* 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);
}
}
}
{
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;
}
int active=0;
#define INTERNET_OPTIONS 11
+ if (!config.internet) return;
+
printf("dowloading list of servers... ");
fflush(stdout);
{
SDL_Event event;
int active=0;
- #define CONFIG_OPTIONS 13
+ #define CONFIG_OPTIONS 14
void update()
{
print(screen,40+10*strlen("Boss key : "),HEIGHT/(CONFIG_OPTIONS+4)*13,config.boss?SDL_GetKeyName(config.boss):"<press key>");
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);
}
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();