nero = Color.new(0,0,0)
rosso = Color.new(255,0,0)
pic = Image.load("SYSTEM/resources/other/options2.png")
ba1 = Image.load("SYSTEM/resources/balls/ball(1)/ball.png")
ba2 = Image.load("SYSTEM/resources/balls/ball(2)/ball.png")
ba3 = Image.load("SYSTEM/resources/balls/ball(3)/ball.png")
ba4 = Image.load("SYSTEM/resources/balls/ball(4)/ball.png")
ba5 = Image.load("SYSTEM/resources/balls/ball(5)/ball.png")
ba6 = Image.load("SYSTEM/resources/balls/ball(6)/ball.png")
ba7 = Image.load("SYSTEM/resources/balls/ball(7)/ball.png")
ba8 = Image.load("SYSTEM/resources/balls/ball(8)/ball.png")
ba9 = Image.load("SYSTEM/resources/balls/ball(9)/ball.png")
ba10 = Image.load("SYSTEM/resources/balls/ball(10)/ball.png")
ba11 = Image.load("SYSTEM/resources/balls/ball(11)/ball.png")
ba12 = Image.load("SYSTEM/resources/balls/ball(12)/ball.png")
ba13 = Image.load("SYSTEM/resources/balls/ball(13)/ball.png")
ba14 = Image.load("SYSTEM/resources/balls/ball(14)/ball.png")
ba15 = Image.load("SYSTEM/resources/balls/ball(15)/ball.png")
ba16 = Image.load("SYSTEM/resources/balls/ball(16)/ball.png")
ba17 = Image.load("SYSTEM/resources/balls/ball(17)/ball.png")
ba18 = Image.load("SYSTEM/resources/balls/ball(18)/ball.png")
ba19 = Image.load("SYSTEM/resources/balls/ball(19)/ball.png")
ba20 = Image.load("SYSTEM/resources/balls/ball(20)/ball.png")

file = io.open("SYSTEM/resources/L.txt", "r") 
L = file:read("*n") 
file:close()

Selected = 20
timer1 = 0
timer2 = 0

set = 0
set1 = 0

while true do
pad = Controls.read()


screen:blit(0,0,pic)
screen:print(7,7,"BALL OPTIONS MENU :",rosso)
screen:print(7,8,"BALL OPTIONS MENU :",rosso)

screen:print(10,240,"Press X to CONFIRM",rosso)

Mp3me.play()
if Mp3me.gettime() == Mp3me.songTime() then
Mp3me.stop()
Mp3me.load("SYSTEM/resources/music/SND1.mp3")
Mp3me.play()
end


if pad:up() then timer1 = timer1 + 1 end
if not pad:up() then timer1 = 0 end
if timer1 == 1 then Selected = Selected - 10 end

if pad:down() then timer2 = timer2 + 1 end
if not pad:down() then timer2 = 0 end 
if timer2 == 1 then Selected = Selected + 10 end

screen:print(10,25,"Ball-1",nero)
screen:print(10,35,"Ball-2",nero)
screen:print(10,45,"Ball-3",nero)
screen:print(10,55,"Ball-4",nero)
screen:print(10,65,"Ball-5",nero)
screen:print(10,75,"Ball-6",nero)
screen:print(10,85,"Ball-7",nero)
screen:print(10,95,"Ball-8",nero)
screen:print(10,105,"Ball-9",nero)
screen:print(10,115,"Ball-10",nero)
screen:print(10,125,"Ball-11",nero)
screen:print(10,135,"Ball-12",nero)
screen:print(10,145,"Ball-13",nero)
screen:print(10,155,"Ball-14",nero)
screen:print(10,165,"Ball-15",nero)
screen:print(10,175,"Ball-16",nero)
screen:print(10,185,"Ball-17",nero)
screen:print(10,195,"Ball-18",nero)
screen:print(10,205,"Ball-19",nero)
screen:print(10,215,"Ball-20",nero)

if Selected==20 then screen:print(10,25,"Ball-1",rosso) end
if Selected==30 then screen:print(10,35,"Ball-2",rosso) end
if Selected==40 then screen:print(10,45,"Ball-3",rosso) end
if Selected==50 then screen:print(10,55,"Ball-4",rosso) end
if Selected==60 then screen:print(10,65,"Ball-5",rosso) end
if Selected==70 then screen:print(10,75,"Ball-6",rosso) end
if Selected==80 then screen:print(10,85,"Ball-7",rosso) end
if Selected==90 then screen:print(10,95,"Ball-8",rosso) end
if Selected==100 then screen:print(10,105,"Ball-9",rosso) end
if Selected==110 then screen:print(10,115,"Ball-10",rosso) end
if Selected==120 then screen:print(10,125,"Ball-11",rosso) end
if Selected==130 then screen:print(10,135,"Ball-12",rosso) end
if Selected==140 then screen:print(10,145,"Ball-13",rosso) end
if Selected==150 then screen:print(10,155,"Ball-14",rosso) end
if Selected==160 then screen:print(10,165,"Ball-15",rosso) end
if Selected==170 then screen:print(10,175,"Ball-16",rosso) end
if Selected==180 then screen:print(10,185,"Ball-17",rosso) end
if Selected==190 then screen:print(10,195,"Ball-18",rosso) end
if Selected==200 then screen:print(10,205,"Ball-19",rosso) end
if Selected==210 then screen:print(10,215,"Ball-20",rosso) end


if Selected==20 then screen:blit(280,120,ba1) end
if Selected==30 then screen:blit(280,120,ba2) end
if Selected==40 then screen:blit(280,120,ba3) end
if Selected==50 then screen:blit(280,120,ba4) end
if Selected==60 then screen:blit(280,120,ba5) end
if Selected==70 then screen:blit(280,120,ba6) end
if Selected==80 then screen:blit(280,120,ba7) end
if Selected==90 then screen:blit(280,120,ba8) end
if Selected==100 then screen:blit(280,120,ba9) end
if Selected==110 then screen:blit(280,120,ba10) end
if Selected==120 then screen:blit(280,120,ba11) end
if Selected==130 then screen:blit(280,120,ba12) end
if Selected==140 then screen:blit(280,120,ba13) end
if Selected==150 then screen:blit(280,120,ba14) end
if Selected==160 then screen:blit(280,120,ba15) end
if Selected==170 then screen:blit(280,120,ba16) end
if Selected==180 then screen:blit(280,120,ba17) end
if Selected==190 then screen:blit(280,120,ba18) end
if Selected==200 then screen:blit(280,120,ba19) end
if Selected==210 then screen:blit(280,120,ba20) end
 
  
if Selected==20 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(1)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end 
if Selected==30 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(2)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==40 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(3)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==50 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(4)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==60 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(5)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==70 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(6)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==80 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(7)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==90 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(8)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==100 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(9)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==110 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(10)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end


if Selected==120 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(11)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end 
if Selected==130 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(12)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==140 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(13)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==150 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(14)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==160 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(15)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==170 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(16)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==180 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(17)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==190 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(18)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==200 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(19)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end
if Selected==210 and pad:cross() then System.copyFile("SYSTEM/resources/balls/ball(20)/ball.png","SYSTEM/resources/balls/usedball/ball.png",0) end



if L==0 then if Selected==120 then Selected=110 end
             if Selected==10 then Selected=20 end
             end

if L==1 then if Selected==130 then Selected=120 end
             if Selected==10 then Selected=20 end
             end

if L==2 then if Selected==140 then Selected=130 end
             if Selected==10 then Selected=20 end
             end

if L==3 then if Selected==150 then Selected=140 end
             if Selected==10 then Selected=20 end
             end

if L==4 then if Selected==160 then Selected=150 end
             if Selected==10 then Selected=20 end
             end

if L==5 then if Selected==170 then Selected=160 end
             if Selected==10 then Selected=20 end
             end

if L==6 then if Selected==180 then Selected=170 end
             if Selected==10 then Selected=20 end
             end

if L==7 then if Selected==190 then Selected=180 end
             if Selected==10 then Selected=20 end
             end

if L==8 then if Selected==220 then Selected=210 end
             if Selected==10 then Selected=20 end
             end



if pad:cross() then set = set + 1 end
if set>0 and set<20 then screen:print(10,230,"Ball successfully replaced !!",rosso) end
if set>0 and set<20 then set1=set1+1 end
if set1==80 then set=0 end
if set1==80 then set1=0 end


screen:print(10,250,"Press O to GO BACK",rosso)
if pad:circle() then dofile("SYSTEM/resources/options/options.lua") end


screen.waitVblankStart()
screen.flip()
screen:clear()
end













