This is a simple drag race that repeats after the distance is reached and can go on a long as you want and when you end it will display your best time.
Space is the gas pedal
up is to shift up
down is to shift down
Don't forget to add the resources folder as the filename$ variable
This is the twenty line version of the drag racer
`Please ebter the adress of the resouces in the below string variable
filename$="E:\Drag Racer":Sync on:sync rate 40:hide mouse:set ambient light 50:MAKE OBJECT box 2, 20,1,40000:position object 2,0,-1,20000:backdrop on:
load image Filename$+"\road.bmp",2:TEXTURE OBJECT 2,2:LOAD object filename$+"\H-F1 Car-Move.x", 1:color backdrop rgb(0,0,0):
position object 1,0,0,0:YROTATE OBJECT 1, 180:LOOP OBJECT 1, 1, 25:count=0:first_time# = timer():current_time#=0:Best_time#=999:Speed#=0:
rpm#=1:acceleration_rating#=1:gear=0:distance=0:do:
IF gear = 0:acceleration_rating#=1:max_speed=30:ENDIF:IF gear = 1:acceleration_rating#=.9:max_speed=65:ENDIF:IF gear = 2:acceleration_rating#=.8:max_speed=100:ENDIF:IF gear = 3:
acceleration_rating#=.7:max_speed=135:ENDIF:IF gear = 4:acceleration_rating#=.6:max_speed=175:ENDIF:IF gear = 5:acceleration_rating#=.5:max_speed=210:ENDIF:
IF SPACEKEY()=1 and speed#<=max_speed:Speed#=Speed#+(acceleration_rating#):ELSE:Speed#=speed#-.1:ENDIF:if speed# > max_speed then speed#=speed#-1:if speed# < 0 then Speed#=0:
rpm# = (speed#/max_speed)*8000+1000:if UPKEY()=1 and count=<0 and gear<6:gear = gear + 1:count=5:endif:if DOWNKEY()=1 and count<0 and gear>-1:gear = gear- 1:
count=5:endif:if gear <= -1 THEN gear = 0:if gear > 5 THEN gear = 5:
count=count-1:current_time# = (timer()-first_time#)/1000:IF object position z(1)>=40000:
Speed#=0:rpm#=0:gear=0:distance=0:First_time#=timer():if current_time#<best_time# then best_time#=current_time#:position object 1,0,0,0:endif:
distance = speed#+object position z(1):Position object 1,0,0,distance:angle = angle + 1:if angle > 360 then angle = 0:
position camera object position x(1)+cos(angle),object position y(1)+10,object position z(1)-15+sin(angle):
point camera object position x(1),object position y(1),object position z(1):text 5,5,"SPEED:"+str$(int(speed#)):text 5,17,"GEAR:"+str$(gear+1):text 5,29,"RPM:"+str$(int(RPM#)):
text 5,41,"DISTANCE:"+str$(distance):text 5,53, "you time is "+ str$(current_time#)+" seconds":text 5,65, "you best time is "+ str$(best_time#)+" seconds":
text 5,77, "Hit the return key to stop":if returnkey()=1:repeat:text 5,5, "you best time is "+ str$(best_time#)+" seconds":text 5,15, "Hit space to exit":
until spacekey()=1:end:endif:sync:loop:
Here is the extended version with comments on some of the segments of code.
`Please ebter the adress of the resouces in the below string variable
Filename$="E:\Drag Racer"
Sync on
sync rate 40
hide mouse
set ambient light 50
`track
MAKE OBJECT box 2, 20,1,40000
position object 2,0,-1,20000
backdrop on
load image filename$+"\road.bmp",2
TEXTURE OBJECT 2,2
`race car
LOAD object filename$+"\H-F1 Car-Move.x", 1
color backdrop rgb(0,0,0)
position object 1,0,0,0
YROTATE OBJECT 1, 180
LOOP OBJECT 1, 1, 25
`Control variables
count=0
first_time# = timer()
current_time#=0
Best_time#=999
Speed#=0
rpm#=1
acceleration_rating#=1
gear=0
distance=0
do
`gear controls
IF gear = 0
acceleration_rating#=1
max_speed=30
ENDIF
IF gear = 1
acceleration_rating#=.9
max_speed=65
ENDIF
IF gear = 2
acceleration_rating#=.8
max_speed=100
ENDIF
IF gear = 3
acceleration_rating#=.7
max_speed=135
ENDIF
IF gear = 4
acceleration_rating#=.6
max_speed=175
ENDIF
IF gear = 5
acceleration_rating#=.5
max_speed=210
ENDIF
`gas pedal
IF SPACEKEY()=1 and speed#<=max_speed
Speed#=Speed#+(acceleration_rating#)
ELSE
Speed#=speed#-.1
ENDIF
if speed# > max_speed then speed#=speed#-1
if speed# < 0 then Speed#=0:
rpm# = (speed#/max_speed)*8000+1000
`gear shifter and controls
if UPKEY()=1 and count=<0 and gear<6
gear = gear + 1
count=5
endif
if DOWNKEY()=1 and count<0 and gear>-1
gear = gear- 1
count=5
endif
if gear <= -1 THEN gear = 0
if gear > 5 THEN gear = 5
count=count-1
current_time# = (timer()-first_time#)/1000
`the objective control and reset
IF object position z(1)>=40000
Speed#=0
rpm#=0
gear=0
distance=0
First_time#=timer()
if current_time#<best_time# then best_time#=current_time#
position object 1,0,0,0
endif
`movement controls
distance = speed#+object position z(1)
Position object 1,0,0,distance
`camera and display
angle = angle + 1
if angle > 360 then angle = 0
position camera object position x(1)+cos(angle),object position y(1)+10,object position z(1)-15+sin(angle)
point camera object position x(1),object position y(1),object position z(1)
`the shown variables
text 5,5,"SPEED:"+str$(int(speed#))
text 5,17,"GEAR:"+str$(gear+1)
text 5,29,"RPM:"+str$(int(RPM#))
text 5,41,"DISTANCE:"+str$(distance)
text 5,53, "you time is "+ str$(current_time#)+" seconds"
text 5,65, "you best time is "+ str$(best_time#)+" seconds"
text 5,77, "Hit the return key to stop"
`The exit key
if returnkey()=1
repeat
text 5,5, "you best time is "+ str$(best_time#)+" seconds"
text 5,15, "Hit space to exit"
until spacekey()=1
end
endif
sync
loop
I hope you have fun playing the game.