/*
- * 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 <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;
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;
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);
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;
}