Tron Light Cycle Example
Please feel free to use/alter this as you wish, It's not complete as it has no Collision/AI's/Menu, but hopefully someone out there may learn something or get an idea on how to improve, (I started out by altering other peoples code so it was a good way to learn for me).
Also if you do decide to make a game using this code, then i would suggest changing the map format to one that will be better for the FPS Rate, I only used the map format here due to speed in making the maps as an example, (Did code and 3 "Levels" in under 2 days), Its not a complete game, But does show the basics of how you could make a Tron style game..
` ---------------------------------------------------
` Tron Light Cycle Example for DarkBasic
` ---------------------------------------------------
` By Michael Mihalyfi
` Mihalyfi@Hotmil.co.uk
` ---------------------------------------------------
` First do general settings
Set Display Mode 1280,1024,32
Sync On : Sync Rate 0 : AutoCam Off
Color Backdrop 0,0
` Set Data for the Game
Global CubeSize# As Float
Global Texture As Integer
Global Texture2 As Integer
` SetReflectionOn = 1 : make object Sphere 100,-5000 : ` This is System Intensive so do not use, (Will Wreck FPS, Although it may be good for getting a MainMenu ScreenShot)
MinSpeed# = 1.5 : ` Minimum Speed of a Light Cycle
MaxSpeed# = 2.5 : ` Maximum Speed of a Light Cycle
CubeSize# = 20 : ` Size of each Cube used to create map
Speed# = MinSpeed# : ` Players Crrent Speed
NewTrail = 1 : ` 1 = Player has just turned a corner
Texture = Find Free Image() : Load Image "Images\Tron Grid.bmp" ,Texture : ` Grid Image used for texturing
Texture2 = Find Free Image() : Load Image "Images\Tron Grid 2.bmp",Texture2 : ` Used ONLY when SetReflectionOn = 1
` Load/Position the Players Object and Set Camera
MyObj = Find Free Object()
Load Object "Objects\lightcycle.3ds",MyObj,1
Set Object Smoothing MyObj,100
Position Object MyObj,100,Object Size Y(MyObj)/2,100
position camera 0,50,50,50
xRotate Camera 20
` Load a Level, (1 Small and 2 large Levels Provided)
` Open To Read 1,"Levels\20 x 20 Arena.txt"
` Open To Read 1,"Levels\Huge Arena.txt"
Open To Read 1,"Levels\Huge Arena 2.txt"
Repeat : CMD$ = ReadString(1)
Inc y,1 : For x = 1 to Len(CMD$)
If Mid$(CMD$,x) = "0" : CreateBox(x*CubeSize#,y*CubeSize#,-(CubeSize#/2),SetReflectionOn)
Else
For z = 1 to Val(Mid$(CMD$,x))
CreateBox(x*CubeSize#,y*CubeSize#,-(CubeSize#/2)+(CubeSize#*z),SetReflectionOn)
Next z : Endif : Next x : Until CMD$ = "<END>" : Close File 1
` ---------------------------------------------------
Do
` Movment and Turning of Players Object
If UpKey() = 1 : Inc Speed#,0.0001 : If Speed# > MaxSpeed# : Speed# = MaxSpeed# : EndIf : EndIf
If DownKey() = 1 : Dec Speed#,0.0001 : If Speed# < MinSpeed# : Speed# = MinSpeed# : EndIf : EndIf
If LeftKey() = 0 And LeftTurn = 1 : LeftTurn = 0 : EndIf
If LeftKey() = 1 And LeftTurn = 0 : LeftTurn = 1 : NewTrail = 1 : yRotate Object MyObj,Object Angle Y(MyObj)-90 : EndIf
If RightKey() = 0 And RightTurn = 1 : RightTurn = 0 : EndIf
If RightKey() = 1 And RightTurn = 0 : RightTurn = 1 : NewTrail = 1 : yRotate Object MyObj,Object Angle Y(MyObj)+90 : EndIf
Move Object MyObj,Speed#/2
` Trail
If NewTrail = 0
Size# = Object Size X(TrailObj)
Delete Object TrailObj
Make Object Box TrailObj,Size#+(Speed#/2),5,0.1
Position Object TrailObj,Object Position X(MyObj),Object Position Y(MyObj),Object Position Z(MyObj)
yRotate Object TrailObj,Object Angle Y(MyObj)
Move Object TrailObj,-Object Size X(TrailObj)*0.5
yRotate Object TrailObj,Object Angle Y(MyObj)+90
Color Object TrailObj,RGB(255,0,0)
EndIf
If NewTrail = 1
NewTrail = 0
TrailObj = Find Free Object()
Make Object Box TrailObj,Speed#,0.1,0.1
Position Object TrailObj,Object Position X(MyObj),Object Position Y(MyObj),Object Position Z(MyObj)
EndIf
` Quick Pause Option
If Upper$(Inkey$()) = "P"
Repeat : Until Inkey$() = ""
EndIf
` Camera Controls
X = Object Position X(MyObj)
Y = Object Position Y(MyObj)
Z = Object Position Z(MyObj)
Angle = Object Angle Y(MyObj)
Distance = 20
Height = 20
Smooth = 50
Collision = 1
Set Camera To Follow X,Y,Z,Angle,Distance,Height,Smooth,Collision
` Display Some Data Here
Text 10,10,"FPS = "+STR$(Screen FPS())
Text 10,30,"Speed = "+STR$(Speed#)
Sync : Loop
` ---------------------------------------------------
Function CreateBox(x#,y#,z#,Reflective) : ` This function creates the box item for the floor or walls
` Make the Standard box
Obj = Find Free Object()
Make Object Cube Obj,CubeSize#
Position Object Obj,x#,z#,y#
Texture Object Obj,Texture
Set Object Cull Obj,1
` If Reflective
If Reflective = 1
Set Object Transparency Obj,1
Obj = Find Free Object()
Make Object Cube Obj,CubeSize#-0.001
Position Object Obj,x#,z#,y#
Texture Object Obj,Texture2
Set Object Transparency Obj,1
Set Reflection Shading On Obj
EndIf
EndFunction
FUNCTION ReadString(Fn) : ` Reads a String from a File
Read String Fn,S$
ENDFUNCTION s$
Attached is Zipped project with Models, Images and Levels, (Should work straight out of zip)
Everyone Be Cool, You, Be Cool.