by DilloDude » Fri Jan 11, 2008 3:43 am
This might not be particularly hard, but then it might not be too easy either. First of all, you need to know how the track goes. I would advise a system of waypoints. These can be just stored in variables. You'll want an array, with the size being the maximum number of points you want. For ease of saving and loading, you'll probably want four integer arrays in a savegroup. Alternatively, you could try using a string, and storing each int in two chars. Most convenient for use would be to make your own struct, but that wouldn't be so convenient to save. You'll want these four integers:
xpos: the x coordinate of the waypoint
ypos: the y coordinate of the waypoint
dir: the direction the waypoint faces
rad: the radius of the waypoint.
Each waypoint will cover a line. The x and y coordinates mark the centre of the line, the direction is perpendicular to the line in the way the track goes, and the radius is the distance from the centre to either end.
You'll need some way of setting up these waypoints initially, whether loading them from a file (you'll need someway of saving them there in the first place) or creating them in code. A file would be more convenient, but it depends on what your doing with the track.
Place a waypoint at each corner of the track (sharp corners may need several). The waypoint should be centred in the middle of the track. The direction should be so it spans straight across. The radius should take it to the edge of the track, or possibly just a little shorter. The first waypoint (index 0 in the array) should be right at the starting line. Waypoints should go all the way around the track 'til just before the start line (if it's a multi-lap course) or end at the finish line (for a single-lap course).
See what you can come up with using that, and then I'll work on using that to make the AI.