--888_______888___8888888___888888888888___888888888888_______8888____________88888______88_______888
--888_______888___8888888___888888888888___888888888888_______8888__________888888888____88_______888
--_888______88____8888888___888888888888___888888888888______888888________8888888888____88_______888
--_888_____888______888__________88_____________88___________888888_______8888_____88____88_______888
--_888_____888______888__________88_____________88___________88__88_______888____________88_______888
--__88_____88_______888__________88_____________88__________888__888______888____________88_______888
--__888___888_______888__________88_____________88__________888__888______88_____________888888888888
--__888___888_______888__________88_____________88__________88____888____888_____________888888888888
--___88___88________888__________88_____________88_________888____888_____88_____________888888888888
--___888_888________888__________88_____________88_________8888888888_____888____________88_______888
--___8888888________888__________88_____________88_________88888888888____888____________88_______888
--____88888_________888__________88_____________88________888888888888____8888_____88____88_______888
--____88888_______8888888________88_____________88________888______888_____8888888888____88_______888
--_____8888_______8888888________88_____________88_______888________888_____888888888____88_______888
--_____888________8888888________88_____________88_______888________888_______88888______88_______888

fonmenu= Image.load("data/img/fonmenu.jpg")
souris = Image.load("data/img/souris1.png")
souris2 = Image.load("data/img/souris2.png")
--souris3 = Image.load("data/img/souris3.png")
kn=Image.load("data/img/kn.png")
kn2=Image.load("data/img/kn2.png")
plane=Image.load("data/img/plane.png")
zagol=Image.load("data/img/zagol.png")
gm=Image.load("data/img/gm.png")
menu=Image.load("data/img/menu.png")
function nill()
kn=nil
kn2=nil
zagol=nil
end
local mk={5}
local ml={5}
file=io.open("data/makesave/save.msn","r")
mk[1]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save2.msn","r")
ml[1]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save3.msn","r")
mk[2]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save4.msn","r")
ml[2]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save5.msn","r")
mk[3]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save6.msn","r")
ml[3]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save7.msn","r")
mk[4]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save8.msn","r")
ml[4]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save9.msn","r")
mk[5]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save10.msn","r")
ml[5]=tonumber(file:read())
file:close()
file=io.open("data/makesave/save11.msn","r")
New_Game=file:read()
file:close()
file=io.open("data/makesave/save12.msn","r")
Settings=file:read()
file:close()
file=io.open("data/makesave/save13.msn","r")
About=file:read()
file:close()
file=io.open("data/makesave/save14.msn","r")
Exit=file:read()
file:close()
file=io.open("data/makesave/save15.msn","r")
NewsGame=file:read()
file:close()
file=io.open("data/makesave/save16.msn","r")
Settingss=file:read()
file:close()
file=io.open("data/makesave/save17.msn","r")
Abouts=file:read()
file:close()
file=io.open("data/nastroi/mensam.cpp","r")
mensam=file:read()
file:close()
file=io.open("data/nastroi/fon.cpp","r")
fons=file:read()
file:close()
function sansAccents (texte)
nomaffiche = string.gsub(texte, "e", "e")
nomaffiche = string.gsub(nomaffiche, "e", "e")
nomaffiche = string.gsub(nomaffiche, "a", "a")
nomaffiche = string.gsub(nomaffiche, "c", "c")
nomaffiche = string.gsub(nomaffiche, "e", "e")
nomaffiche = string.gsub(nomaffiche, "î", "i")
nomaffiche = string.gsub(nomaffiche, "€", "E")
nomaffiche = string.gsub(nomaffiche, "ñ", "n")
nomaffiche = string.gsub(nomaffiche, "ù", "u")
return nomaffiche
end

font = Font.load("data/font/qwe.ttf")
font:setPixelSizes(20,20)
font10 = Font.load("data/font/qwe.ttf")
font10:setPixelSizes(20,25)
font11 = Font.load("data/font/qwe.ttf")
font11:setPixelSizes(20,17)
font2 = Font.load("data/font/qwe.ttf")
font2:setPixelSizes(50,50)

function save()
file=io.open("data/makesave/save.msn","w")
file:write(mk[1])
file:close()
file=io.open("data/makesave/save2.msn","w")
file:write(ml[1])
file:close()
file=io.open("data/makesave/save3.msn","w")
file:write(mk[2])
file:close()
file=io.open("data/makesave/save4.msn","w")
file:write(ml[2])
file:close()
file=io.open("data/makesave/save5.msn","w")
file:write(mk[3])
file:close()
file=io.open("data/makesave/save6.msn","w")
file:write(ml[3])
file:close()
file=io.open("data/makesave/save7.msn","w")
file:write(mk[4])
file:close()
file=io.open("data/makesave/save8.msn","w")
file:write(ml[4])
file:close()
file=io.open("data/makesave/save9.msn","w")
file:write(mk[5])
file:close()
file=io.open("data/makesave/save10.msn","w")
file:write(ml[5])
file:close()
end

Mp3me.stop()
Mp3me.load("data/sound/1.mp3")
Mp3me.play()

white=Color.new(255,255,255)
red=Color.new(255,0,0)
black=Color.new(0,0,0)
blue=Color.new(81,188,255)

x = 240
y = 136
qupe=0
pizd=0
bb=0
vv=0
vvv=0
p=0
o=0
oo=0
i=0
m=0
l=0
ll=0
z=0
r=0
u=0
zz=0
c=0
tt=1
xx=-60
yy=247
xxx=-60
pl=0
pll=0
bu=0
buu=0
stu=0
qr=1
zxz=0
vb=0
qupe=0
s=272
ss=-61
ii=0
iii=0
iiii=0
local pin={5}
local masx={4}
local masy={4}
masy[1]=40
masx[1]=-20

for i=1,5 do--dlia proverki stolknovenii
pin[i]=0
end

function gen()
if tonumber(mensam)>=1 then
for i=2,tonumber(mensam) do --da sobsno i sozdau uroven dlia samoleta
m = math.random(50,60)
l = math.random(50,200)
masx[i]=masx[i-1]-l
masy[i]=masy[i-1]+m
end
i=1
end
end

while true do
if l==0 then
gen()
end
if tonumber(mensam)>=1 then
if masx[tonumber(mensam)]+vb<480 then
vb=vb+3
else
vb=0
gen()
end
end
screen:clear()
pad = Controls.read()
if pad:l() and pad:down() then
file=io.open("data/lang/lang.ini","w")
file:write(0)
file:close()
end
if pad:select() then
file=io.open("data/makesave/screenshoter.msn","r")
nscreen=tonumber(file:read())
file:close()
screen:save("data/screenshot/SHOT"..nscreen..".png")
nscreen=nscreen+1
file=io.open("data/makesave/screenshoter.msn","w")
file:write(math.ceil(nscreen))
file:close()
end
if c+480>=0 then
c=c-tonumber(fons)
else
c=0
end
screen:blit(0,0,fonmenu)
--screen:blit(c+480,0,fonmenu)
--screen:fontPrint(font2,90,50,"Run!Stick!Run!",rnd)
if qupe==1 then
screen:blit(0,ss,gm)--raspechatka kruzka GM
if pad:circle() and x>=0 and x<=60 and y>=0 and y<=61 then
font=nil
nill()
dofile("data/scripts/gm.ttf")
end
end
Image:blit(mk[1],ml[1],zagol)--zagolovok
if tonumber(mensam)>=1 then
for i=1,tonumber(mensam) do--raspechativau bliat))
screen:blit(masx[i]+vb,masy[i],plane)
end
end
if qr==1 then
screen:blit(mk[2]-10,ml[2]-10,kn2)
if mk[2]>=480 and ml[2]>=272 then
qr=qr+1
else
if pad:cross() then
Mp3me.stop()
screen:clear()
font=nil
nill()
dofile(NewsGame)
end
end
else
screen:blit(mk[2],ml[2],kn)
end
if qr==2 then
screen:blit(mk[3]-10,ml[3]-10,kn2)
if mk[3]>=480 and ml[3]>=272 then
qr=qr+1
else
if pad:cross() then
font=nil
nill()
dofile(Settingss)
end
end
else
screen:blit(mk[3],ml[3],kn)
end
if qr==3 then
screen:blit(mk[4]-10,ml[4]-10,kn2)
if mk[4]>=480 and ml[4]>=272 then
qr=qr+1
else
if pad:cross() then
font=nil
nill()
dofile(Abouts)
end
end
else
screen:blit(mk[4],ml[4],kn)
end
if qr==4 then
if mk[5]>=480 and ml[5]>=272 then
qr=qr+1
else
if pad:cross() then
System.Quit()
end
end
screen:blit(mk[5]-10,ml[5]-10,kn2)
else
screen:blit(mk[5],ml[5],kn)
end
screen:fontPrint(font,mk[2]+27,ml[2]+27,New_Game,red)
screen:fontPrint(font,mk[3]+33,ml[3]+27,Settings,red)
screen:fontPrint(font,mk[4]+37,ml[4]+27,About,red)
screen:fontPrint(font,mk[5]+53,ml[5]+27,Exit,red)
if pad:down() and oldpad:down()~=pad:down() then
qr=qr+1
end
if pad:up() and oldpad:up()~=pad:up() then
qr=qr-1
end
if qr>4 then
qr=1
end
if qr<1 then
qr=4
end

--menuchka

if pad:start() and oldpad:start()~=pad:start() then--vkluchenie menu
qupe=1
x = 240
y = 136
end
if qupe==1 then
if s>246 then
s=s-2
end
if ss<-1 then
ss=ss+4
end
screen:blit(0,s,menu)

if x>=mk[1] and x<=mk[1]+160 and y>=ml[1] and y<=ml[1]+26 then
if pad:circle() and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 then
pin[1]=1
if x>=0 and x<=27 and y>=248 and y<=270 then--udalenie
mk[1]=500
ml[1]=300
save()
else -- inache peremeshenie
mk[1]=math.ceil(x-20)--80
ml[1]=math.ceil(y-10)--13
screen:fontPrint(font11,200,264,"x= " .. mk[1],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[1],blue)
end
end
else
pin[1]=0
end
if x>=mk[2] and x<=mk[2]+150 and y>=ml[2] and y<=ml[2]+40 then
if pad:square() then--pereimenovka
New_Game= System.startOSK(New_Game,"Vvedite")
file=io.open("data/makesave/save11.msn","w")
file:write(New_Game)
file:close()
end
if pad:triangle() then--perenaznachenie
NewsGame= System.startOSK(NewsGame,"Vvedite")
file=io.open("data/makesave/save15.msn","w")
file:write(NewsGame)
file:close()
end
if pad:circle() and pin[1]==0 and pin[3]==0 and pin[4]==0 and pin[5]==0 then--udalenie
pin[2]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[2]=500
ml[2]=300
save()
else--inache peremeshenie
mk[2]=math.ceil(x-20)--75
ml[2]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[2],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[2],blue)
end
end
else
pin[2]=0
end
if x>=mk[3] and x<=mk[3]+150 and y>=ml[3] and y<=ml[3]+40 then
if pad:square() then--pereimenovka
Settings= System.startOSK(Settings,"Vvedite")
file=io.open("data/makesave/save12.msn","w")
file:write(Settings)
file:close()
end
if pad:triangle() then--perenaznachenie
Settingss= System.startOSK(Settingss,"Vvedite")
file=io.open("data/makesave/save16.msn","w")
file:write(Settingss)
file:close()
end
if pad:circle() and pin[2]==0 and pin[1]==0 and pin[4]==0 and pin[5]==0 then--udalenie
pin[3]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[3]=500
ml[3]=300
save()
else--inache peremeshenie
mk[3]=math.ceil(x-20)--75
ml[3]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[3],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[3],blue)
end
end
else
pin[3]=0
end
if x>=mk[4] and x<=mk[4]+150 and y>=ml[4] and y<=ml[4]+40 then
if pad:square() then--pereimenovka
About= System.startOSK(About,"Vvedite")
file=io.open("data/makesave/save13.msn","w")
file:write(About)
file:close()
end
if pad:triangle() then--perenaznachenie
Abouts= System.startOSK(Abouts,"Vvedite")
file=io.open("data/makesave/save17.msn","w")
file:write(Abouts)
file:close()
end
if pad:circle() and pin[2]==0 and pin[3]==0 and pin[1]==0 and pin[5]==0 then--udalenie
pin[4]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[4]=500
ml[4]=300
save()
else--inache peremeshenie
mk[4]=math.ceil(x-20)--75
ml[4]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[4],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[4],blue)
end
end
else
pin[4]=0
end
if x>=mk[5]and x<=mk[5]+150 and y>=ml[5] and y<=ml[5]+40 then
if pad:square() then--pereimenovka
Exit= System.startOSK(Exit,"Vvedite")
file=io.open("data/makesave/save14.msn","w")
file:write(Exit)
file:close()
end
if pad:circle() and pin[2]==0 and pin[3]==0 and pin[4]==0 and pin[1]==0 then--udalenie
pin[5]=1
if x>=0 and x<=27 and y>=248 and y<=270 then
mk[5]=500
ml[5]=300
save()
else--inache peremeshenie
mk[5]=math.ceil(x-20)--75
ml[5]=math.ceil(y-20)--20
screen:fontPrint(font11,200,264,"x= " .. mk[5],blue)
screen:fontPrint(font11,280,264,"y= " .. ml[5],blue)
end
end
else
pin[5]=0
end

if System.powerIsPowerOnline() then 
zaradbat=zaradbat+1
if zaradbat>=1 then screen:blit(430,s+2,bat14) end
if zaradbat>=10 then screen:blit(430,s+2,bat15) end
if zaradbat>=20 then screen:blit(430,s+2,bat16) end
if zaradbat>=30 then screen:blit(430,s+2,bat17) end
if zaradbat>=40 then screen:blit(430,s+2,bat18) end
if zaradbat>=50 then screen:blit(430,s+2,bat19) end
if zaradbat>=60 then screen:blit(430,s+2,bat20) end
if zaradbat>=70 then screen:blit(430,s+2,bat21) end
if zaradbat>=80 then screen:blit(430,s+2,bat22) end
if zaradbat>=90 then screen:blit(430,s+2,bat23) end
if zaradbat>=100 then screen:blit(430,s+2,bat24) end
if zaradbat>=110 then screen:blit(430,s+2,bat25) end
if zaradbat>=120 then screen:blit(430,s+2,bat26) end
if zaradbat>=130 then zaradbat=1 end
else
zaradbat=1
if System.powerGetBatteryLifePercent() >= 0 and System.powerGetBatteryLifePercent() <=4 then screen:blit(430,s+2,bat0) end
if System.powerGetBatteryLifePercent() > 4 then screen:blit(432,s+2,bat1) end
if System.powerGetBatteryLifePercent() > 8 then screen:blit(432,s+2,bat2) end
if System.powerGetBatteryLifePercent() > 16 then screen:blit(432,s+2,bat3) end
if System.powerGetBatteryLifePercent() > 24 then screen:blit(432,s+2,bat4) end
if System.powerGetBatteryLifePercent() > 32 then screen:blit(432,s+2,bat5) end
if System.powerGetBatteryLifePercent() > 40 then screen:blit(432,s+2,bat6) end
if System.powerGetBatteryLifePercent() > 48 then screen:blit(432,s+2,bat7) end
if System.powerGetBatteryLifePercent() > 56 then screen:blit(432,s+2,bat8) end
if System.powerGetBatteryLifePercent() > 64 then screen:blit(432,s+2,bat9) end
if System.powerGetBatteryLifePercent() > 72 then screen:blit(432,s+2,bat10) end
if System.powerGetBatteryLifePercent() > 80 then screen:blit(432,s+2,bat11) end
if System.powerGetBatteryLifePercent() > 88 then screen:blit(432,s+2,bat12) end
if System.powerGetBatteryLifePercent() > 96 then screen:blit(432,s+2,bat13) end
end
screen:fontPrint(font10,365,s+22,System.getTime(1).." : "..System.getTime(2),blue)
screen:blit(x,y,souris)
end
if x>=450 and x<=471 and y>=248 and y<=269 then--vikluchenie menu
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"otkluchenie",blue)
else
screen:fontPrint(font11,200,266,"disconnection",blue)
end
if pad:circle() then
s=272
ss=-61
x=0
y=0
qupe=0
end
end
if pad:select() and qupe==1 then
s=272
ss=-61
x=0
y=0
qupe=0
end
if x>=51 and x<=72 and y>=248 and y<=269 then--sohranenie
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"sohranenie",blue)
else
screen:fontPrint(font11,200,266,"save",blue)
end
if pad:circle() and qupe==1 then 
save()
end
end
if x>=143 and x<=163 and y>=248 and y<=269 then--otmena
screen:blit(x,y,souris2)
if lang==2 then
screen:fontPrint(font11,200,266,"otmena",blue)
else
screen:fontPrint(font11,200,266,"cancel",blue)
end
if pad:circle() and qupe==1 then
mk[1]=117
ml[1]=15
mk[2]=167
ml[2]=70
mk[3]=167
ml[3]=120
mk[4]=167
ml[4]=175
mk[5]=167
ml[5]=225
save()
end
end
if x>=90 and x<=118 and y>=248 and y<=269 then--notepad
screen:blit(x,y,souris2)
screen:fontPrint(font11,200,266,"lua edit",blue)
if pad:circle() and qupe==1 then
font=nil
nill()
dofile("data/Notepad/Notepad.dat")
end
end
if qupe==1 then
if x>=0 and x<=60 and y>=0 and y<=61 then
screen:blit(x,y,souris2)
end
end
screen:flip()
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 32;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 32;
end
if x < 0 then x = 0 elseif x + souris:width() > 480 then x = 480 -  souris:width() end
if y < 0 then y = 0 elseif y + souris:height() > 272 then y = 268 -  souris:width() end
oldpad=pad
end

--888_______888___8888888___888888888888___888888888888_______8888____________88888______88_______888
--888_______888___8888888___888888888888___888888888888_______8888__________888888888____88_______888
--_888______88____8888888___888888888888___888888888888______888888________8888888888____88_______888
--_888_____888______888__________88_____________88___________888888_______8888_____88____88_______888
--_888_____888______888__________88_____________88___________88__88_______888____________88_______888
--__88_____88_______888__________88_____________88__________888__888______888____________88_______888
--__888___888_______888__________88_____________88__________888__888______88_____________888888888888
--__888___888_______888__________88_____________88__________88____888____888_____________888888888888
--___88___88________888__________88_____________88_________888____888_____88_____________888888888888
--___888_888________888__________88_____________88_________8888888888_____888____________88_______888
--___8888888________888__________88_____________88_________88888888888____888____________88_______888
--____88888_________888__________88_____________88________888888888888____8888_____88____88_______888
--____88888_______8888888________88_____________88________888______888_____8888888888____88_______888
--_____8888_______8888888________88_____________88_______888________888_____888888888____88_______888
--_____888________8888888________88_____________88_______888________888_______88888______88_______888