--888888__8888__888___88____888____88
--88_______88___888___88____888____88
--88_______88___8888__88____8_8____88
--88_______88___88_8__88___88_88___88
--888888___88___88__8_88___88__8___88
--88_______88___88__8888___8___8___88
--88_______88___88___888__8888888__88
--88_______88___88___888__88___88__88
--88______8888__88____88_88_____88_888888

fin=Image.load("data/img/fin.png")--zagruzka kartinki na vremennuu peremennuu
m19=Image.load("data/img/m1911.png")--zagruzka kartinki na vremennuu peremennuu
perso=Image.load("data/pers/perso.png")--zagruzka kartinki na vremennuu peremennuu
bos=Image.load("data/pers/bos.png")--zagruzka kartinki na vremennuu peremennuu
perso2=Image.load("data/pers/perso2.png")--zagruzka kartinki na vremennuu peremennuu
mini=Image.load("data/img/mini.png")--zagruzka kartinki na vremennuu peremennuu
pul=Image.load("data/img/pul2.png")--zagruzka kartinki na vremennuu peremennuu
zombie=Image.load("data/pers/zombie.png")--zagruzka kartinki na vremennuu peremennuu
zombie2=Image.load("data/pers/zombie2.png")--zagruzka kartinki na vremennuu peremennuu
life=Image.load("data/img/life.png")--zagruzka kartinki na vremennuu peremennuu
kub=Image.load("data/img/01.png")--zagruzka kartinki na vremennuu peremennuu
hper=Image.load("data/img/hp.png")--zagruzka kartinki na vremennuu peremennuu
hper2=Image.load("data/img/hp2.png")--zagruzka kartinki na vremennuu peremennuu
hp01=Image.load("data/img/hp/hp01.png")--zagruzka kartinki na vremennuu peremennuu
hp02=Image.load("data/img/hp/hp02.png")--zagruzka kartinki na vremennuu peremennuu
hp03=Image.load("data/img/hp/hp03.png")--zagruzka kartinki na vremennuu peremennuu
hp04=Image.load("data/img/hp/hp04.png")--zagruzka kartinki na vremennuu peremennuu
hp05=Image.load("data/img/hp/hp05.png")--zagruzka kartinki na vremennuu peremennuu
hp06=Image.load("data/img/hp/hp06.png")--zagruzka kartinki na vremennuu peremennuu
hp07=Image.load("data/img/hp/hp07.png")--zagruzka kartinki na vremennuu peremennuu
hp08=Image.load("data/img/hp/hp08.png")--zagruzka kartinki na vremennuu peremennuu
hp09=Image.load("data/img/hp/hp09.png")--zagruzka kartinki na vremennuu peremennuu
hp10=Image.load("data/img/hp/hp10.png")--zagruzka kartinki na vremennuu peremennuu
hp11=Image.load("data/img/hp/hp11.png")--zagruzka kartinki na vremennuu peremennuu
hp12=Image.load("data/img/hp/hp12.png")--zagruzka kartinki na vremennuu peremennuu
hp13=Image.load("data/img/hp/hp13.png")--zagruzka kartinki na vremennuu peremennuu
hp14=Image.load("data/img/hp/hp14.png")--zagruzka kartinki na vremennuu peremennuu
hp15=Image.load("data/img/hp/hp15.png")--zagruzka kartinki na vremennuu peremennuu
hp16=Image.load("data/img/hp/hp16.png")--zagruzka kartinki na vremennuu peremennuu
udar=Image.load("data/img/udar.png")--zagruzka kartinki na vremennuu peremennuu

file=io.open("data/nastroi/poy.CPP","r")--otkritie storonnego faila
poy=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/kolvo.CPP","r")--otkritie storonnego faila
kolvo=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/skpul.CPP","r")--otkritie storonnego faila
skpul=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/gun.CPP","r")--otkritie storonnego faila
gunkol=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/shut.CPP","r")--otkritie storonnego faila
shut=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/save.CPP","r")--otkritie storonnego faila
peremennay=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/bright.CPP","r")--otkritie storonnego faila
bright=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/chislo.CPP","r")--otkritie storonnego faila
chislo=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/left.CPP","r")--otkritie storonnego faila
left=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/right.CPP","r")--otkritie storonnego faila
right=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania
file=io.open("data/nastroi/fire.CPP","r")--otkritie storonnego faila
er=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania

font = Font.load("data/font/qwe3.ttf")--podgruzka chrifta
font:setPixelSizes(30,20)--zadanie razmera chriftu
font4 = Font.load("data/font/qwe3.ttf")--podgruzka chrifta
font4:setPixelSizes(30,10)--zadanie razmera chriftu
font40 = Font.load("data/font/qwe3.ttf")--podgruzka chrifta
font40:setPixelSizes(40,20)--zadanie razmera chriftu

local masbx={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local masby={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local masbxb={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local masbyb={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local masbxbx={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local masbyby={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local han={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local ham={tonumber(chislo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local gunx={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local guny={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local hphp={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local hh={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local hhh={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local hhhh={tonumber(kolvo)}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local pina={3}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov
local pinas={3}--sozdanie odnomernogo massiva v kotorom opredelennoe mnou ranee chislo elementov

pinas[1]=0--prisvaivanie elementam ih znachenii
pinas[2]=0--prisvaivanie elementam ih znachenii
pinas[3]=0--prisvaivanie elementam ih znachenii
pina[1]=0--prisvaivanie elementam ih znachenii
pina[2]=255--prisvaivanie elementam ih znachenii
pina[3]=255--prisvaivanie elementam ih znachenii
masby[1]=-31--prisvaivanie elementam ih znachenii
x=240--prisvaivanie elementam ih znachenii
y=230--prisvaivanie elementam ih znachenii
t=0--prisvaivanie elementam ih znachenii
tt=0--prisvaivanie elementam ih znachenii
zz=0--prisvaivanie elementam ih znachenii
zizn=17--prisvaivanie elementam ih znachenii
zizni=17--prisvaivanie elementam ih znachenii
zb=0--prisvaivanie elementam ih znachenii
qr=1--prisvaivanie elementam ih znachenii
mll=125--prisvaivanie elementam ih znachenii
mnn=76--prisvaivanie elementam ih znachenii
pizd=0--prisvaivanie elementam ih znachenii
c=-272--prisvaivanie elementam ih znachenii
bosx=190--prisvaivanie elementam ih znachenii
bosy=-80--prisvaivanie elementam ih znachenii

for i=1,chislo do--podgotovka dannih
masbyb[i]=-11--prisvaivanie elementam ih znachenii
masbyby[i]=-16--prisvaivanie elementam ih znachenii
hhh[i]=0--prisvaivanie elementam ih znachenii
hhhh[i]=0--prisvaivanie elementam ih znachenii
hphp[i]=0--prisvaivanie elementam ih znachenii
han[i]=0--prisvaivanie elementam ih znachenii
ham[i]=0--prisvaivanie elementam ih znachenii
end

for h=1,tonumber(kolvo) do--ustal ia ne hochu pisat,no tut voobchem dlia pulek
gunx[h]=-20--prisvaivanie elementam ih znachenii
guny[h]=-20--prisvaivanie elementam ih znachenii
hh[h]=0--prisvaivanie elementam ih znachenii
end
h=1--prisvaivanie elementam ih znachenii

for i=2,chislo do--generacia zombie
r=math.random(30,60)
k=math.random(100,250)
p=math.random(1,10)
pp=math.random(1,15)
masbx[i]=math.random(0,450)
masby[i]=masby[i-1]-r
if p==1 or p==4 then
masbxb[i]=math.random(0,460)
masbyb[i]=masbyb[i-1]-k
han[i]=1
end
if pp==1 or pp==4 or pp==8 then
masbxbx[i]=math.random(0,460)
masbyby[i]=masbyby[i-1]-k
ham[i]=1
end
end

function nill()
udar=nil
opng=nil
hp01=nil
hp02=nil
hp03=nil
hp04=nil
hp05=nil
hp06=nil
hp07=nil
hp08=nil
hp09=nil
hp10=nil
hp11=nil
hp12=nil
hp13=nil
hp14=nil
hp15=nil
hp16=nil
fin=nil
m19=nil
perso=nil
perso2=nil
mini=nil
pul=nil
zombie=nil
zombie2=nil
font=nil
font4=nil
font40=nil
end

function cleare()
for i=1,chislo do
masby[i]=-400
end
end

function fire1()--strelba
if tonumber(gunkol)>0 then
gunkol=gunkol-1
if h<tonumber(kolvo) then
h=h+1
else
h=1
end
guny[h]=y-10
gunx[h]=x+12
hh[h]=0--dolgo dumal kak ispravit ochibku,i v itoge dobavil etu stroku,htia ne ponimau zachem ona,no ona rabotaet !))
end
end

while true do--zapusk igrovogo cikla
screen:clear()--ochistka ekrana
pad = Controls.read()--podgruzka knopok psp
if pizd==0 then--igrovoi process
if pina[2]>0 and pinas[2]==0 then--perelivanie bukv
pina[2]=pina[2]-bright
black=Color.new(pina[1],pina[2],pina[3])
elseif pina[1]<255 and pinas[1]==0 then
pinas[2]=1
pina[1]=pina[1]+bright
black=Color.new(pina[1],pina[2],pina[3])
elseif pina[3]>0 and pinas[3]==0 then
pinas[1]=1
pina[3]=pina[3]-bright
black=Color.new(pina[1],pina[2],pina[3])
elseif pina[2]<255 and pinas[2]==1 then
pinas[3]=1
pina[2]=pina[2]+bright
black=Color.new(pina[1],pina[2],pina[3])
elseif pina[1]>0 and pinas[1]==1 then
pina[1]=pina[1]-bright
black=Color.new(pina[1],pina[2],pina[3])
elseif pina[3]<255 and pinas[3]==1 then
pina[3]=pina[3]+bright
black=Color.new(pina[1],pina[2],pina[3])
else
pinas[1]=0
pinas[2]=0
pinas[3]=0
pina[1]=0
pina[2]=255
pina[3]=255
end
if zb<10 then
zb=zb+1
else
zb=0
end

if c<0 then--peremechenie fona
c=c+0.3
else
c=-272
end

screen:blit(0,math.ceil(c),fin)--fon
screen:blit(0,math.ceil(c)+272,fin)--fon

for i=1,chislo do--proverka ubivania puliami
if gunx[h]>=masbx[tonumber(chislo)] and gunx[h]+4<=masbx[tonumber(chislo)]+36 and guny[h]+hh[h]<=masby[tonumber(chislo)] and guny[h]+hh[h]>=masby[tonumber(chislo)]-30 then--uslovie popadania puliami
hphp[tonumber(chislo)]=hphp[tonumber(chislo)]+1--otnimanie HP protivnika
guny[h]=-400--ubiranie s ekrana puli
hh[h]=0--HZ zachem eto =)
if hphp[tonumber(chislo)]>=2 then
zz=zz+1--nachislenie ochkov
masby[tonumber(chislo)]=500--ubiranie s ekrana zombie
hphp[tonumber(chislo)]=0
end
else
if gunx[h]>=masbx[i] and gunx[h]+4<=masbx[i]+36 and guny[h]+hh[h]<=masby[i] and guny[h]+hh[h]>=masby[i]-30 then--uslovie popadania puliami
hphp[i]=hphp[i]+1--otnimanie HP protivnika
guny[h]=-400--ubiranie s ekrana puli
hh[h]=0--HZ zachem eto =)
if hphp[i]>=2 then
zz=zz+1--nachislenie ochkov
masby[i]=350--ubiranie s ekrana zombie
hphp[i]=0
end
end
end
if masby[i]<310 then
masby[i]=masby[i]+0.8--peremechenie zombei
else
masby[i]=500
end
if han[i]==1 then--sbor pulek
if x>=masbxb[i]-10 and x<=masbxb[i]+20 and (masbyb[i]+hhh[i])+10>=y and masbyb[i]+hhh[i]<=y+60 then
gunkol=gunkol+20--popolnenie patronov
hhh[i]=-400
end
if masbyb[i]+hhh[i]<300 then
hhh[i]=hhh[i]+0.8--XZ
else
hhh[i]=-400
end
screen:blit(masbxb[i],masbyb[i]+hhh[i],kub)--boepripasi
end
if ham[i]==1 then--sbor HP
if x>=masbxbx[i]-10 and x<=masbxbx[i]+20 and (masbyby[i]+hhhh[i])+16>=y and masbyby[i]+hhhh[i]<=y+60 then
zizn=20
hhhh[i]=-400
end
if masbyby[i]+hhhh[i]<300 then
hhhh[i]=hhhh[i]+0.8--XZ
else
hhhh[i]=-400
end
screen:blit(masbxbx[i],masbyby[i]+hhhh[i],life)--aptechka
end
if zb<=5 then--hodba zombei
screen:blit(masbx[i],masby[i],zombie)
else
screen:blit(masbx[i],masby[i],zombie2)
end
if hphp[i]==0 then
screen:blit(masbx[i]+5,masby[i]-5,hper)
else
screen:blit(masbx[i]+5,masby[i]-5,hper2)
end
end

if math.ceil(masby[tonumber(chislo)])>=500 then--BOSS FINAL
screen:blit(bosx,bosy,bos)
if gunx[h]>=bosx and gunx[h]+4<=bosx+92 and guny[h]+hh[h]<=bosy and guny[h]+hh[h]>=bosy-80 then
zizni=zizni-0.5--otnimanie ziznei u bosa
zz=zz+1
guny[h]=-400
hh[h]=0
end
if zizni==17 then
screen:blit(bosx+35,bosy-5,hper)
elseif zizni>=16 then
screen:blit(bosx+35,bosy-5,hp01)
elseif zizni>=15 then
screen:blit(bosx+35,bosy-5,hp02)
elseif zizni>=14 then
screen:blit(bosx+35,bosy-5,hp03)
elseif zizni>=13 then
screen:blit(bosx+35,bosy-5,hp04)
elseif zizni>=12 then
screen:blit(bosx+35,bosy-5,hp05)
elseif zizni>=11 then
screen:blit(bosx+35,bosy-5,hp06)
elseif zizni>=10 then
screen:blit(bosx+35,bosy-5,hp07)
elseif zizni>=9 then
screen:blit(bosx+35,bosy-5,hp08)
elseif zizni>=8 then
screen:blit(bosx+35,bosy-5,hp09)
elseif zizni>=7 then
screen:blit(bosx+35,bosy-5,hp10)
elseif zizni>=6 then
screen:blit(bosx+35,bosy-5,hp11)
elseif zizni>=5 then
screen:blit(bosx+35,bosy-5,hp12)
elseif zizni>=4 then
screen:blit(bosx+35,bosy-5,hp13)
elseif zizni>=3 then
screen:blit(bosx+35,bosy-5,hp14)
elseif zizni>=2 then
screen:blit(bosx+35,bosy-5,hp15)
elseif zizni>=1 then
screen:blit(bosx+35,bosy-5,hp16)
end
if bosy+30<=y then--intellekt bosa
bosy=bosy+1
else
bosy=bosy-1
end
if bosx+33<=x then
bosx=bosx+1
else
bosx=bosx-1
end
if bosy+30>=y and bosx+30<=x and bosx+36>=x then
if zizn>0 then
screen:blit(0,0,udar)
zizn=zizn-0.1
else
System.message("YOU DIED!",0)
screen:save("data/img/o.jpg")
opng=Image.load("data/img/o.jpg")
file=io.open("data/nastroi/save.CPP","w")
file:write(math.ceil(zz))
file:close()
bosy=-80
qr=2
pizd=1
end
end
if zizni<=0 then
System.message("YOU WIN! AND BOSS DIED!",0)
file=io.open("data/nastroi/save.CPP","w")
file:write(math.ceil(zz))
file:close()
file=io.open("data/makesave/save24.msn","w")
file:write(6)
file:close()
nill()
dofile("data/load/load.cpp")
end
end

if shut=="1" then
for h=1,tonumber(kolvo) do--strelba pulami
if guny[h]+hh[h]>-10 then
hh[h]=hh[h]-tonumber(skpul)
end
screen:blit(gunx[h],guny[h]+hh[h],pul)
end
end

if t==1 then--raspechatka hodbi persa
tt=tt+1
end
if tt>10 then
t=0
tt=0
end
if tt>=5 and tt<=10 then
screen:blit(x,y,perso2)
else
screen:blit(x,y,perso)
end
if zizn==17 then
screen:blit(x+4,y+55,hper)
elseif zizn>=16 then
screen:blit(x+4,y+55,hp01)
elseif zizn>=15 then
screen:blit(x+4,y+55,hp02)
elseif zizn>=14 then
screen:blit(x+4,y+55,hp03)
elseif zizn>=13 then
screen:blit(x+4,y+55,hp04)
elseif zizn>=12 then
screen:blit(x+4,y+55,hp05)
elseif zizn>=11 then
screen:blit(x+4,y+55,hp06)
elseif zizn>=10 then
screen:blit(x+4,y+55,hp07)
elseif zizn>=9 then
screen:blit(x+4,y+55,hp08)
elseif zizn>=8 then
screen:blit(x+4,y+55,hp09)
elseif zizn>=7 then
screen:blit(x+4,y+55,hp10)
elseif zizn>=6 then
screen:blit(x+4,y+55,hp11)
elseif zizn>=5 then
screen:blit(x+4,y+55,hp12)
elseif zizn>=4 then
screen:blit(x+4,y+55,hp13)
elseif zizn>=3 then
screen:blit(x+4,y+55,hp14)
elseif zizn>=2 then
screen:blit(x+4,y+55,hp15)
elseif zizn>=1 then
screen:blit(x+4,y+55,hp16)
end
screen:blit(x+12,y-8,m19)--pistolet

for i=1,chislo do--proverka stolknovenia
if x>=masbx[i] and x<=masbx[i]+36 and masby[i]+30>=y and masby[i]<=y+60 or masby[i]>=303 and masby[i]<310 then
if zizn>0 then
screen:blit(0,0,udar)
zizn=zizn-0.1
else
System.message("YOU DIED!",0)
qr=2
screen:save("data/img/o.jpg")
opng=Image.load("data/img/o.jpg")
file=io.open("data/nastroi/save.CPP","w")
file:write(math.ceil(zz))
file:close()
pizd=1
end
end
end

screen:blit(0,0,mini)
screen:fontPrint(font,350,22,"SCORE :",black)
screen:fontPrint(font,440,22,math.ceil(zz),black)
screen:fontPrint(font4,350,37,"BEST :",black)
screen:fontPrint(font4,420,37,peremennay,black)
if shut=="1" then
screen:fontPrint(font40,20,30,"GUN :",black)
screen:fontPrint(font40,80,30,math.ceil(tonumber(gunkol)),black)
end

if er=="cross" then
if pad:cross() and oldpad:cross()~=pad:cross() then
fire1()
end
end
if er=="circle" then
if pad:circle() and oldpad:circle()~=pad:circle() then
fire1()
end
end
if er=="square" then
if pad:square() and oldpad:square()~=pad:square() then
fire1()
end
end
if er=="triangle" then
if pad:triangle() and oldpad:triangle()~=pad:triangle() then
fire1()
end
end
if er=="down" then
if pad:down() and oldpad:down()~=pad:down() then
fire1()
end
end
if er=="left" then
if pad:left() and oldpad:left()~=pad:left() then
fire1()
end
end
if er=="right" then
if pad:right() and oldpad:right()~=pad:right() then
fire1()
end
end
if er=="up" then
if pad:up() and oldpad:up()~=pad:up() then
fire1()
end
end
if er=="r" then
if pad:r() and oldpad:r()~=pad:r() then
fire1()
end
end
if er=="l" then
if pad:l() and oldpad:l()~=pad:l() then
fire1()
end
end

if pad:start() then
screen:save("data/img/o.jpg")
opng=Image.load("data/img/o.jpg")
pizd=1
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 pad:up() then
t=1
y =y - 10
elseif pad:down() then
t=1
y =y + 10
elseif pad:left() then
t=1
x =x - 10
elseif pad:right() then
t=1
x =x + 10
elseif math.abs(pad:analogY()) > 32 then
t=1
y = y + pad:analogY() / 32;
elseif math.abs(pad:analogX()) > 32 then
t=1
x = x + pad:analogX() / 32;
else
t=0
tt=0
end
end

if pizd==1 then--zapusk menu
screen:blit(0,0,opng)
screen:blit(mll,mnn,pause)
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>3 then
qr=1
end
if qr<1 then
qr=3
end
if qr==1 then
screen:blit(mll+35,mnn+30,ukaz)
if pad:cross() then
if zizn>1 then
pizd=0
else
qr=2
end
end
end
if qr==2 then
screen:blit(mll+35,mnn+54,ukaz)
if pad:cross() then
file=io.open("data/nastroi/save.CPP","w")
file:write(math.ceil(zz))
file:close()
nill()
pizd=0
dofile("data/scripts/d.cpp")
end
end
if qr==3 then
screen:blit(mll+35,mnn+78,ukaz)
if pad:cross() then
nill()
dofile("data/scripts/script.cpp")
end
end
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

screen:flip()
oldpad=pad
if x < 0 then x = 0 elseif x + souris:width() > 470 then x = 470 -  souris:width() end
if y < 50 then y = 50 elseif y + souris:height() > 239 then y = 230 -  souris:width() end
end