[Xmltools-development] xmltools2/xmltools/tests CMakeLists.txt cars.c track.c
Status: Beta
Brought to you by:
nik_89
|
From: nik_89 <ni...@us...> - 2004-11-11 22:27:06
|
Update of /cvsroot/xmltools/xmltools2/xmltools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32544 Modified Files: CMakeLists.txt cars.c track.c Log Message: added the saving of the tracks but I have disabled it since xmltools needed tweaks. added a buggy spinoff, it currently doesnt place the car on the track when it spins Index: CMakeLists.txt =================================================================== RCS file: /cvsroot/xmltools/xmltools2/xmltools/tests/CMakeLists.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CMakeLists.txt 23 Oct 2004 14:41:38 -0000 1.2 --- CMakeLists.txt 11 Nov 2004 22:26:55 -0000 1.3 *************** *** 6,11 **** TARGET_LINK_LIBRARIES(mwindows) ELSE (WIN32) ! LINK_LIBRARIES(SDL m pthread) ! INCLUDE_DIRECTORIES(/usr/include /usr/include/sdl-1.2) ENDIF (WIN32) --- 6,12 ---- TARGET_LINK_LIBRARIES(mwindows) ELSE (WIN32) ! LINK_DIRECTORIES(. ./lib) ! LINK_LIBRARIES(SDL m pthread xmltools) ! INCLUDE_DIRECTORIES(/usr/include /usr/include/sdl-1.2 ./include) ENDIF (WIN32) Index: cars.c =================================================================== RCS file: /cvsroot/xmltools/xmltools2/xmltools/tests/cars.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** cars.c 23 Oct 2004 03:31:38 -0000 1.18 --- cars.c 11 Nov 2004 22:26:56 -0000 1.19 *************** *** 34,38 **** static void car_offtrack(int cnum) { ! if (car[cnum]->speed > 0) { int a = abs(car[cnum]->speed / CARS_SPEED_OFFSET); --- 34,38 ---- static void car_offtrack(int cnum) { ! if (car[cnum]->speed > 0 && car[cnum]->offtrack == 1) { int a = abs(car[cnum]->speed / CARS_SPEED_OFFSET); *************** *** 44,53 **** } car[cnum]->speed -= CARS_SPINOFF_BRAKE_OFFSET; } else { ! car[cnum]->xpos = car[cnum]->lastxpos; ! car[cnum]->ypos = car[cnum]->lastypos; ! car[cnum]->offtrack = 0; } return; --- 44,73 ---- } car[cnum]->speed -= CARS_SPINOFF_BRAKE_OFFSET; + if (car[cnum]->rotation < 16) + car[cnum]->rotation += 1; + else + car[cnum]->rotation = 0; } else { ! if (car[cnum]->offtrack == 1) ! car[cnum]->offtrack = 2; /* the replacing part */ ! int a = abs(car[cnum]->speed / CARS_SPEED_OFFSET); ! while (a--) ! if (car[cnum]->ypos < YRES - 20) /* to counter off screen gaps */ ! { ! car[cnum]->xpos -= car[cnum]->xspeed; ! car[cnum]->ypos -= car[cnum]->yspeed; ! if (car[cnum]->xpos == (car[cnum]->lastxpos * car[cnum]->yspeed) ! && car[cnum]->ypos == (car[cnum]->lastypos * car[cnum]->xspeed)) ! { ! printf("car back on track\n"); ! car[cnum]->speed = 0; ! car[cnum]->offtrack = 0; ! break; ! } ! ! } ! car[cnum]->speed += CARS_SPINOFF_BRAKE_OFFSET; } return; *************** *** 580,584 **** void Cars_SetCarData(int num, CARS_DATA *buf) ! { car[num] = buf; return; --- 600,604 ---- void Cars_SetCarData(int num, CARS_DATA *buf) ! { /* to change, will need a memcpy() */ car[num] = buf; return; *************** *** 596,600 **** if (!car[a]->offtrack) Cars_Move(a); ! else if (car[a]->offtrack) car_offtrack(a); a++; --- 616,620 ---- if (!car[a]->offtrack) Cars_Move(a); ! else car_offtrack(a); a++; Index: track.c =================================================================== RCS file: /cvsroot/xmltools/xmltools2/xmltools/tests/track.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** track.c 17 Oct 2004 17:48:00 -0000 1.6 --- track.c 11 Nov 2004 22:26:56 -0000 1.7 *************** *** 14,17 **** --- 14,20 ---- + + #include "xmltools/xmltools.h" + static unsigned char mytrack[TRACK_WIDTH][TRACK_HEIGHT]; *************** *** 120,126 **** --- 123,167 ---- int Track_Init() { + memset(mytrack, 0, sizeof(unsigned char) * TRACK_WIDTH * TRACK_HEIGHT); Track_SetTile(3, 4, TT_HORIZONTAL); /* track start */ + + #if load_track + /* load the map from the save file */ + int a = 0; + if (a = open("save_racetrack.xml", 0644) == -1) + { + return 0; + } + close(a); + + Xmltool_GetXmlDesc("save_racetrack.xml"); + NODE_MAP *template = Nmap_GetData(); + + char num[5]; + a = 0; + NODE_MAP *n_map = NULL; + char *x, *y, *type; + while (a < 30) + { + memset(num, '\0', 5); + sprintf(num, "%d", a); + n_map = (NODE_MAP*)Xmltool_MReadXml("save_racetrack.xml", template->parent_name, "num", num); + x = (char*)Nmap_GetContent("x"); + y = (char*)Nmap_GetContent("y"); + type = (char*)Nmap_GetContent("type"); + + Track_SetTile(atoi(x), atoi(y), type[0] - 'A'); + a++; + } + int fd = 0; + if (fd = open("save_racetrack.xml", 0644) != -1) + unlink("save_racetrack.xml"); + close(fd); + /* end of map loading */ + #endif + + #if sample_debug_track /* debug sample track */ Track_SetTile(4, 4, TT_BOTTOMRIGHT_CORNER); *************** *** 143,147 **** Track_SetTile(1, 4, TT_BOTTOMLEFT_CORNER); Track_SetTile(2, 4, TT_HORIZONTAL); ! #if simple_debug_track Track_SetTile(4, 4, TT_HORIZONTAL); --- 184,189 ---- Track_SetTile(1, 4, TT_BOTTOMLEFT_CORNER); Track_SetTile(2, 4, TT_HORIZONTAL); ! #endif ! #if simple_debug_track Track_SetTile(4, 4, TT_HORIZONTAL); *************** *** 192,195 **** --- 234,278 ---- int Track_Cleanup() { + #if save_track + /* save the track configuration if it is valid */ + if (Track_IsValid()) + { + char *savefile = "save_racetrack.xml"; + int x = 0; + int y = 0, a = 0; + char strx[20], stry[20], type[5], num[5]; + Nmap_Clear(); + while (y < 5) + { + printf("here\n"); + memset(strx, '\0', 20); + memset(stry, '\0', 20); + memset(type, '\0', 5); + memset(num, '\0', 5); + + sprintf(strx, "%d", x); + sprintf(stry, "%d", y); + sprintf(num, "%d", a); + type[0] = mytrack[x][y] + 'A'; + + /* printf("num %s type %s\n x-y(%s-%s)\n", num, type, strx, stry); */ + + Nmap_Add("track", "num", num); + Nmap_Add("track", "type", type); + Nmap_Add("track", "x", strx); + Nmap_Add("track", "y", stry); + Xmltool_MAddXml(savefile); + + x++; + if (x >= 6) + { + y++; + x = 0; + } + a++; + } + printf("saved racetrack successfully\n"); + } + #endif return 0; } |