responce = " "
save = 0
wincount=0
moneysave = 0
betup = 0
betdown = 0

while true do
pad2 = Controls.read()
	if pad2:right() then
		upCount = upCount+1
	if upCount == 1 then
		save = save+1 end
   else
	upCount = 0
end
 
	if pad2:left() then
		downCount = downCount+1
	if downCount == 1 then
		save = save-1 end
   else
	downCount = 0 end
	if pad2:select() then break end
	if pad2:start() then
		dofile "menu.lua" end
	if pad2:cross() and save == 1 then screen:save("save1.png") end
	if pad2:cross() and save == 2 then screen:save("save2.png") end
	if pad2:cross() and save == 3 then screen:save("save3.png") end
	if pad2:cross() and save == 4 then screen:save("save4.png") end
	if pad2:cross() and save == 5 then screen:save("save5.png") end
	if pad2:cross() and save == 6 then screen:save("save6.png") end
	if pad2:cross() and save == 7 then screen:save("save7.png") end
	if pad2:cross() and save == 8 then screen:save("save8.png") end
	if pad2:cross() and save == 9 then screen:save("save9.png") end
	if pad2:cross() and save == 10 then screen:save("save10.png") end

if time/25 < aitime/25 then
	betup = betup + 1
	responce = "YOU ROCK...PRESS START FOR THE NEXT RACE!" 
	difference = "Ahead" 
	timediff = (aitime/25)-(time/25) end
	
if time/25 > aitime/25 then
	betdown = betdown + 1
	responce = "YOU SUCK...PRESS START AND TRY NOT TO SUCK!"
	difference = "Behind"
	timediff = (time/25)-(aitime/25) end
	
if time/25 == aitime/25 then
	responce = "TIE...PRESS START TO TRY AGAIN!!" 
	timediff = 0 
	difference = "TIE" end	

if save < 0 then save = 0 end
if save > 10 then save = 10 end
if ai == s2000 then aiboard = "S2000" end
if ai == skyline then aiboard = "GT-R" end
if ai == supra then aiboard = "Supra" end
if ai == stang then aiboard = "'05 GT" end
if ai == vette then aiboard = "Z06" end
if ai == gto then aiboard = "3000GT" end
if ai == rx7 then aiboard = "RX-7" end
if ai == charger then aiboard = "440R/T" end

if time/25 < aitime/25 and wins < 8 then
	wincount = wincount+1
end


if wincount==1 then 
	wins = wins+1
	savewins()
end

if time/25 < high then
	touchthis:play()
	saveHighscore()
	loadHighscore()
end

if wins == 8 then
	dofile "win.lua"
end

if betup == 1 then
	money = money+bet
	savemoney()
end
if betdown == 1 then
	money = money-bet
	savemoney()
end


loadwins()
loadHighscore()
screen:clear()
screen:blit(0, 0, strip)
screen:print(13, 28, time/25, red)
screen:print(13, 36, max, red)
screen:print(13, 12, "YOU", black)
screen:print(13, 87, aitime/25, red)
screen:print(13, 95, aimax, red)
screen:print(10, 70, aiboard, black)
screen:print(14, 148, timediff, red)
screen:print(11, 130, difference, black)
screen:print(95, 200, responce, black)
screen:print(130, 230, "TO SAVE YOUR TIME PRESS X", black)
screen:print(180, 250, "Save File:", black)
screen:print(260, 250, save, black)
screen:print(425, 10, "BEST", red)
screen:print(425, 20, high, red)
screen:print(205, 130, "WINS", black)
screen:print(198, 150, wins, black)
screen:print(211, 150, "of 8", black)
screen:flip()
screen.waitVblankStart()
end