ok, the forum "post code" thingy is eating a chunk of the code, so you don`t have the bit with the end/start of the loop and its messing up, oddly enough it has the start and the end of the code, I will try putting it into the code snippet thingy, it might fit there.
Rem Project: racey
Rem Created: 26/08/2004 11:38:05
Rem ***** Main Source File *****
sync on:sync rate 40
rem lets make it go at a reasonable speed for most PC`s
rem heres the ground for the track
make matrix 1,512,512,20,20
rem go away annoying arrow type thingy
hide mouse
rem heres our amazing track
load image "track.bmp",1
rem here we prepare the texture to map to the matrix
prepare matrix texture 1,1,20,20
rem this is the number of the first tile image we will place on the matrix
tile=1
rem heres the tricky bit of code that maps the matrix tiles in order and correctly
rem I had ages of greif first time I tried this, because (a) the example is wrong
rem and (b) for some weird reason the tiles map to the matrix back to front and upside down
rem don`t ask me why.
rem so here we step through the locations backwards
for i=19 to 0 step -1
rem and here is forwards
for l=0 to 19
rem and here we turn around the varables so that its l,i instead of i,l
set matrix tile 1,l,i,tile
rem and switch to the next tile in the sequence
inc tile
rem end of the for-next loops
next l
next i
rem this makes sure we see the changes to the matrix (always a nice idea)
update matrix 1
rem now we open our custom .dat file for reading
open to read 1,"pathdata.dat"
rem first thing we do is find out how many waypoints we need
read word 1,maxpoints
rem so that we can DIM an array to exactly the size we need so we don`t waste ram
dim path(maxpoints,2)
rem and then we step through this loop that reads two values and places them into the array locations
for i=1 to maxpoints
rem getting the two words of data, notice that as we saved em as words they have to be retreived as words or misery follows
read word 1,path(i,1)
read word 1,path(i,2)
rem and this loop repeats until we have filled the array
next i
rem everything starts at waypoint one, so the target to start everything going is waypoint 2
current_waypoint=2
rem this is the high tech spheroid opponent car mk1, see it and weep (trendy solid blue paint too....like my car)
make object sphere 1,1
rem actualy its a bit oval, cos a round car looks silly
scale object 1,100,50,200
rem heres a coat of paint for the beast (not a run in sight)
color object 1,rgb(0,0,200)
rem lets place it on the track at checkpoint 1
position object 1,path(1,1),0.51,path(1,2)
rem and point it at checkpoint 2 so it at least is faceing the right direction
point object 1,path(2,1),0.51,path(2,2)
rem now we make some checkpoint objects to head too, simpler to handle than raw arrays
rem remember maxpoints is the maximum number of checkpoints
for i=1 to maxpoints
rem lets keep the polys down, a plain will do, all we have to do is to check for collision with it
make object plain i+1,2,2
rem here we place the plain on the track at the position supplied by the data from our waypoint editor
position object i+1,path(i,1),0,path(i,2)
rem and here we hide it, collision will still work etc, even though it`s hid, and we don`t want to see the checkpoints
hide object i+1
rem a check to make sure we don`t overun the total amount of objects we have
if i<maxpoints
rem we point them at each other so that they face across the track
point object i+1,path(i+1,1),0,path(i+1,2)
rem end of the check
endif
rem end of the loop
next i
rem we get to drive the camera...cool huh?, this is the player
position camera path(1,1),0.51,path(1,2)
rem make sure we are looking in the correct direction
point camera path(2,1),0.51,path(2,2)
rem and start off stationary (no cheating please)
speed#=0
rem just some details to set up and extra models to make, we don`t want the camera flying about at this point
autocam off
rem this is one important sphere, it has two jobs, in the setup it makes sure trees are not on the track
rem then it gets to follow the camera position and check how close we are to a waypoint, if we stray too far from
rem the track (and hence the waypoints) our speed takes a thrashing until we get back on the track, so no short cuts then
make object sphere 5000,15
rem geneticaly engineered conical trees, very cheap, we`ll have 200 ta!, if your framerates take a dive then get rid
rem of this section (between the ************`s) their just scenery, you don`t need em for the rest to work
rem it just gives you something to see whizzing by
rem *******************************************************************************************************************
for i=1 to 200
rem heres where they make the conical trees, smart factory huh?
make object cone 6000+i,rnd(5)+3
rem heres where they paint em all different shades of green to prevent monotony setting in
color object 6000+i,rgb(0,(rnd(200))+50,0)
rem we don`t want to hit em and they would get in the way of the waypoint checking, so off with their collision
set object collision off 6000+i
rem do I need to repeat myself, myself, myself, we repeat this bit until a potential tree
rem position is not near a waypoint (and hence the track(
repeat
rem a random tree position..variety X
x=rnd(511)+1
rem a random tree position... variety z
z=rnd(511)+1
rem so we plonk the big sphere at the potential position for our tree
position object 5000,rnd(512),0,rnd(512)
rem and if we get collision then we are either too close to a tree or the track (we hit a waypoint marker), if this happens then
rem collision is NOT zero, so the loop goes back round and picks another random position
until object collision(5000,0)=0
rem if we get to here then there was no collision so we plant a tree (ecological we are)
position object 6000+i,x,0,z
rem and we repeat until we have 200 of the green genetic freaks
next i
rem ***********************************************************************************************************************
rem we want to print some info, so lets make the screen look nice, first we want to be able to see the speedo easily
rem this isn`t the best way to display data on the screen but it will do for now
set text size 80
rem if you get blocky characters then you don`t have the
rem cooper font on your machine, so pick one you do have
set text font "cooper"
rem this ensures they erase the previous characters when the text updates and gives it a legible background for little cost
set text opaque
rem here we tweak the camera range since the default is a bit useless
set camera range 0.5,1000
rem heres the countdown timer, we count down from 5 to zero, displaying it to the user as we do, then the game starts
for i=5 to 0 step -1
rem here we set t to the current time plus one second (timer works in millisecs...1000 to the second)
t=timer()+1000
rem we repeatedly display the current value of I until the timer has reached the value of t (one second delay)
repeat
rem displaying I in the middle of the screen
text 320,200,str$(i)
rem just so we can see it happen since sync is on
sync
rem and when timer is over one second we let I go down to the next value (remember I is counting down)
until timer()>t
rem and heres the next I
next i
rem AAARGH!, after all that we finaly get to the top of the game loop, everything between here and do is the actual game
rem you will notice there is more actual setup than game, and not a lot to show for the setup either
do
rem here we hold the object number of the plain (waypoint) the car has hit, in between waypoints this value will be 0
target=object collision (1,current_waypoint)
rem if we are between waypoints and it is not the players track tracking sphere we detected then we are at a waypoint
if target>0 and target<5000
rem we where at a waypoint so we need the next waypoint, they where all made in the same order they where placed
rem in the editor, so we just increment by 1
inc current_waypoint
rem theres a problem with just increaseing the waypoint number, eventualy we will run out of waypoints
rem so we cunningly check if we have gone too far, we compare with the maxpoints value we loaded from the dat file
if current_waypoint>maxpoints
rem and if it is too big then we are at the last waypoint on the track, so we reset to the first one
current_waypoint=1
rem with that sorted we go back to the main point of this decision code
endif
rem now we have a valid new waypoint number, we point the computers car at it, then we allow the program to continue
point object 1,object position x(current_waypoint),0.51,object position z(current_waypoint)
rem we have made our decisons, back to running the loop
endif
rem hmmm wonder what direction the player is scrolling the mouse?
direction=mousemovex()
rem if the value is lower than zero then we turn the car (camera) in the direction we need
if direction<0
rem in this case left four degrees
turn camera left 4
rem and thats all we have to do to steer
endif
rem this si the same as the above but for the other direction
if direction>0
rem right four degrees, if you find the game too twitchy then reduce these values
turn camera right 4
rem and thats all there is to that
endif
rem ahh! the accelerator, top speed for this game is 130 mph, guess what value controls that
if upkey() and speed#<1.3
rem and here we speed up slowly as we hold the key down (wouldnt do to get to top speed instantly)
speed#=speed#+0.01
rem and thats all we need to do for the accelerator
endif
rem I chose the downkey for the brake/reverse, seems logical to me anyway, I also limited the maximum reverse speed to 30mph
if downkey() and speed#>-0.3
rem we can slow down faster than we accelerate, good thing too or we would have hit that semi
speed#=speed#-0.02
rem thats all I did for brakes, notice they double as the reverse, since the speed can go below 0mph
endif
rem heres that 15 unit sphere again, this time instead of checking that trees are clear of the road
rem it`s following the camera, we check if you are hitting waypoint plains, if you are not then you must be off
rem the track, so we slow you down to a crawl, get back on the track and the shere hits the waypoints again, and you
rem can speed up again, all this does is subtract more speed than the accelerator can give you, so if you change one
rem then you need to change this to make sure you can`t accelerate when off the track
if object collision(5000,0)=0 and speed#>0.2
rem down speed! down boy!
speed#=speed#-0.02
rem and that short bit takes care of you straying off the track
endif
rem so here we get to move the camera forwards by the speed you are going
move camera speed#
rem and the sphere follow along to check collision
position object 5000,camera position x(),0,camera position z()
rem the computer car continues on its path
move object 1,1
rem this little bundle makes sure we only see new speed updates every 1/2 second, otherwise the numbers can change realy fast
rem and make a mess of the display by blurring etc
if timer()>t
rem we only set a new intspeed every half second
intspeed=int(speed#*100)
rem then we add another half second to t
t=timer()+500
rem so the IF part of this bit will only be true when timer() is equal to t
endif
rem that sorts the variable update, so here we show what the speed has been for the last half second
center text 320,400,"Speed:"+str$(intspeed)+"MPH"
rem here we have the player looking down at a slight angle so that he can see the road better
pitch camera down 10
rem and here we display the framerate
text 0,0,str$(screen fps())
rem now lets see what the result of all this has been
sync
rem and here we place the layers head back level so that when the camera moves in the next frame
rem it doesn1t get closer to the floor and sink through it eventualy
pitch camera up 10
rem and the end of the play loop
loop
Mentor.
PC1: P4 3ghz, 1gig mem, 2x160gig hd`s, Radeon 9800pro w cooler (3rd gfx card), 6 way speakers.
PC2: AMD 2ghz, 512mb ram, FX5200 ultra, 16 bit SB.
Mini ATX cases suck.