--888888_____88888____888___888__888888_____888
--88___8____88___88___888___888__88___8_____888
--88___88__88_____88__888___888__88___88____8_8
--88___8___88_____88__8888_8888__88___8____88_88
--888888___88_____88__88_888_88__888888____88__8
--88___88__88_____88__88_888_88__88___88___8___8
--88___88__88_____88__88__8__88__88___88__8888888
--88___88___88___88___88_____88__88___88__88___88
--888888_____88888____88_____88__888888__88_____88

bomba=Image.load("data/img/bomba.jpg")--zagruzka kartinki na vremennuu peremennuu
ten=Image.load("data/img/ten.png")--zagruzka kartinki na vremennuu peremennuu
p1=Image.load("data/img/p1.png")--zagruzka kartinki na vremennuu peremennuu
p2=Image.load("data/img/p2.png")--zagruzka kartinki na vremennuu peremennuu
p3=Image.load("data/img/p3.png")--zagruzka kartinki na vremennuu peremennuu
p4=Image.load("data/img/p4.png")--zagruzka kartinki na vremennuu peremennuu
bum=Image.load("data/img/bum.png")--zagruzka kartinki na vremennuu peremennuu
shkala=Image.load("data/img/shkala.png")--zagruzka kartinki na vremennuu peremennuu
sourisc=Image.load("data/img/souris4.png")--zagruzka kartinki na vremennuu peremennuu
sourisc2=Image.load("data/img/souris5.png")--zagruzka kartinki na vremennuu peremennuu
blacke=Color.new(0,0,0)--zadanie cveta

function nill()--funkcia otchistki pamiati
bomba=nill
p1=nill
p2=nill
p3=nill
p4=nill
bum=nill
sourisc=nil
sourisc2=nil
end--zakritie funkcii

file=io.open("data/nastroi/save.CPP","r")--otkritie storonnego faila
peremennay=file:read()--kod dlia ego schitivania
file:close()--ostanovka schitivania

font88 = Font.load("data/font/qwe3.ttf")--podgruzka chrifta
font88:setPixelSizes(60,14)--zadanie razmera chriftu

Mp3me.stop()--ostanovka muziki
Mp3me.load("data/sound/3.mp3")--zagruzka muziki
Mp3me.play()--igrat

local bom={4}--sozdanie massiva na 4 elementa
sh=25
for i=1,4 do
bom[i]=0
end

while true do--zapusk igrovogo cikla
screen:clear()--ochistka ekrana
pad = Controls.read()--podgruzka knopok psp
screen:blit(0,0,bomba)--raspechatka bombi
if bom[1]==0 then--esli 1 element massiva bom raven 0 to propechatka pervogo provoda
screen:blit(243,120,p1)--raspechatka provoda
end--konec
if bom[2]==0 then--esli 2 element massiva bom raven 0 to propechatka pervogo provoda
screen:blit(280,120,p2)--raspechatka provoda
end--konec
if bom[3]==0 then--esli 3 element massiva bom raven 0 to propechatka pervogo provoda
screen:blit(320,120,p3)--raspechatka provoda
end--konec
if bom[4]==0 then--esli 4 element massiva bom raven 0 to propechatka pervogo provoda
screen:blit(360,120,p4)--raspechatka provoda
end--konec
screen:fontPrint(font88,280,102,math.ceil(peremennay),blacke)
screen:blit(sh,150,shkala)
if pad:cross() then--esli knopka krestik
screen:blit(x,y,sourisc2)--propechatka zazatix ploskogubec
if x>=233 and x<=261 and y>=120 and y<=199 then
if bom[2]==1 then
bom[1]=1
else
peremennay=0
end
end
if x>=270 and x<=298 and y>=120 and y<=199 then
bom[2]=1
end
if x>=310 and x<=338 and y>=120 and y<=199 then
if bom[2]==1 and bom[1]==1 and bom[4]==1 then
bom[3]=1
else
peremennay=0
end
end
if x>=350 and x<=378 and y>=120 and y<=199 then
if bom[2]==1 and bom[1]==1 then
bom[4]=1
else
peremennay=0
end
end
else
screen:blit(x,y,sourisc)
end

if x>=270 and x<=298 and y>=120 and y<=199 and bom[2]==0 then
if sh<153 then
sh=sh+1
end
elseif x>=233 and x<=250 and y>=120 and y<=199 and bom[1]==0 then
if sh<117 then
sh=sh+1
else
sh=sh-1
end
elseif x>=350 and x<=378 and y>=120 and y<=199 and bom[4]==0 then
if sh<90 then
sh=sh+1
else
sh=sh-1
end
elseif x>=310 and x<=338 and y>=120 and y<=199 and bom[3]==0 then
if sh<61 then
sh=sh+1
else
sh=sh-1
end
else
if sh>25 then
sh=sh-1
end
end

screen:blit(0,0,ten)
peremennay=peremennay-0.01--otschet do vzriva
if peremennay<=0 then
screen:blit(0,0,bum)
end
if peremennay<-0.01 then
System.message("You died! =(",0)
nill()
dofile("data/scripts/script.cpp")
end

if bom[1]==1 and bom[2]==1 and bom[3]==1 and bom[4]==1 and sh<=25 then--proverka uspechnogo prohozdenia
System.message("You win and bomb diaktivirovana!",0)--vivod soobchenia
file=io.open("data/makesave/save24.msn","w")--zapis progressa v failik
file:write(4)
file:close()
nill()
dofile("data/load/load.cpp")--zagruzka sleduuchego urovnia
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
y =y - 10
end
if pad:down() then
y =y + 10
end
if pad:left() then
x =x - 10
end
if pad:right() then
x =x + 10
end

if pad:r() then
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 16;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 16;
end
else
if math.abs(pad:analogY()) > 32 then
y = y + pad:analogY() / 64;
end
if math.abs(pad:analogX()) > 32 then
x = x + pad:analogX() / 64;
end
end

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