System.usbDiskModeActivate() 

---COLORS
black = Color.new(0, 0, 0)
red = Color.new(255, 0, 0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
white = Color.new(255, 255, 255)
orange = Color.new(242, 101, 34)
yellow = Color.new(255, 242, 0)


---LOADING
loading = Image.load("pics/loading1.png")
screen:clear()
screen:blit(0, 0, loading)
screen:print(190, 230, "Loading Cars", yellow) 
screen:flip()
supra = Image.load("pics/supra.png")
skyline = Image.load("pics/gtr.png")
stang = Image.load("pics/stang.png")
crx = Image.load("pics/crx.png")
rx7 = Image.load("pics/rx7.png")
s13 = Image.load("pics/240.png")
iroc = Image.load("pics/iroc.png")
integra = Image.load("pics/integra.png")
sting = Image.load("pics/sting.png")
charger = Image.load("pics/charger.png")
supra2 = Image.load("pics/supra2.png")
vette = Image.load("pics/vette.png")
gto = Image.load("pics/3000gt.png")
gt350 = Image.load("pics/gt350.png")
s2000 = Image.load("pics/s2000.png")
prelude = Image.load("pics/prelude.png")

screen:clear()
screen:blit(0, 0, loading)
screen:print(190, 230, "Loading Menus", yellow) 
screen:flip()
screen.waitVblankStart()
locked = Image.load("pics/locked.png")
supramenu = Image.load("pics/supramenu.png")
gtrmenu = Image.load("pics/gtrmenu.png")
stangmenu = Image.load("pics/stangmenu.png")
crxmenu = Image.load("pics/crxmenu.png")
rx7menu = Image.load("pics/rx7menu.png")
s13menu = Image.load("pics/240sxmenu.png")
irocmenu = Image.load("pics/irocmenu.png")
integramenu = Image.load("pics/integramenu.png")
stingmenu = Image.load("pics/stingmenu.png")
chargermenu = Image.load("pics/chargermenu.png")
supra2menu = Image.load("pics/supra2menu.png")
vettemenu = Image.load("pics/vettemenu.png")
gtmenu = Image.load("pics/3000gtmenu.png")
gt350menu = Image.load("pics/gt350menu.png")
s2000menu = Image.load("pics/s2000menu.png")
preludemenu = Image.load("pics/preludemenu.png")
intro1 = Image.load("pics/intro1.png")




screen:clear()
screen:blit(0, 0, loading)
screen:print(190, 230, "Loading Sounds", yellow) 
screen:flip()
screen.waitVblankStart()
revlow = Sound.load("sound/revlow.wav")
no = Sound.load("sound/no.wav")
revlow2 = Sound.load("sound/revlow2.wav")
revmid = Sound.load("sound/revmid.wav")
revhigh = Sound.load("sound/revhigh.wav")
idle = Sound.load("sound/idle.wav")
tiresound = Sound.load("sound/tire.wav")
burnout = Sound.load("sound/burnout.wav")
kickit = Sound.load("sound/kickit.wav")
touchthis = Sound.load("sound/touchthis.wav")


screen:clear()
screen:blit(0, 0, loading)
screen:print(170, 230, "Loading Save Info", yellow) 
screen:flip()
screen.waitVblankStart()
intakeFile = "saveinfo/intake.txt"
exhaustFile = "saveinfo/exhaust.txt"
cpuFile = "saveinfo/cpu.txt"
turboFile = "saveinfo/turbo.txt"
nosFile = "saveinfo/nos.txt"
tiresFile = "saveinfo/tires.txt"
tranFile = "saveinfo/tran.txt"
highscoreFile = "saveinfo/time.txt"
winsFile = "saveinfo/wins.txt"
moneyFile = "saveinfo/money.txt"

screen:clear()
screen:blit(0, 0, loading)
screen:print(170, 230, "Loading Race Info", yellow) 
screen:flip()
screen.waitVblankStart()
track = Image.load("pics/bg.png")
street = Image.load("pics/bg2.png")
dash = Image.load("pics/dashboard.png")
strip = Image.load("pics/strip.png")
win = Image.load("pics/win.png")
pausescreen = Image.load("pics/pause.png")
engine = Image.load("pics/engine.png")
finishline1 = Image.load("pics/finish.png")
finishline2 = Image.load("pics/finish2.png")
boot = Image.load("pics/boot.png")
knob = Image.load("pics/knob.png")
blank = Image.load("pics/black.png")
screen:clear()
screen:blit(0, 0, loading)
screen:print(190, 230, "Loading Done", yellow)
screen:flip()
screen.waitVblankStart() 

inst = 0
dpadx = 25
dpady = 130
lx = 118
ly = 70
rx = 310
ry = 70
xx = 385
xy = 147
ox = 385
oy = 132
sqx = 385
sqy = 162
trix =385 
triy = 117
selx = 252
sely = 197
stx = 310
sty = 197
anax = 132
anay = 195
set = 0 

dpadfunct = "none"
dpadfunct2 = " "
dpadfunct3 = " "
dpadfunct4 = " "
anafunct = "none"
lfunct = "none"
rfunct = "none"
xfunct = "none"
ofunct = "none"
sqfunct = "none"
trifunct = "none"
selfunct = "none"
stfunct = "none"
group = "none"

function saveintake()
  intakefile = io.open(intakeFile, "w")
  if intakefile then
    intakefile:write(intake)
    intakefile:close()
  end
end
 
function loadintake()
  intakefile = io.open(intakeFile, "r")
  if intakefile then
    intakeopt = intakefile:read("*n")
    intakefile:close()
  end
end
----
function saveexhaust()
  exhaustfile = io.open(exhaustFile, "w")
  if exhaustfile then
    exhaustfile:write(exhaust)
    exhaustfile:close()
  end
end
 
function loadexhaust()
  exhaustfile = io.open(exhaustFile, "r")
  if exhaustfile then
    exhaustopt = exhaustfile:read("*n")
    exhaustfile:close()
  end
end
----
function savecpu()
  cpufile = io.open(cpuFile, "w")
  if cpufile then
    cpufile:write(cpu)
    cpufile:close()
  end
end
 
function loadcpu()
  cpufile = io.open(cpuFile, "r")
  if cpufile then
    cpuopt = cpufile:read("*n")
    cpufile:close()
  end
end
----
function saveturbo()
  turbofile = io.open(turboFile, "w")
  if turbofile then
    turbofile:write(turbo)
    turbofile:close()
  end
end
 
function loadturbo()
  turbofile = io.open(turboFile, "r")
  if turbofile then
    turboopt = turbofile:read("*n")
    turbofile:close()
  end
end
----
function savenos()
  nosfile = io.open(nosFile, "w")
  if nosfile then
    nosfile:write(nosremain)
    nosfile:close()
  end
end
 
function loadnos()
  nosfile = io.open(nosFile, "r")
  if nosfile then
    nosremain = nosfile:read("*n")
    nosfile:close()
  end
end
----
function savetires()
  tiresfile = io.open(tiresFile, "w")
  if tiresfile then
    tiresfile:write(tires)
    tiresfile:close()
  end
end
 
function loadtires()
  tiresfile = io.open(tiresFile, "r")
  if tiresfile then
    tiresopt = tiresfile:read("*n")
    tiresfile:close()
  end
end
----
function savetran()
  tranfile = io.open(tranFile, "w")
  if tranfile then
    tranfile:write(tran)
    tranfile:close()
  end
end
 
function loadtran()
  tranfile = io.open(tranFile, "r")
  if tranfile then
    tranopt = tranfile:read("*n")
    tranfile:close()
  end
end
----
function loading()
  loadopt = loadopt+1
end


function startcontrols()
startpad = Controls.read()
if startpad:start() then 
	dofile "menu.lua"
end
if startpad:cross() then
	inst = inst+1
else inst = 0	
end
end

function loadparts()
  loadintake()
  loadexhaust()
  loadcpu()
  loadturbo()
  loadnos()
  loadtires()
  loadtran()
end



while true do

if inst == 1 then set = set+1 end
if set > 3 then set = 0 end

if set == 0 then
dpadfunct = "Move"
dpadfunct2 = " "
dpadfunct3 = " "
dpadfunct4 = " "
anafunct = "none"
lfunct = "none"
rfunct = "none"
xfunct = "Select"
ofunct = "none"
sqfunct = "none"
trifunct = "none"
selfunct = "Restart"
stfunct = "none"
group = "MENU"
end

if set == 1 then
dpadfunct = "Up/Down:"
dpadfunct2 = "Move"
dpadfunct3 = "Left/Right:"
dpadfunct4 = "Change Part"
anafunct = "none"
lfunct = "none"
rfunct = "none"
xfunct = "Select"
ofunct = "none"
sqfunct = "none"
trifunct = "none"
selfunct = "none"
stfunct = "none"
group = "SHOP"
end
if set == 2 then
dpadfunct = "none"
dpadfunct2 = " "
dpadfunct3 = " "
dpadfunct4 = " "
anafunct = "none"
lfunct = "Shift Down"
rfunct = "Shift Up"
xfunct = "Accel"
ofunct = "NOS"
sqfunct = "Brake"
trifunct = "Screenshot"
selfunct = "Menu"
stfunct = "Pause"
group = "EASY RACE"
end
if set == 3 then
dpadfunct = "none"
dpadfunct2 = " "
dpadfunct3 = " "
dpadfunct4 = " "
anafunct = "Shifter"
lfunct = "Clutch"
rfunct = "Accel"
xfunct = "none"
ofunct = "NOS"
sqfunct = "Brake"
trifunct = "Screenshot"
selfunct = "Menu"
stfunct = "Pause"
group = "HARD RACE"
end




startcontrols()
screen:blit(0, 0, intro1)
screen:drawLine(340, 118, 380, 118, white)
screen:drawLine(340, 148, 380, 148, white)
screen:drawLine(350, 133, 380, 133, white)
screen:drawLine(315, 133, 315, 163, white)
screen:drawLine(315, 163, 380, 163, white)
screen:drawLine(325, 90, 325, 80, white)
screen:drawLine(140, 90, 140, 80, white)
screen:drawLine(90, 133, 115, 133, white)
screen:drawLine(139, 167, 139, 195, white)
screen:drawLine(303, 183, 310, 195, white)
screen:drawLine(287, 183, 280, 195, white)
screen:print(dpadx, dpady, dpadfunct, white)
screen:print(dpadx, dpady+10, dpadfunct2, white)
screen:print(dpadx, dpady+20, dpadfunct3, white)
screen:print(dpadx, dpady+30, dpadfunct4, white)
screen:print(anax, anay, anafunct, white)
screen:print(lx, ly, lfunct, white)
screen:print(rx, ry, rfunct, white)
screen:print(xx, xy, xfunct, white)
screen:print(ox, oy, ofunct, white)
screen:print(trix, triy, trifunct, white)
screen:print(sqx, sqy, sqfunct, white)
screen:print(selx, sely, selfunct, white)
screen:print(stx, sty, stfunct, white)
screen:print(210, 73, group, white)
screen:print(10, 235, "Note: If at ANY time you run out of money the game is over.", red)
screen:print(172, 130, "Press X for more", white) 
screen:flip()
screen.waitVblankStart()
end 
