-----------------------------------------------------------------------------
-- Cargame Version 0.2 by Nick Kochurov (dalejrrocks)
-- E-mail: dalejrrocks@rambler.ru or nascar_sk8ing_technology@yahoo.com
-----------------------------------------------------------------------------
green = Color.new(0,0,255)--actually blue
white     = Color.new(255,255,255)

proportional = Font.createProportional()
proportional:setPixelSizes(0, 10)

currentcolor1 = green
currentcolor2 = green
currentcolor3 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = green
currentcolor7 = green
currentcolor8 = green
currentcolor9 = green
currentcolor10 = green
currentcolor11 = green
currentcolor12 = green
currentcolor13 = green
currentcolor14 = green
currentcolor15 = green
currentcolor16 = green
currentcolor17 = green
currentcolor18 = green
currentcolor19 = green
currentcolor20 = green
currentcolor21 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
currentcolor28 = green
currentcolor29 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor36 = green
currentcolor37 = green
currentcolor38 = green
currentcolor39 = green
currentcolor40 = green
currentcolor41 = green
currentcolor42 = green
currentcolor43 = green
currentcolor44 = green
currentcolor45 = green
currentcolor46 = green
currentcolor47 = green
currentcolor48 = green
currentcolor49 = green
currentcolor50 = green
currentchoice = 90
menuchoice = 90
currentchoice3 = 90
currentchoice4 = 90
currentchoice5 = 90
currentchoice6 = 90
currentchoice7 = 90
pole1=0
red1=1000
yellow1=1500
yellow2=2000
green1=3000
oldpad1 = Controls.read()
totaltime=4500
winmargin=3
fg=0.2
sg=0.1
tg=0.05
fog=0.04
fig=0.03
sig=0.02
seg=0.01
neutralrpm=0
fgrpm=1000
sgrpm=2000
tgrpm=3500
fogrpm=4000
figrpm=4800
sigrpm=5300
redlinerpm=5800
optionselected = false
optionselected2 = false
optionselected3 = false
optionselected4 = false
optionselected5 = false
optionselected6 = false
pxx=336
pxy=238
pxx2=124
pxy2=238
p1b="circle"
p12b="triangle"
p21b="left"
p22b="up"
g1s="R"
g2s="L"
p1c="pad:circle()"
oldp1c="oldpad:circle()"
p12c="pad:triangle()"
oldp12c="oldpad:triangle()"
p21c="pad:left()"
oldp21c="oldpad:left()"
p22c="pad:up()"
oldp22c="oldpad:up()"
g1ss="pad:r()"
oldg1ss="oldpad:r()"
g2ss="pad:l()"
oldg2ss="oldpad:l()"
tsc0re=20
gasrpm=20
scroll = true
engine=Image.load("images/choice/engine.png")
function whichoption()
screen:fontPrint(proportional,135,90,"Race Light Timing",currentcolor8)
screen:fontPrint(proportional,135,100,"Race Win Margin",currentcolor9)
screen:fontPrint(proportional,135,110,"Player Starting Position",currentcolor16)
screen:fontPrint(proportional,135,120,"Acceleration Control",currentcolor19)
screen:fontPrint(proportional,135,130,"RPM Control",currentcolor36)
screen:fontPrint(proportional,135,140,"Player Controls",currentcolor39)
screen:fontPrint(proportional,135,150,"Save Settings",currentcolor40)
screen:fontPrint(proportional,135,160,"Load Settings",currentcolor43)
screen:fontPrint(proportional,135,170,"Continue",currentcolor18)
if pad1:down() and oldpad1:down() ~= pad1:down() and menuchoice < 170 then
menuchoice = menuchoice + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and menuchoice > 90 then
menuchoice = menuchoice - 10
end

if menuchoice == 90  then 
currentcolor9 = green
currentcolor8 = white
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected = true
end
end
if menuchoice == 100  then 
currentcolor8 = green
currentcolor9 = white
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected2 = true
end
end
if menuchoice == 110  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = white
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected3 = true
end
end

if menuchoice == 120  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = green
currentcolor19 = white
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected4 = true
end
end


if menuchoice == 130  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = white
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected5 = true
end
end

if menuchoice == 150  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = white
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
savesettings()
savecontrolsettings()
end
end

if menuchoice == 160  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = white
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
loadsettings()
end
end

if menuchoice == 140  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = green
currentcolor19 = green
currentcolor36 = green
currentcolor39 = white
currentcolor40 = green
currentcolor43 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected6 = true
end
end
if menuchoice == 170  then 
currentcolor8 = green
currentcolor9 = green
currentcolor16 = green
currentcolor18 = white
currentcolor19 = green
currentcolor36 = green
currentcolor39 = green
currentcolor40 = green
currentcolor43 = green
end
end

function savesettings()
  file = io.open("settings.txt","w+")
  file:write("pole1=")
  file:write(pole1)
  file:write("\n")
  file:write("red1=")
  file:write(red1)
  file:write("\n")
  file:write("yellow1=")
  file:write(yellow1)
  file:write("\n")
  file:write("yellow2=")
  file:write(yellow2)
  file:write("\n")
  file:write("green1=")
  file:write(green1)
  file:write("\n")
  file:write("totaltime=")
  file:write(totaltime)
  file:write("\n")  
  file:write("winmargin=")
  file:write(winmargin)
  file:write("\n")  
  file:write("tsc0re=")
  file:write(tsc0re)
  file:write("\n")  
  file:write("fg=")
  file:write(fg)
  file:write("\n")  
  file:write("sg=")
  file:write(sg)
  file:write("\n")  
  file:write("tg=")
  file:write(tg)
  file:write("\n")  
  file:write("fog=")
  file:write(fog)
  file:write("\n")  
  file:write("fig=")
  file:write(fig)
  file:write("\n")  
  file:write("sig=")
  file:write(sig)
  file:write("\n")  
  file:write("seg=")
  file:write(seg)
  file:write("\n")  
  file:write("fgrpm=")
  file:write(fgrpm)
  file:write("\n")  
  file:write("sgrpm=")
  file:write(sgrpm)
  file:write("\n")  
  file:write("tgrpm=")
  file:write(tgrpm)
  file:write("\n")  
  file:write("fogrpm=")
  file:write(fogrpm)
  file:write("\n")  
  file:write("figrpm=")
  file:write(figrpm)
  file:write("\n")  
  file:write("sigrpm=")
  file:write(sigrpm)
  file:write("\n")
  file:write("neutralrpm=")
  file:write(neutralrpm)
  file:write("\n")
  file:write("redlinerpm=")
  file:write(redlinerpm)
  file:write("\n")
  file:write("gasrpm=")
  file:write(gasrpm)
  file:write("\n")
  file:write("pxx=")
  file:write(pxx)
  file:write("\n")
  file:write("pxy=")
  file:write(pxy)
  file:write("\n")
  file:write("pxx2=")
  file:write(pxx2)
  file:write("\n")
  file:write("pxy2=")
  file:write(pxy2)
  file:write("\n")
 file:close()
end

function savecontrolsettings()
file = io.open("controlsettings.txt","w+")
file:write("p1c=")
  file:write(p1c)
  file:write("\n")
  file:write("oldp1c=")
  file:write(oldp1c)
  file:write("\n")
  file:write("p12c=")
  file:write(p12c)
  file:write("\n")
  file:write("oldp12c=")
  file:write(oldp12c)
  file:write("\n")
  file:write("p21c=")
  file:write(p21c)
  file:write("\n")
  file:write("oldp21c=")
  file:write(oldp21c)
  file:write("\n")
  file:write("p22c=")
  file:write(p22c)
  file:write("\n")
  file:write("oldp22c=")
  file:write(oldp22c)
  file:write("\n")
  file:write("g1ss=")
  file:write(g1ss)
  file:write("\n")
  file:write("oldg1ss=")
  file:write(oldg1ss)
  file:write("\n")
  file:write("g2ss=")
  file:write(g2ss)
  file:write("\n")
  file:write("oldg2ss=")
  file:write(oldg2ss)
  file:write("\n")
 file:close()
end

function loadsettings()
dofile("settings.txt")
dofile("controlsettings.txt")
end

ok = 0

function playercontrols()
screen:fontPrint(proportional,135,90,"Player 1, 1st Button Up:".." "..p1b,currentcolor41)
screen:fontPrint(proportional,135,100,"Player 1, 2nd Button Up:".." "..p12b,currentcolor42)
screen:fontPrint(proportional,135,110,"Player 2, 1st Button Up:".." "..p21b,currentcolor44)
screen:fontPrint(proportional,135,120,"Player 2, 2nd Button Up:".." "..p22b,currentcolor45)
screen:fontPrint(proportional,135,130,"Player 1, Gear Up:".." "..g1s,currentcolor46)
screen:fontPrint(proportional,135,140,"Player 2, Gear Up:".." "..g2s,currentcolor47)
screen:fontPrint(proportional,135,150,"Continue",currentcolor48)

if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice7 < 150 and scroll == true then
currentchoice7 = currentchoice7 + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice7 > 90 and scroll == true then
currentchoice7 = currentchoice7 - 10
end
if currentchoice7 == 90 then
currentcolor41=white
currentcolor42=green
currentcolor44=green
currentcolor45=green
currentcolor46=green
currentcolor47=green
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
p1b="down"
p1c="pad:down()"
end
if pad1:up() then
p1b="up"
p1c="pad:up()"
end
if pad1:left() then
p1b="left"
p1c="pad:left()"
end
if pad1:right() then
p1b="right"
p1c="pad:right()"
end
if pad1:triangle() then
p1b="triangle"
p1c="pad:triangle()"
end
if pad1:square() then
p1b="square"
p1c="pad:square()"
end
if pad1:circle() then
p1b="circle"
p1c="pad:circle()"
end
if pad1:cross() then
p1b="cross"
p1c="pad:cross()"
end
if pad1:l() then
p1b="L"
p1c="pad:l()"
end
if pad1:r() then
p1b="R"
p1c="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select()  and ok == 2 then
scroll = true
ok = 0
end
end
if currentchoice7 == 100 then
currentcolor41=green
currentcolor42=white
currentcolor44=green
currentcolor45=green
currentcolor46=green
currentcolor47=green
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
p12b="down"
p12c="pad:down()"
end
if pad1:up() then
p12b="up"
p12c="pad:up()"
end
if pad1:left() then
p12b="left"
p12c="pad:left()"
end
if pad1:right() then
p12b="right"
p12c="pad:right()"
end
if pad1:triangle() then
p12b="triangle"
p12c="pad:triangle()"
end
if pad1:square() then
p12b="square"
p12c="pad:square()"
end
if pad1:circle() then
p12b="circle"
p12c="pad:circle()"
end
if pad1:cross() then
p12b="cross"
p12c="pad:cross()"
end
if pad1:l() then
p12b="L"
p12c="pad:l()"
end
if pad1:r() then
p12b="R"
p12c="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select() and ok == 2 then
scroll = true
ok = 0
end
end
if currentchoice7 == 110 then
currentcolor41=green
currentcolor42=green
currentcolor44=white
currentcolor45=green
currentcolor46=green
currentcolor47=green
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
p21b="down"
p21c="pad:down()"
end
if pad1:up() then
p21b="up"
p21c="pad:up()"
end
if pad1:left() then
p21b="left"
p21c="pad:left()"
end
if pad1:right() then
p21b="right"
p21c="pad:right()"
end
if pad1:triangle() then
p21b="triangle"
p21c="pad:triangle()"
end
if pad1:square() then
p21b="square"
p21c="pad:square()"
end
if pad1:circle() then
p21b="circle"
p21c="pad:circle()"
end
if pad1:cross() then
p21b="cross"
p21c="pad:cross()"
end
if pad1:l() then
p21b="L"
p21c="pad:l()"
end
if pad1:r() then
p21b="R"
p21c="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select() and ok == 2 then
scroll = true
ok = 0
end
end
if currentchoice7 == 120 then
currentcolor41=green
currentcolor42=green
currentcolor44=green
currentcolor45=white
currentcolor46=green
currentcolor47=green
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
p22b="down"
p22c="pad:down()"
end
if pad1:up() then
p22b="up"
p22c="pad:up()"
end
if pad1:left() then
p22b="left"
p22c="pad:left()"
end
if pad1:right() then
p22b="right"
p22c="pad:right()"
end
if pad1:triangle() then
p22b="triangle"
p22c="pad:triangle()"
end
if pad1:square() then
p22b="square"
p22c="pad:square()"
end
if pad1:circle() then
p22b="circle"
p22c="pad:circle()"
end
if pad1:cross() then
p22b="cross"
p22c="pad:cross()"
end
if pad1:l() then
p22b="L"
p22c="pad:l()"
end
if pad1:r() then
p22b="R"
p22c="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select() and ok == 2 then
scroll = true
ok = 0
end
end
if currentchoice7 == 130 then
currentcolor41=green
currentcolor42=green
currentcolor44=green
currentcolor45=green
currentcolor46=white
currentcolor47=green
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
g1s="down"
g1ss="pad:down()"
end
if pad1:up() then
g1s="up"
g1ss="pad:up()"
end
if pad1:left() then
g1s="left"
g1ss="pad:left()"
end
if pad1:right() then
g1s="right"
g1ss="pad:right()"
end
if pad1:triangle() then
g1s="triangle"
g1ss="pad:triangle()"
end
if pad1:square() then
g1s="square"
g1ss="pad:square()"
end
if pad1:circle() then
g1s="circle"
g1ss="pad:circle()"
end
if pad1:cross() then
g1s="cross"
g1ss="pad:cross()"
end
if pad1:l() then
g1s="L"
g1ss="pad:l()"
end
if pad1:r() then
g1s="R"
g1ss="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select() and ok == 2 then
scroll = true
ok = 0
end
end
if currentchoice7 == 140 then
currentcolor41=green
currentcolor42=green
currentcolor44=green
currentcolor45=green
currentcolor46=green
currentcolor47=white
currentcolor48=green
if pad1:select() and oldpad1:select() ~= pad1:select() then
scroll=false
ok = ok+1
end
if scroll == false then
if pad1:down() then
g2s="down"
g2ss="pad:down()"
end
if pad1:up() then
g2s="up"
g2ss="pad:up()"
end
if pad1:left() then
g2s="left"
g2ss="pad:left()"
end
if pad1:right() then
g2s="right"
g2ss="pad:right()"
end
if pad1:triangle() then
g2s="triangle"
g2ss="pad:triangle()"
end
if pad1:square() then
g2s="square"
g2ss="pad:square()"
end
if pad1:circle() then
g2s="circle"
g2ss="pad:circle()"
end
if pad1:cross() then
g2s="cross"
g2ss="pad:cross()"
end
if pad1:l() then
g2s="L"
g2ss="pad:l()"
end
if pad1:r() then
g2s="R"
g2ss="pad:r()"
end

end
if pad1:select() and oldpad1:select() ~= pad1:select() and ok == 2 then
scroll = true
ok = 0
end
end

if currentchoice7 == 150 then
currentcolor42=green
currentcolor41=green
currentcolor44=green
currentcolor45=green
currentcolor46=green
currentcolor47=green
currentcolor48=white
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
oldp1c="old"..p1c
oldp12c="old"..p12c
oldp21c="old"..p21c
oldp22c="old"..p22c
oldg1ss="old"..g1ss
oldg2ss="old"..g2ss
optionselected6 = false
currentchoice7 = 90
end
end
end

function setrpms()
screen:fontPrint(proportional,135,90,"Neutral:"..neutralrpm,currentcolor38)
screen:fontPrint(proportional,135,100,"First Gear:"..fgrpm,currentcolor28)
screen:fontPrint(proportional,135,110,"Second Gear:"..sgrpm,currentcolor29)
screen:fontPrint(proportional,135,120,"Third Gear:"..tgrpm,currentcolor30)
screen:fontPrint(proportional,135,130,"Fourth Gear:"..fogrpm,currentcolor31)
screen:fontPrint(proportional,135,140,"Fifth Gear:"..figrpm,currentcolor32)
screen:fontPrint(proportional,135,150,"Sixth Gear:"..sigrpm,currentcolor33)
screen:fontPrint(proportional,135,160,"Seventh Gear:"..sigrpm,currentcolor34)
screen:fontPrint(proportional,135,170,"Redline:"..redlinerpm,currentcolor37)
screen:fontPrint(proportional,135,180,"RPM Added With The `Gas' Button:"..gasrpm,currentcolor50)
screen:fontPrint(proportional,135,190,"Continue",currentcolor35)
if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice6 < 190 then
currentchoice6 = currentchoice6 + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice6 > 90 then
currentchoice6 = currentchoice6 - 10
end
if currentchoice6 == 90 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = white
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
neutralrpm=neutralrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and fgrpm > 0 then
neutralrpm=neutralrpm-1
end
end

if currentchoice6 == 100 then
currentcolor28 = white
currentcolor29 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
fgrpm=fgrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sgrpm> 0 then
fgrpm=fgrpm-1
end
end

if currentchoice6 == 110 then
currentcolor29 = white
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
sgrpm=sgrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sgrpm> 0 then
sgrpm=sgrpm-1
end
end
if currentchoice6 == 120 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = white
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
tgrpm=tgrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and tgrpm > 0 then
tgrpm=tgrpm-1
end
end
if currentchoice6 == 130 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = white
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
fogrpm=fogrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and fogrpm > 0 then
fogrpm=fogrpm-1
end
end
if currentchoice6 == 140 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = white
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
figrpm=figrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and figrpm > 0 then
figrpm=figrpm-1
end
end
if currentchoice6 == 150 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = white
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
sigrpm=sigrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sigrpm > 0 then
sigrpm=sigrpm-1
end
end
if currentchoice6 == 160 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = white
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
sigrpm=sigrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sigrpm > 0 then
sigrpm=sigrpm-1
end
end
if currentchoice6 == 170 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = white
currentcolor38 = green
currentcolor50 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
redlinerpm=redlinerpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and redlinerpm > 0 then
redlinerpm=redlinerpm-1
end
end
if currentchoice6 == 180 then
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = green
currentcolor37 = green
currentcolor38 = green
currentcolor50 = white
if pad1:r() and oldpad1:r() ~= pad1:r() then 
gasrpm=gasrpm+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and gasrpm > 0 then
gasrpm=gasrpm-1
end
end
if currentchoice6 == 190  then 
currentcolor29 = green
currentcolor28 = green
currentcolor30 = green
currentcolor31 = green
currentcolor32 = green
currentcolor33 = green
currentcolor34 = green
currentcolor35 = white
currentcolor37 = green
currentcolor38 = green
currentcolor50 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected5 = false
currentchoice6 = 90
end
end
end


function accelerationcontrol()
screen:fontPrint(proportional,135,90,"First Gear:"..fg,currentcolor20)
screen:fontPrint(proportional,135,100,"Second Gear:"..sg,currentcolor21)
screen:fontPrint(proportional,135,110,"Third Gear:"..tg,currentcolor22)
screen:fontPrint(proportional,135,120,"Fourth Gear:"..fog,currentcolor23)
screen:fontPrint(proportional,135,130,"Fifth Gear:"..fig,currentcolor24)
screen:fontPrint(proportional,135,140,"Sixth Gear:"..sig,currentcolor25)
screen:fontPrint(proportional,135,150,"Seventh Gear:"..seg,currentcolor26)
screen:fontPrint(proportional,135,160,"Continue:",currentcolor27)
if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice5 < 160 then
currentchoice5 = currentchoice5 + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice5 > 90 then
currentchoice5 = currentchoice5 - 10
end
if currentchoice5 == 90  then 
currentcolor21 = green
currentcolor20 = white
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
fg=fg+0.1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and fg > 0 then
fg=fg-0.1
end
end
if currentchoice5 == 100  then 
currentcolor21 = white
currentcolor20 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
sg=sg+0.1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sg > 0 then
sg=sg-0.1
end
end
if currentchoice5 == 110  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = white
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
tg=tg+0.1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and tg > 0 then
tg=tg-0.1
end
end
if currentchoice5 == 120  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = green
currentcolor23 = white
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
fog=fog+0.1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and fog > 0 then
fog=fog-0.1
end
end
if currentchoice5 == 130  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = white
currentcolor25 = green
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
fig=fig+0.01
end
if pad1:l() and oldpad1:l() ~= pad1:l() and fig > 0 then
fig=fig-0.01
end
end
if currentchoice5 == 140  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = white
currentcolor26 = green
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
sig=sig+0.01
end
if pad1:l() and oldpad1:l() ~= pad1:l() and sig > 0 then
sig=sig-0.01
end
end
if currentchoice5 == 150  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = white
currentcolor27 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
seg=seg+0.01
end
if pad1:l() and oldpad1:l() ~= pad1:l() and seg > 0 then
seg=seg-0.01
end
end

if currentchoice5 == 160  then 
currentcolor21 = green
currentcolor20 = green
currentcolor22 = green
currentcolor23 = green
currentcolor24 = green
currentcolor25 = green
currentcolor26 = green
currentcolor27 = white
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected4 = false
currentchoice5 = 90
end
end
end

function carstartingpos()
screen:fontPrint(proportional,135,90,"Player One:"..pxx.." ".."x-axis",currentcolor13)
screen:fontPrint(proportional,135,100,"Player One:"..pxy.." ".."y-axis",currentcolor10)
screen:fontPrint(proportional,135,110,"Player One:"..pxx2.." ".."x-axis",currentcolor14)
screen:fontPrint(proportional,135,120,"Player One:"..pxy2.." ".."y-axis",currentcolor17)
screen:fontPrint(proportional,135,130,"Continue",currentcolor15)
if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice4 < 130 then
currentchoice4 = currentchoice4 + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice4 > 90 then
currentchoice4 = currentchoice4 - 10
end
if currentchoice4 == 90  then 
currentcolor14 = green
currentcolor13 = white
currentcolor15 = green
currentcolor10 = green
currentcolor17 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
pxx=pxx+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and pxx > 0 then
pxx=pxx-1
end
end
if currentchoice4 == 100  then
currentcolor14 = green
currentcolor13 = green
currentcolor15 = green
currentcolor10 = white
currentcolor17 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
pxy=pxy+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and pxy > 0 then
pxy=pxy-1
end
end
if currentchoice4 == 110  then 
currentcolor14 = white
currentcolor13 = green
currentcolor15 = green
currentcolor10 = green
currentcolor17 = green

if pad1:r() and oldpad1:r() ~= pad1:r() then
pxx2=pxx2+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and pxx2 > 0 then
pxx2=pxx2-1
end
end
if currentchoice4 == 120  then 
currentcolor14 = green
currentcolor13 = green
currentcolor15 = green
currentcolor10 = green
currentcolor17 = white

if pad1:r() and oldpad1:r() ~= pad1:r() then
pxy2=pxy2+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and pxy2 > 0 then
pxy2=pxy2-1
end
end

if currentchoice4 == 130  then 
currentcolor14 = green
currentcolor13 = green
currentcolor15 = white
currentcolor10 = green
currentcolor17 = green

if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected3 = false
currentchoice4 = 90
end
end
end

function setwinmargin()
screen:fontPrint(proportional,135,90,"Win Margin:"..winmargin.." ".."Screens Ahead",currentcolor12)
screen:fontPrint(proportional,135,100,"Total Score:"..tsc0re.." ".."Points",currentcolor49)
screen:fontPrint(proportional,135,110,"Continue",currentcolor11)
if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice3 < 110 then
currentchoice3 = currentchoice3 + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice3 > 90 then
currentchoice3 = currentchoice3 - 10
end
if currentchoice3 == 90  then 
currentcolor12 = white
currentcolor11 = green
currentcolor49 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
winmargin=winmargin+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and winmargin > 0 then
winmargin=winmargin-1
end
end
if currentchoice3 == 100  then 
currentcolor12 = green
currentcolor11 = green
currentcolor49 = white
if pad1:r() and oldpad1:r() ~= pad1:r() then
tsc0re=tsc0re+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and winmargin > 0 then
tsc0re=tsc0re-1
end
end
if currentchoice3 == 110  then 
currentcolor12 = green
currentcolor11 = white
currentcolor49 = green
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected2 = false
currentchoice3 = 90
end
end

end

function setstarttime()
screen:fontPrint(proportional,135,90,"Pole shown:"..pole1.." ".."miliseconds",currentcolor1)
screen:fontPrint(proportional,135,100,"Red Light Start:"..red1.." ".."miliseconds",currentcolor2)
screen:fontPrint(proportional,135,110,"Yellow Light 1 Start:"..yellow1.." ".."miliseconds",currentcolor3)
screen:fontPrint(proportional,135,120,"Yellow Light 2 Start:"..yellow2.." ".."miliseconds",currentcolor4)
screen:fontPrint(proportional,135,130,"Green Light Start:"..green1.." ".."miliseconds",currentcolor5)
screen:fontPrint(proportional,135,140,"Total Time:"..totaltime.." ".."miliseconds",currentcolor6)
screen:fontPrint(proportional,135,150,"Continue.",currentcolor7)
if pad1:down() and oldpad1:down() ~= pad1:down() and currentchoice < 150 then
currentchoice = currentchoice + 10
end
if pad1:up() and oldpad1:up() ~= pad1:up() and currentchoice > 90 then
currentchoice = currentchoice - 10
end

if currentchoice == 90  then 
if pad1:r() and oldpad1:r() ~= pad1:r() then
pole1=pole1+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and pole1 > 0 then
pole1=pole1-1
end
currentcolor1 = white
currentcolor2 = green
currentcolor3 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = green
currentcolor7 = green
end
if currentchoice == 100 then 
if pad1:r() and oldpad1:r() ~= pad1:r() then
red1=red1+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and red1 > 0 then
red1=red1-1
end
currentcolor2 = white
currentcolor1 = green
currentcolor3 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = green
currentcolor7 = green
end
if currentchoice == 110 then 
if pad1:r() and oldpad1:r() ~= pad1:r() then
yellow1=yellow1+1
end
if pad1:l() and oldpad1:l() ~= pad1:l()  and yellow1 > 0 then
yellow1=yellow1-1
end
currentcolor3 = white
currentcolor2 = green
currentcolor1 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = green
currentcolor7 = green
end
if currentchoice == 120 then
currentcolor3 = green
currentcolor2 = green
currentcolor1 = green
currentcolor4 = white
currentcolor5 = green
currentcolor6 = green
currentcolor7 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
yellow2=yellow2+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and yellow2 > 0 then
yellow2=yellow2-1
end
end
if currentchoice == 130 then
currentcolor3 = green
currentcolor2 = green
currentcolor1 = green
currentcolor4 = green
currentcolor5 = white
currentcolor6 = green
currentcolor7 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
green1=green1+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and green1 > 0 then
green1=green1-1
end
end
if currentchoice == 140 then
currentcolor3 = green
currentcolor2 = green
currentcolor1 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = white
currentcolor7 = green
if pad1:r() and oldpad1:r() ~= pad1:r() then
totaltime=totaltime+1
end
if pad1:l() and oldpad1:l() ~= pad1:l() and totaltime > 0 then
totaltime=totaltime-1
end
end

if currentchoice == 150 then
currentcolor3 = green
currentcolor2 = green
currentcolor1 = green
currentcolor4 = green
currentcolor5 = green
currentcolor6 = green
currentcolor7 = white
if pad1:cross() and oldpad1:cross() ~= pad1:cross() then
optionselected = false
currentchoice = 90
end

end

end
while true do
pad1 = Controls.read()
screen:blit(0,0,engine)

if optionselected == false and optionselected2 == false and optionselected3 == false and optionselected4 == false and optionselected5 == false and optionselected6 == false then
whichoption()
end
if optionselected == true then
setstarttime()
end
if optionselected2 == true then
setwinmargin()
end
if optionselected3 == true then
carstartingpos()
end
if optionselected4 == true then
accelerationcontrol()
end

if optionselected5 == true then
setrpms()
end

if optionselected6 == true then
playercontrols()
end

if pad1:cross() and menuchoice == 170 then
break
end

oldpad1=pad1
screen:flip()
screen:waitVblankStart()
end --end of code:1462