Well after the many helpful tips that were given to me on my previous threads, I was able to come up with this program below.
(Warning, its a fair read)
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` Mike's Racing Game
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` Started Project: 10:50PM, Thursday, October 15, 2009
` Finished Project: N/A
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` By Michael T. Schlueter
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
REMSTART
'Notes'
06/01/2010-Program Requires "Beach Bug 2" from the DarkMATTER Browser installed with Dark Basic Pro CD-ROM. Not sure if it's
on the online version. The file name is 'H-Beach Bug 2-Move.x. Also, need to find a better way to check for
multiple environment objects with the cars.
REMEND
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` Start Of Program
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
hide mouse
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Variables
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Object Variables
AoR=3 `Amount of Cars in the Race. Minimum is 2, Maximum is 50.
Grnd=51 `Environment starts in 50s. This is the main ground.
EvrmtMax=Grnd+2 `Determinds the maximum value for the environment objects. Exculdes Ground: so if you have ground and 1 jump, its Grnd+1
Evrmt=Grnd `Makes Evrmt start with Ground.
`Physic Variables
F#=0.25 `Turning Force of A wheel
L#=0.05 `Force of the ground pushing back on the car
Grav#=0.05 `force of gravity
Mult#=10 `multiplier
JuAir=0
NoSpd=0 `Car in Idle
dim CurSpd#(AoR) `Current speed of car in array
for S=1 to AoR
CurSpd#(S)=0
next S
TopSpd=1 `the maximum speed the car can go
Accel#=0.0005 `the acceleration of the car
Decel#=0.00001 `the deacceleration of the car
Brake#=0.001 `the braking power of the car
`Controller Variables
DIM Control(AoR,4) `1=Gas, 2=Right turn, 3=Left turn, 4=Brake
for C=1 to AoR
for H=1 to 4
Control(C,H)=0
next H
next C
dim HghtY#(AoR)
for H=1 to AoR
HghtY#(H)=0
next H
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Setup
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Race Car Maker
DIM Car(AoR)
for R=1 to AoR
Car(R)=R
load object "Beach Bug 2\H-Beach Bug 2-Move.x",Car(R)
yrotate object Car(R),180
fix object pivot Car(R)
Scale object Car(R),200,200,200
position object Car(R),rnd(50)-25,10,rnd(50)-25
next R
`Environment Maker
`The Main Ground
Make object plain Grnd,10000,10000
xrotate object Grnd,90
`A jump
Make object box 52,5,10,2
position object 52,20,0,-20
xrotate object 52,-45
`A jump
Make object box 53,5,10,2
position object 53,-20,0,20
xrotate object 53,45
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` The Main Loop Begins**************************************************************************
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Do
`Control Camera
position camera 0,25,-50
point camera object position x(Car(1)),object position y(Car(1)),object position z(Car(1))
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Keyboard Controls
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
if upkey()=1
Control(1,1)=1 `Gas=1
else
Control(1,1)=0 `Gas=0
endif
if Rightkey()=1
Control(1,2)=1 `R Turn=1
else
Control(1,2)=0 `R Turn=0
endif
if Leftkey()=1
Control(1,3)=1 `L Turn=1
else
Control(1,3)=0 `L Turn=0
endif
if Downkey()=1
Control(1,4)=1 `Brake=1
else
Control(1,4)=0 `Brake=0
endif
remstart
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`AI Controls
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Creates a Controller for each Car minus the Human controlled one. All AI controller objects are in 200s.
for AI=302 to AoR+300
`Looks to the Ai's next checkpoint
make object plain AI,1,1
`2 plains that if the looker plain looks through either one, the car will turn achordingly.
make object plain AI+50,50,50
instance object AI+60,AI+50
`Positioning and rotaing the plains in their spots
yrotate object AI+50,90
yrotate object AI+60,90
position object AI+50,limb position x (Car(AI-300),4),limb position y (Car(AI-300),4),limb position z (Car(AI-300),1)
position object AI+60,limb position x (Car(AI-300),10),limb position y (Car(AI-300),10),limb position z (Car(AI-300),10)
position object AI,limb position x (Car(AI-300),1),limb position y (Car(AI-300),1),limb position z (Car(AI-300),1)
`The Check
next AI
remend
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Controlling the Cars
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
for R=1 to AoR
`HghtY#(R)=object position y (Car(R))
`set object speed Car(R),CurSpd#*100
`make the car fall to the ground
`dec HghtY#(R),Grav#
`position object Car(R),object position x (Car(R)),HghtY#(R),object position z (Car(R))
`Control speed and direction
if Control(R,1)=1 and CurSpd#(R)<TopSpd
`CurSpd#(R)=curvevalue(TopSpd,CurSpd#(R),Accel#)
inc CurSpd#(R),Accel#
else
`CurSpd#(R)=curvevalue(NoSpd,CurSpd#(R),Decel#)
if CurSpd#(R)>NoSpd
dec CurSpd#(R),Decel#
endif
endif
if Control(R,2)=1 then turn object right Car(R),F#
if Control(R,3)=1 then turn object left Car(R),F#
if Control(R,4)=1
Control(R,1)=0
`CurSpd#(R)=curvevalue(NoSpd,CurSpd#(R),Brake#)
if CurSpd#(R)>NoSpd
dec CurSpd#(R),Brake#
endif
endif
move object Car(R),CurSpd#(R)
next R
remstart
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Ground Detection
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
for R=1 to AoR
`If the environment object number exceeds the Max reset it.
If Evrmt>EvrmtMax then Evrmt=Grnd
`Detects if a wheel is touching the ground
`Left Front Wheel:4
if intersect object (Grnd,limb position x (Car(R),4),limb position y (Car(R),4),limb position z (Car(R),4),limb position x (Car(R),4),limb position y (Car(R),4)-2,limb position z (Car(R),4))>0
roll object left Car(R),F#
pitch object down Car(R),F#
`move object up Car(R),L#
inc HghtY#(R),F#*Mult#
endif
`Left Rear Wheel:6
if intersect object (Grnd,limb position x (Car(R),6),limb position y (Car(R),6),limb position z (Car(R),6),limb position x (Car(R),6),limb position y (Car(R),6)-2,limb position z (Car(R),6))>0
roll object right Car(R),F#
pitch object down Car(R),F#
`move object up Car(R),L#
inc HghtY#(R),F#*Mult#
endif
`Right Rear Wheel:8
if intersect object (Grnd,limb position x (Car(R),8),limb position y (Car(R),8),limb position z (Car(R),8),limb position x (Car(R),8),limb position y (Car(R),8)-2,limb position z (Car(R),8))>0
roll object left Car(R),F#
pitch object up Car(R),F#
`move object up Car(R),L#
inc HghtY#(R),F#*Mult#
endif
`Right Front Wheel:10
if intersect object (Grnd,limb position x (Car(R),10),limb position y (Car(R),10),limb position z (Car(R),10),limb position x (Car(R),10),limb position y (Car(R),10)-2,limb position z (Car(R),10))>0
roll object right Car(R),F#
pitch object up Car(R),F#
`move object up Car(R),L#
inc HghtY#(R),F#*Mult#
endif
`Increases the environment object number
inc Evrmt,1
next R
remend
remstart
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Functions
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
CarPhysics()
AIController()
HumanController()
ControlReturn()
remend
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` The Main Loop Ends****************************************************************************
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Loop
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`Functions (are currently commented out, do to the fact they're not working at the moment.)
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
remstart
function CarPhysics()
for R=1 to AoR
`If the environment object number exceeds the Max reset it.
If Evrmt>EvrmtMax then Evrmt=Grnd
`Detects if a wheel is touching the ground
`Left Front Wheel
if intersect object (Evrmt,limb position x (Car(R),4),limb position y (Car(R),4),limb position z (Car(R),4),limb position x (Car(R),4),limb position y (Car(R),4)-1,limb position z (Car(R),4))>0
roll object right Car(R),F#
pitch object up Car(R),F#
move object up Car(R),L#
endif
`Left Rear Wheel
if intersect object (Evrmt,limb position x (Car(R),6),limb position y (Car(R),6),limb position z (Car(R),6),limb position x (Car(R),6),limb position y (Car(R),6)-1,limb position z (Car(R),6))>0
roll object right Car(R),F#
pitch object down Car(R),F#
move object up Car(R),L#
endif
`Right Rear Wheel
if intersect object (Evrmt,limb position x (Car(R),8),limb position y (Car(R),8),limb position z (Car(R),8),limb position x (Car(R),8),limb position y (Car(R),8)-1,limb position z (Car(R),8))>0
roll object left Car(R),F#
pitch object down Car(R),F#
move object up Car(R),L#
endif
`Right Rear Wheel
if intersect object (Evrmt,limb position x (Car(R),10),limb position y (Car(R),10),limb position z (Car(R),10),limb position x (Car(R),10),limb position y (Car(R),10)-1,limb position z (Car(R),10))>0
roll object left Car(R),F#
pitch object up Car(R),F#
move object up Car(R),L#
endif
`Increases the environment object number
inc Evrmt,1
next R
endfunction
function AIController()
`Creates a Controller for each Car minus the Human controlled one. All AI controller objects are in 200s.
for AI=202 to AoR+200
`Looks to the Ai's next checkpoint
make object plain AI,1,1
`2 plains that if the looker plain looks through either one, the car will turn achordingly.
make object plain AI+50,50,50
instance object AI+60,AI+50
`Positioning and rotaing the plains in their spots
yrotate object AI+50,90
yrotate object AI+60,90
position object AI+50,limb position x (Car(AI-200),4),limb position y (Car(AI-200),4),limb position z (Car(AI-200),1)
position object AI+60,limb position x (Car(AI-200),10),limb position y (Car(AI-200),10),limb position z (Car(AI-200),10)
position object AI,limb position x (Car(AI-200),1),limb position y (Car(AI-200),1),limb position z (Car(AI-200),1)
`The Check
next AI
endfunction
function HumanController()
`Keyboard Controls
if upkey()=1
Control(1,1)=1 `Gas=1
else
Control(1,1)=0 `Gas=0
endif
if Rightkey()=1
Control(1,2)=1 `R Turn=1
else
Control(1,2)=0 `R Turn=0
endif
if Leftkey()=1
Control(1,3)=1 `L Turn=1
else
Control(1,3)=0 `L Turn=0
endif
if Downkey()=1
Control(1,4)=1 `Brake=1
else
Control(1,4)=0 `Brake=0
endif
endfunction
function ControlReturn()
for R=1 to AoR
if Control(R,1)=1
CurSpd#(R)=curvevalue(TopSpd,CurSpd#(R),Accel#)
else
CurSpd#(R)=curvevalue(NoSpd,CurSpd#(R),Decel#)
endif
if Control(R,2)=1 then turn object right Car(R),F#
if Control(R,3)=1 then turn object left Car(R),F#
if Control(R,4)=1
Control(R,1)=0
CurSpd#(R)=curvevalue(NoSpd,CurSpd#(R),Brake#)
endif
move object Car(R),CurSpd#(R)
next R
endfunction
remend
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` Below is Commented Out. Left for Reference.
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
remstart
`Environment Objects
Ground=FreeObject()
position camera 0,50,-100
Point Camera 0,0,0
`Make Quick Ground
make object plain Ground,1000,1000
xrotate object Ground, 90
`Racers
dim Racer(5)
Racer(1)=FreeObject()
Racer(2)=FreeObject()
Racer(3)=FreeObject()
Racer(4)=FreeObject()
Racer(5)=FreeObject()
`A 'FOR' loop to figure out how many players
for P=1 to 5 step 1
load object "Beach Bug 2\H-Beach Bug 2-Move.x",
`load object "Beach Bug 2\H-Beach Bug 2-Move.x",Racer(P)
next P
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` Main Loop
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Do
Loop
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
` End Main Loop
`````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
remstart
` Free Object
Function FreeObject( )
` Add to array
Array Insert At Bottom _ObjTaken(0)
Obj = Array Count( _ObjTaken(0) )
` If object Obj doesnt exist, and isnt reserved..
If ( (Object Exist( Obj ) = 0) && (_ObjTaken(Obj) = 0) )
` Reserve
_ObjTaken( Obj ) = 1
` Return object
ExitFunction Obj
Endif
EndFunction 0
`Find a Free object
function FreeObject()
ID=1
while (object exist(ID))
inc ID
endwhile
endfunction ID
remend
Problem A: I've commented out My functions as I found they weren't working for some reason. I'm not too familiar with them, so I probaly missed something there.
Problem B: My Physic aren't working correctly. The Cars do funky rotations on just the flat plain(Grnd) and I've spent a day and a half trying to figure out what is wrong with no luck.

I've also commented this part out of the loop.
Problem C: So when I couldn't get the 2 fellas above working, I moved on to see if I could get the AI working. So I copied the code from the function and decided to see what error I'd get from this if any. Sure enough, at line 132 object already exists. Considering the the first object made is 302 (it was at 202, but I moved it up 100 units to try and fix it, which didn't work), and I had not programed any object higher than 100, I was completely stumped.
This I commented out as well and then played around with the AoR variable and found the Max and Mins for racers.
Well I'll thank you all ahead of time for looking through and finding what I can't. Oh and I have the Car object on the download thingy, and it's image on the post below. You'll have to edit the file name for the object path in the SETUP section of the code or just put it in a folder called "Beach Bug 2" or if you have darkMATTER you can find it in vehicles as beach bug 2 and avoid the whole download process altogether.
Mike
If you've noticed this notice, you will have noticed that this notice was not worth noticing.