--Fishing v. 1.5.0 Final RUS by RechnijY and Oxy949

System.currentDirectory("system")

FIFTYwhite = Color.new(120,120,120,100)
white = Color.new(255,255,255)
red = Color.new(255,0,0)
green = Color.new(0, 255,0)
blue = Color.new(0, 0, 255)
black = Color.new(0, 0, 0)
blackL = Color.new( 109, 109, 109)
orange = Color.new(225,176,62)
violet = Color.new(255,0,255)
yellow = Color.new(255,255,0)

--Txt
FlFile = io.open("txt/FL.txt", "r")
flLOAD = FlFile:read("*n")
FlFile:close()
FirstLaunch = flLOAD
if FirstLaunch == nil then
FirstLaunch = 1
end

ScoreFile = io.open("txt/Money.txt", "r")
ScoreLOAD = ScoreFile:read("*n")
ScoreFile:close()
sc1 = ScoreLOAD
if sc1 == nil then
sc1 = 0
end

GameoverFile = io.open("txt/END.txt", "r")
GameoverR = GameoverFile:read("*n")
GameoverFile:close()
Gameover = GameoverR

DayFile = io.open("txt/Time.txt", "r")
daytimerRED = DayFile:read("*n")
DayFile:close()
daytimer = daytimerRED 
if daytimer == nil then
daytimer = 0
end

DayFile2 = io.open("txt/useTime.txt", "r")
daytimerRED2 = DayFile2:read("*n")
DayFile2:close()
UseRealTIME = daytimerRED2
if UseRealTIME == nil then
UseRealTIME = 0
end

nameuser = io.open("txt/Name.txt", "r")
name01 = nameuser:read()
nameuser:close()
PlayerName = name01
if PlayerName == nil then
PlayerName = " "
end

--Shop TXT
Playeractive2 = io.open("txt/shop/SelectedBaiT.txt", "r")
SelectedBaiT = Playeractive2:read("*n")
Playeractive2:close()
if SelectedBaiT == nil then
SelectedBaiT = 1
end

Playeractive = io.open("txt/shop/player.txt", "r")
playerbought = Playeractive:read("*n")
Playeractive:close()
if playerbought == nil then
playerbought = 0
end

Playeractive = io.open("txt/shop/FS.txt", "r")
Fs1 = Playeractive:read("*n")
Playeractive:close()
if Fs1 == nil then
Fs1 = 1
end

WORMSFILE = io.open("txt/shop/worms.txt", "r")
wormsnomber = WORMSFILE:read("*n")
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "r")
cornssnomber = WORMSFILE:read("*n")
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "r")
motilsnomber = WORMSFILE:read("*n")
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "r")
oparyshsnomber = WORMSFILE:read("*n")
WORMSFILE:close()
if wormsnomber == nil then
wormsnomber = 25
end
if cornssnomber == nil then
cornssnomber = 0
end
if motilsnomber == nil then
motilsnomber = 0
end
if oparyshsnomber == nil then
oparyshsnomber = 0
end

RodFILE = io.open("txt/shop/RODKOEF.txt", "r")
Rodread = RodFILE:read("*n")
RodFILE:close()
rodkoef = Rodread
if rodkoef == nil then
rodkoef = 0.1
end

ReelFILE = io.open("txt/shop/REELKOEF.txt", "r")
Reelread = ReelFILE:read("*n")
ReelFILE:close()
reelkoef = Reelread
if reelkoef == nil then
reelkoef = 0.1
end

HookFILE = io.open("txt/shop/HOOKKOEF.txt", "r")
Hookread = HookFILE:read("*n")
HookFILE:close()
hookkoef = Hookread
if hookkoef == nil then
hookkoef = 0.1
end

LuckFILE = io.open("txt/shop/LUCKKOEF.txt", "r")
Luckread = LuckFILE:read("*n")
LuckFILE:close()
luckkoef = Luckread
if luckkoef == nil then
luckkoef = 0.1
end

--Font
fontS1 = 28
fontS2 = 14

snapitcBIG = Font.load("fonts/font1.TTF")
snapitcBIG:setPixelSizes(0,fontS1)

snapitcLIT = Font.load("fonts/font1.TTF")
snapitcLIT:setPixelSizes(0,fontS2)

snapitcLITeng = Font.load("fonts/font1ENG.TTF")
snapitcLITeng:setPixelSizes(0,fontS2)

--Main values
mp3 = {}
mp3no = 0
LoadFirst = 0
gamestate = "loading"
Loadingtime = 0
LtextX = 450
Lv150X = - 450
LoadbgSTATE = 0 
MenuX = 480
EXactive = 0
MenuY = 0
TextX = 480
MENUselect = 1
level = 0
padcross = 0
SelectMap1 = 1
FishingSTAGE = "Vait"
daytimer2 = 0
fishingrodX = 150
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
fishingswMove = 0
scroll1 = 0
peck = 0
Ppeck = 0
pecktime = 0
weight1 = 0
animationEP = 0
PadcrossEP = 0
shopstage = "buyplayer"
FsSEL = 1
loadtov = 0

NetworkSTAGE = "Connect"
HelpSTAGE = "Control"
Fishlist = 1
scroll2 = 0
starttimer = 0
rodhard = 0
LoadnetSTATE = 0
playerselect = 1
SettingsSTATE = "main"
setsel = 1
alerting = 0

Fishes = {	{name="BELwi AMUR", stoimost=200, maxweight=6000},
		{name="BELORwBICA", stoimost=300, maxweight=4000},
		{name="BELUGA", stoimost=1000, maxweight=1000},
		{name="BERQ", stoimost=300, maxweight=10000},
		{name="BESTER", stoimost=950, maxweight=100},
		{name="BwcOK", stoimost=20, maxweight=200},
		{name="BUFFALO", stoimost=150, maxweight=2800},
		{name="cAVIcA", stoimost=400, maxweight=4000},
		{name="cEBAK", stoimost=150, maxweight=8000},
		{name="cEHONb", stoimost=100, maxweight=5200},
		{name="ceRNwi AMUR", stoimost=230, maxweight=3000},
		{name="ELEC", stoimost=1200, maxweight=2100},
		{name="eRQ", stoimost=20, maxweight=230},
		{name="FORELb", stoimost=400, maxweight=10000},
		{name="gEREH", stoimost=120, maxweight=6000},
		{name="GOLAVLb", stoimost=300, maxweight=4000},
		{name="GOLEC", stoimost=250, maxweight=7000},
		{name="GORcAK", stoimost=10, maxweight=25},
		{name="GUSTERA", stoimost=600, maxweight=5000},
		{name="HARIUS", stoimost=100, maxweight=7000},
		{name="KAMBALA", stoimost=290, maxweight=3000},
		{name="KARASb", stoimost=90, maxweight=2200},
		{name="KARP", stoimost=160, maxweight=12000},
		{name="KEFALb", stoimost=340, maxweight=7050},
		{name="KETA", stoimost=700, maxweight=100},
		{name="KIGUc", stoimost=900, maxweight=100},
		{name="KILbKA", stoimost=120, maxweight=300},
		{name="KORUQKA", stoimost=270, maxweight=90},
		{name="KRASNOPeRKA", stoimost=300, maxweight=3500},
		{name="KUMGA", stoimost=280, maxweight=3000},
		{name="KUNDGA", stoimost=600, maxweight=4500},
		{name="LENOK", stoimost=760, maxweight=4100},
		{name="LEq", stoimost=130, maxweight=3600},
		{name="LINb", stoimost=990, maxweight=8000},
		{name="LOSOSb", stoimost=800, maxweight=13000},
		{name="MALbMA", stoimost=450, maxweight=100},
		{name="MIKIGA", stoimost=600, maxweight=2800},
		{name="NALIM", stoimost=680, maxweight=6990},
		{name="NAVAGA", stoimost=40, maxweight=29},
		{name="NERKA", stoimost=300, maxweight=100},
		{name="OKUNb", stoimost=50, maxweight=400},
		{name="OMUL", stoimost=90, maxweight=100},
		{name="OSeTR", stoimost=1100, maxweight=100},
		{name="PALIA", stoimost=500, maxweight=100},
		{name="PALTUS", stoimost=2000, maxweight=100},
		{name="PELJD", stoimost=200, maxweight=100},
		{name="PESKARb", stoimost=70, maxweight=120},
		{name="PLOTVA", stoimost=120, maxweight=9000},
		{name="PODLEqIK", stoimost=130, maxweight=7000},
		{name="PODUST", stoimost=190, maxweight=2000},
		{name="ROTAN", stoimost=40, maxweight=490},
		{name="RJPUQKA", stoimost=20, maxweight=105},
		{name="SALAKA", stoimost=400, maxweight=5000},
		{name="SELbDb", stoimost=300, maxweight=5500},
		{name="SeMGA", stoimost=500, maxweight=1800},
		{name="Sevruga", stoimost=150, maxweight=800},
		{name="QUKA", stoimost=300, maxweight=17000},
		{name="SIG", stoimost=500, maxweight=9000},
		{name="SINEC", stoimost=290, maxweight=2800},
		{name="SNETOK", stoimost=400, maxweight=4660},
		{name="SOM", stoimost=600, maxweight=20000},
		{name="SOPA", stoimost=750, maxweight=2440},
		{name="STERLAD", stoimost=900, maxweight=4200},
		{name="SUDAK", stoimost=1240, maxweight=18000},
		{name="TARAN", stoimost=100, maxweight=3600},
		{name="TUMENb", stoimost=190, maxweight=2480},
		{name="TOLSTOLOBIK", stoimost=200, maxweight=9000},
		{name="TRESKA", stoimost=120, maxweight=6400},
		{name="UGORb", stoimost=300, maxweight=9990},
		{name="UKLEiKA", stoimost=20, maxweight=140},
		{name="USAc", stoimost=200, maxweight=7880},
		{name="YgNAJ KOLYQKA", stoimost=10, maxweight=39},
		{name="VERcOGLJD", stoimost=560, maxweight=10000},
		{name="VESLONOS", stoimost=990, maxweight=12000},
		{name="VOBLA", stoimost=90, maxweight=5000},
		{name="YAZ", stoimost=50, maxweight=3000},
		{name="ZUBATKA", stoimost=360, maxweight=2880},
		{name="BANKA", stoimost=10, maxweight=1000},
		{name="BUTwLKA ZELeNAJ", stoimost=100, maxweight=1000},
		{name="BUTwLKA KORIcNEVAJ", stoimost=100, maxweight=1000},
		{name="KEDA", stoimost=300, maxweight=1000},
		{name="BONUS", stoimost=10000, maxweight=500}}

CompetitLIST = { {name="LOVLJ NA VREMJ", briffing="POiMAi KAK MOgNO BOLbQE RwB ZA OTVEDeNNOE VREMJ!"},
		{name="KTO BOLbQE", briffing="POBEgDAET TOT, KTO POiMAET BOLbQUY RwBU"}}

selectCOMPET1 = 1
--Images
Block = Image.createEmpty(150, 45)
Block:clear(black)

load1IMG = Image.load("images/boot/bg1.png")
System.memclean()
load2IMG = Image.load("images/boot/bg2.png")
System.memclean()
bgSTATE = Image.load("images/boot/FISH.png")
System.memclean()
text = Image.load("images/boot/text.png")
System.memclean()
v150 = Image.load("images/boot/v150.png")
System.memclean()
menuIMG = Image.load("images/menu/menu.png")
System.memclean()
moneyIMG = Image.load("images/menu/money.png")
System.memclean()
mapsinfo = Image.load("images/maps/info.png")
System.memclean()
timeIMG = Image.load("images/menu/time.png")
System.memclean()
fishingrod = Image.load("images/fishingrods/fishingrod_1.png")
System.memclean()
fishingrod_Wait = Image.load("images/fishingrods/fishingrod_1.png")
System.memclean()
fishingrod_Using = Image.load("images/fishingrods/fishingrod_1_USING.png")
System.memclean()
fishingrod_Using1 = Image.load("images/fishingrods/fishingrod_1_USING2.png")
System.memclean()
fishingrod_Using2 = Image.load("images/fishingrods/fishingrod_1_USING.png")
System.memclean()
reel = Image.load("images/reels/reel_1.png")
System.memclean()
reel_USING1 = Image.load("images/reels/reel_1_USING1.png")
System.memclean()
reel_USING2 = Image.load("images/reels/reel_1_USING2.png")
System.memclean()
reel_USING3 = Image.load("images/reels/reel_1_USING3.png")
System.memclean()
reel_USING4 = Image.load("images/reels/reel_1_USING4.png")
System.memclean()
pecktimeIMG = Image.load("images/menu/pecktime.png")
System.memclean()
pecktimelineIMG = Image.load("images/menu/pecktimeline.png")
System.memclean()
playerIMG = Image.load("images/shop/player.png")
System.memclean()
upgradeIMG = Image.load("images/shop/upgrade.png")
System.memclean()
fsIMG = Image.load("images/shop/fs.png")
System.memclean()
reelIMG = Image.load("images/shop/reel.png")
System.memclean()
crossimg_1 = Image.load("images/menu/cross.png")
System.memclean()
crossimg_2 = Image.load("images/menu/cross2.png")
System.memclean()
bordIMG = Image.load("images/fishes/Bord.png")
System.memclean()

--Functions
function ScoreWrite()
ScoreFile = io.open("txt/Money.txt", "w")
ScoreFile:write(sc1)
ScoreFile:close()
end

tempfiles = System.listDirectory("ms0:/MUSIC/Music")
if tempfiles == nil then
else
for i = 3,table.getn(tempfiles) do
if string.sub(tempfiles[i].name,-4) == ".mp3" or string.sub(tempfiles[i].name,-4) == ".MP3" or string.sub(tempfiles[i].name,-4) == ".Mp3" then
mp3[table.getn(mp3) + 1] = "../../../../MUSIC/Music/"..tempfiles[i].name
end
end
end

function PlayMp3()

if pad:square() then
Mp3me.stop()
mp3no = 0
end

if table.getn(mp3) > 0 then

if LoadFirst == 0 then
mp3no = mp3no + 1
Mp3me.stop()
Mp3me.load(mp3[mp3no])
Mp3me.play()
LoadFirst = 1
end

if pad:start() then
if pad:left() then
mp3no = mp3no - 1

elseif pad:right() then
mp3no = mp3no + 1
end
if mp3no <= 0 then
mp3no = table.getn(mp3)
elseif mp3no > table.getn(mp3) then
mp3no = 1
end

Mp3me.stop()
Mp3me.load(mp3[mp3no])
Mp3me.play()
end

if Mp3me.eos() == "true" then
mp3no = mp3no + 1
if mp3no <= 0 then
mp3no = table.getn(mp3)
elseif mp3no > table.getn(mp3) then
mp3no = 1
end
Mp3me.stop()
Mp3me.load(mp3[mp3no])
Mp3me.play()
end
end

end

function loadmapIMG(Mupnum, MinLEVELtoCONT)
if level >= MinLEVELtoCONT then
if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/maps/map-lacke"..Mupnum..".png")
System.memclean()
LoadbgSTATE = 1
end
else
if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/maps/map-un.png")
System.memclean()
LoadbgSTATE = 1
end
end
if level >= MinLEVELtoCONT and padcross == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "fishing"
LoadbgSTATE = 0
padcross = 0
end
end

function Endwith(Maonum,from1,to1)
if SelectMap1 == Maonum then
Pfish = math.random(from1,to1)
fishIMG = Image.load("images/fishes/"..Pfish..".jpg")
System.memclean()
end
end

function ExtraPecking()
if peck == 1 then
fishingswMove = fishingswMove + 1

if fishingswMove >= 5 then
fishingrodX = math.random(fishingrodX - 2,fishingrodX + 2)
end
animationEP = animationEP + 1
if animationEP >= 0 and animationEP < 5 then
screen:blit(190,60,crossimg_1)
end
if animationEP >= 5 and animationEP < 10 then
screen:blit(190,60,crossimg_2)
end
if animationEP >= 10 then
animationEP = 0
end
if pad:circle() and oldpad:circle() ~= pad:circle() then
PadcrossEP = PadcrossEP + 1
end

if peck == 0 then
fishingrod_Using = fishingrod_Using2
EXactive = 0
PadcrossEP = 0
end

if 155 - FishingswimerY - (level+1)*1.5*(luckkoef*10) > 2 then
if PadcrossEP >= 155 - FishingswimerY - (level+1)*1.5*(luckkoef*10) then
fishkind = 0
FishingSTAGE = "End"
PadcrossEP = 0
fishingrod_Using = fishingrod_Using2
end
else
if PadcrossEP >= 3 then
fishkind = 0
FishingSTAGE = "End"
PadcrossEP = 0
fishingrod_Using = fishingrod_Using2
end
end

end
end

function Loading()

if Gameover == 1 then
if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/menu/lose.png")
System.memclean()
LoadbgSTATE = 1
end
screen:blit(0,0,bgSTATE)
FishingSTAGE = "Vait"
screen:fontPrint(snapitcBIG,20,130,"Vw PROIGRALI!!! NAgMITE X!",red)
screen:fontPrint(snapitcLIT,25,160,"PROFILb SBROSITSJ I IGRA PEREZAPUSTITSJ!",red)
if pad:cross() then
screen:fontPrint(snapitcBIG,120,180,"POgALUiSTA PODOgDITE...",red)
ScoreFile = io.open("txt/Money.txt", "w")
ScoreFile:write("600")
ScoreFile:close()
sc1 = 600
Gameover = 0
FlFile = io.open("txt/FL.txt", "w")
FlFile:write("1")
FlFile:close()
flLOAD = 1

FlFile = io.open("txt/Shop/fs.txt", "w")
FlFile:write("1")
FlFile:close()
Fs1 = 1

DayFile = io.open("txt/Time.txt", "w")
DayFile:write("8")
DayFile:close()
daytimer = 8

DayFile2 = io.open("txt/useTIME.txt", "w")
DayFile2:write("0")
DayFile2:close()

nameuser = io.open("txt/Name.txt", "w")
nameuser:write("User")
nameuser:close()

gameoverfile = io.open("txt/End.txt", "w")
gameoverfile:write("0")
gameoverfile:close()

ScoreFile2 = io.open("txt/Shop/SelectedBaiT.txt", "w")
ScoreFile2:write("1")
ScoreFile2:close()
SelectedBaiT = 1

Playeractive = io.open("txt/shop/player.txt", "w")
Playeractive:write("0")
Playeractive:close()
playerbought = 0
Mp3me.stop()
mp3no = 0

WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(25)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
wormsnomber = 25
cornssnomber = 0
motilsnomber = 0
oparyshsnomber = 0

ReelFILE = io.open("txt/shop/REELKOEF.txt", "w")
ReelFILE:write("0.1")
ReelFILE:close()
reelkoef = 0.1

RodFILE = io.open("txt/shop/RODKOEF.txt", "w")
RodFILE:write("0.1")
RodFILE:close()
rodkoef = 0.1

ReelFILE = io.open("txt/shop/HOOKKOEF.txt", "w")
ReelFILE:write("0.1")
ReelFILE:close()
hookkoef = 0.1

RodFILE = io.open("txt/shop/LUCKKOEF.txt", "w")
RodFILE:write("0.1")
RodFILE:close()
luckkoef = 0.1

Gameover = 0
gameoverfile = io.open("txt/End.txt", "w")
gameoverfile:write("0")
gameoverfile:close()

mp3 = {}
mp3no = 0
LoadFirst = 0
gamestate = "loading"
Loadingtime = 0
LoadbgSTATE = 0 
MenuX = 480
EXactive = 0
MenuY = 0
TextX = 480
MENUselect = 1
level = 0
padcross = 0
SelectMap1 = 1
FishingSTAGE = "Vait"
daytimer2 = 0
fishingrodX = 150
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
fishingswMove = 0
scroll1 = 0
peck = 0
Ppeck = 0
pecktime = 0
weight1 = 0
animationEP = 0
PadcrossEP = 0
shopstage = "buyplayer"
FsSEL = 1
loadtov = 0

NetworkSTAGE = "Connect"
HelpSTAGE = "Control"
Fishlist = 1
scroll2 = 0
starttimer = 0
rodhard = 0
LoadnetSTATE = 0
playerselect = 1
SettingsSTATE = "main"
setsel = 1
alerting = 0

FirstLaunch = 1
gamestate = "loading"
LoadbgSTATE = 0
padcross = 0

load1IMG = Image.load("images/boot/bg1.png")
System.memclean()
load2IMG = Image.load("images/boot/bg2.png")
System.memclean()
bgSTATE = Image.load("images/boot/FISH.png")
System.memclean()
text = Image.load("images/boot/text.png")
System.memclean()
v150 = Image.load("images/boot/v150.png")
System.memclean()

end
else

if Loadingtime >= 0 and Loadingtime < 15 then
screen:blit(0,0,load1IMG)
if pad:select() and oldpad:select() ~= pad:select() then
Loadingtime = 14
end
end
if Loadingtime >= 15 and Loadingtime < 30 then
screen:blit(0,0,load2IMG)
if pad:select() and oldpad:select() ~= pad:select() then
Loadingtime = 29
end
end
if Loadingtime >= 30 and Loadingtime < 50 then
screen:blit(0,0,bgSTATE)
screen:blit(LtextX,0,text)
screen:blit(Lv150X,0,v150)
if LtextX > 4 then
LtextX = LtextX - 5
end
if Lv150X < -4 then
Lv150X = Lv150X + 5
end
if pad:select() and oldpad:select() ~= pad:select() then
Loadingtime = 54
end
end

if Loadingtime >= 50 and Loadingtime < 55 then
screen:blit(0,0,bgSTATE)
screen:blit(LtextX,0,text)
screen:blit(Lv150X,0,v150)
if LtextX > -400 then
LtextX = LtextX - 35
end
if Lv150X < 400 then
Lv150X = Lv150X + 35
end
if pad:select() and oldpad:select() ~= pad:select() then
Loadingtime = 54
end
end

if Loadingtime >= 0 and Loadingtime <= 55 then
Loadingtime = Loadingtime + 0.2
end

if Loadingtime >= 55 then
load1IMG = nil
load2IMG = nil
text = nil
v150 = nil
gamestate = "menu"
LoadbgSTATE = 0
end
end

end

function Menu()

if FirstLaunch == 1 then
PlayerName = System.startOSK("Your name(12 length - max)","Your name")

nameuser = io.open("txt/Name.txt", "w")
nameuser:write(PlayerName)
nameuser:close()

FlFile = io.open("txt/FL.txt", "w")
FlFile:write("0")
FlFile:close()
FirstLaunch = 0

end

if LoadbgSTATE == 0 then
if daytimer >= 5 and daytimer <= 23 then
bgSTATE = Image.load("images/menu/bgday.png")
end
if daytimer <= 5 or daytimer >= 23 then
bgSTATE = Image.load("images/menu/bgnight.png")
end
System.memclean()
LoadbgSTATE = 1 
end
screen:blit(0,0,bgSTATE)
screen:blit(MenuX,MenuY,menuIMG)
screen:blit(0,210,moneyIMG)
screen:fontPrint(snapitcLITeng,TextX + 10,30,PlayerName,orange)
screen:fontPrint(snapitcLIT,TextX,50,"IGRA", blackL)
screen:fontPrint(snapitcLIT,TextX,80,"MAGAZIN", blackL)
screen:fontPrint(snapitcLIT,TextX,110,"INTERNET", blackL)
screen:fontPrint(snapitcLIT,TextX,140,"NASTROiKI", blackL)
screen:fontPrint(snapitcLIT,TextX,170,"POMOqb", blackL)
screen:fontPrint(snapitcLIT,TextX,200,"Eqe IGRw", blackL)
screen:fontPrint(snapitcLIT,TextX,230,"VwHOD", blackL)
screen:fontPrint(snapitcLIT,10,240,"DENbGI - "..sc1.."RUB",black)
screen:fontPrint(snapitcLIT,10,260,"UR. - "..level.." SLED. - "..levelnext.."RUB",black)

if MenuX >= 352 then
MenuX = 352
end

if TextX > 383 then
TextX = 383
end

if pad:up() ~= oldpad:up() and pad:up() then
MENUselect = MENUselect - 1
end

if pad:down() ~= oldpad:down() and pad:down() then
MENUselect = MENUselect + 1
end

if MENUselect <= 0 then
MENUselect = 7
end

if MENUselect >= 8 then
MENUselect = 1
end

if MENUselect == 1 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "selectmap"
LoadbgSTATE = 0
SelectMap1 = 1
end
screen:fontPrint(snapitcLIT,TextX,50,"IGRA", black)
end

if MENUselect == 2 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "shopping"
LoadbgSTATE = 0
end
screen:fontPrint(snapitcLIT,TextX,80,"MAGAZIN", black)
end

if MENUselect == 3 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "network"
LoadbgSTATE = 0
end
screen:fontPrint(snapitcLIT,TextX,110,"INTERNET", black)
end

if MENUselect == 4 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "settings"
LoadbgSTATE = 0
end
screen:fontPrint(snapitcLIT,TextX,140,"NASTROiKI", black)
end

if MENUselect == 5 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "help"
LoadbgSTATE = 0
end
screen:fontPrint(snapitcLIT,TextX,170,"POMOqb", black)
end

if MENUselect == 6 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
gamestate = "competitions"
LoadbgSTATE = 0
end
screen:fontPrint(snapitcLIT,TextX,200,"Eqe IGRw", black)
end

if MENUselect == 7 then
if pad:cross() and oldpad:cross() ~= pad:cross() then
ScoreWrite()
System.Quit()
end
screen:fontPrint(snapitcLIT,TextX,230,"VwHOD", black)
end

if sc1 < 9999999 and string.len(sc1) <= 8 and PlayerName == "RechnijY" then
if pad:l() and pad:r() and pad:triangle() and pad:up() then
sc1 = sc1 + 200
ScoreWrite()
end
if pad:l() and pad:r() and pad:triangle() and pad:right() then
sc1 = sc1*2
ScoreWrite()
end
end
if sc1 > 200 and PlayerName == "RechnijY" then
if pad:l() and pad:r() and pad:triangle() and pad:down() then
sc1 = sc1 - 200
ScoreWrite()
end
if pad:l() and pad:r() and pad:triangle() and pad:left() then
sc1 = sc1/2
ScoreWrite()
end
end

end

function SelectMap()

if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/maps/map-lacke"..SelectMap1..".png")
System.memclean()
LoadbgSTATE = 1
end

if pad:cross() and oldpad:cross() ~= pad:cross() then
padcross = padcross + 1
end

if SelectMap1 < 23 and pad:up() and oldpad:up() ~= pad:up() then
padcross = 1
LoadbgSTATE = 0
SelectMap1 = SelectMap1 + 1
end

if SelectMap1 > 1 and pad:down() and oldpad:down() ~= pad:down() then
padcross = 1
LoadbgSTATE = 0
SelectMap1 = SelectMap1 - 1
end

if SelectMap1 < 18 and pad:r() and oldpad:r() ~= pad:r() then
padcross = 1
LoadbgSTATE = 0
SelectMap1 = SelectMap1 + 5
end

if SelectMap1 > 5 and pad:l() and oldpad:l() ~= pad:l() then
padcross = 1
LoadbgSTATE = 0
SelectMap1 = SelectMap1 - 5
end

if SelectMap1 == 1 then
loadmapIMG(1, 0)
end
if SelectMap1 == 2 then
loadmapIMG(2, 0)
end
if SelectMap1 == 3 then
loadmapIMG(3, 0)
end
if SelectMap1 == 4 then
loadmapIMG(4, 1)
end
if SelectMap1 == 5 then
loadmapIMG(5, 1)
end
if SelectMap1 == 6 then
loadmapIMG(6, 1)
end
if SelectMap1 == 7 then
loadmapIMG(7, 2)
end
if SelectMap1 == 8 then
loadmapIMG(8, 2)
end
if SelectMap1 == 9 then
loadmapIMG(9, 3)
end
if SelectMap1 == 10 then
loadmapIMG(10, 3)
end
if SelectMap1 == 11 then
loadmapIMG(11, 3)
end
if SelectMap1 == 12 then
loadmapIMG(12, 4)
end
if SelectMap1 == 13 then
loadmapIMG(13, 4)
end
if SelectMap1 == 14 then
loadmapIMG(14, 4)
end
if SelectMap1 == 15 then
loadmapIMG(15, 5)
end
if SelectMap1 == 16 then
loadmapIMG(16, 5)
end
if SelectMap1 == 17 then
loadmapIMG(17, 5)
end
if SelectMap1 == 18 then
loadmapIMG(18, 6)
end
if SelectMap1 == 19 then
loadmapIMG(19, 6)
end
if SelectMap1 == 20 then
loadmapIMG(20, 6)
end
if SelectMap1 == 21 then
loadmapIMG(21, 6)
end
if SelectMap1 == 22 then
loadmapIMG(22, 6)
end
if SelectMap1 == 23 then
loadmapIMG(23, 6)
end

screen:blit(0,0,bgSTATE)
screen:blit(0,0,mapsinfo)
screen:fontPrint(snapitcLIT,400,264,"KARTA "..SelectMap1,black)



if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
LoadbgSTATE = 0
padcross = 0
SelectMap1 = 1
end

end

function Fishing(fishingmode)

if LoadbgSTATE == 0 then
Lacke1_DAY = Image.load("images/lackes/lacke"..SelectMap1.."_DAY.png")
System.memclean()
Lacke1_DAY1 = Image.load("images/lackes/lacke"..SelectMap1.."_DAY.png")
System.memclean()
Lacke1_NIGHT = Image.load("images/lackes/lacke"..SelectMap1.."_NIGHT.png")

pecktimeIMG = Image.load("images/menu/pecktime"..SelectedBaiT..".png")
System.memclean()

Fishingswimer = Image.load("images/Fishingswimers/Fishingswimer"..Fs1..".png")
System.memclean()
Fishingswimer_USING1 = Image.load("images/Fishingswimers/Fishingswimer_"..Fs1.."_USING1.png")
System.memclean()
Fishingswimer_USING2 = Image.load("images/Fishingswimers/Fishingswimer_"..Fs1.."_USING2.png")
System.memclean()
Fishingswimer_USING3 = Image.load("images/Fishingswimers/Fishingswimer_"..Fs1.."_USING3.png")
System.memclean()

LoadbgSTATE = 1 
end

screen:blit(0,0,Lacke1_DAY)

if daytimer >= 5 and daytimer <= 23 then
Lacke1_DAY = Lacke1_DAY1
end
if daytimer <= 5 or daytimer >= 23 then
Lacke1_DAY = Lacke1_NIGHT
end

if FishingSTAGE == "Vait" then
FishingswimerX = fishingrodX  - 5
screen:blit(fishingrodX,0,reel)
screen:blit(fishingrodX,0,fishingrod)

if pad:l() and fishingrodX > 10 then
fishingrodX = fishingrodX - 10
end
if pad:r() and fishingrodX < 410 then
fishingrodX = fishingrodX + 10
end

if pad:cross() and oldpad:cross() ~= pad:cross() then
padcross = padcross + 1
end

if padcross == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiTNumbers > 0 then
FishingSTAGE = "Fishing"
padcross = 0
else
alerting = 1
end
end

end

if FishingSTAGE == "Fishing" then
screen:blit(FishingswimerX,FishingswimerY,Fishingswimer)
screen:blit(fishingrodX,0,reel)
screen:blit(fishingrodX,0,fishingrod_Using)

if pad:l() and fishingrodX > 15 then
fishingrodX = fishingrodX - 10
FishingswimerX = FishingswimerX - 0.5
end
if pad:r() and fishingrodX < 400 then
fishingrodX = fishingrodX + 10
FishingswimerX = FishingswimerX + 0.5
end

if FishingswimerY >= 150 and peck == 1 then
fishkind = 0
FishingSTAGE = "End"
end

if pad:cross() and FishingswimerY <= 150 and EXactive == 0 then
if rodhard <= 150 then
rodhard = rodhard + 2 + level/2 - rodkoef*3
end
FishingswimerY = FishingswimerY + 0.25 + (level/25) + reelkoef
if scroll1 >= 0 and scroll1 < 10  then
scroll1 =scroll1 + 4
reel = reel_USING1
end
if scroll1 >= 10 and scroll1 < 20  then
scroll1 = scroll1 + 4
reel = reel_USING2
end
if scroll1 >= 20 and scroll1 < 30  then
scroll1 =scroll1 + 4
reel = reel_USING3
end
if scroll1 >= 30 and scroll1 < 40  then
scroll1 =scroll1 + 4
reel = reel_USING4
end
if scroll1 >= 40 or scroll1 < 0 then
scroll1 = 0
end
end

if rodhard > 150 then
FishingSTAGE = "Crash"
fishingrod_Using = fishingrod_Using2
end

if rodhard > 3 then
rodhard = rodhard - 2 + (level/27)
end

if peck == 0 and pad:triangle() and oldpad:triangle() ~= pad:triangle() then
FishingSTAGE = "Vait"
fishingrod_Using = fishingrod_Using2
rodhard = 0
FishingswimerY = 80
Fishingswimer = Fishingswimer_USING1
scroll2 = 0
starttimer = 0
Ppeck  = 0
padcross = 1
end

if peck == 1 and pad:triangle() and oldpad:triangle() ~= pad:triangle() then
if EXactive == 0 then
EXactive = 1
end
end

if EXactive == 1 then
fishingrod_Using = fishingrod_Using1
ExtraPecking()
end

if peck == 1 then
scroll2 = scroll2 + 1
fishingswMove = fishingswMove + 1

if not pad:cross() then
if fishingswMove >= 5 then
FishingswimerX = math.random(FishingswimerX - 3,FishingswimerX + 3)
FishingswimerY = math.random(FishingswimerY - 1,FishingswimerY + 1)
fishingswMove = 0
end
end
if scroll2 >= 0 and scroll2 < 10  then
Fishingswimer = Fishingswimer_USING1
end
if scroll2 >= 10 and scroll2 < 20  then
Fishingswimer = Fishingswimer_USING2
end
if scroll2 >= 20 and scroll2 < 30  then
Fishingswimer = Fishingswimer_USING3
end
if scroll2 >= 30 and scroll2 < 32  then
Fishingswimer = Fishingswimer_USING2
end
if scroll2 >= 32 or scroll2 < 0 then
scroll2 = 0
end
end

if peck == 0 and FishingswimerY <= 150 then
if SelectedBaiTNumbers  > 0 then
Ppeck = math.random(0,3000-(level*20+2230+luckkoef*500))
if Ppeck == 25 then
peck = 1
starttimer = 1
end
else
alerting = 1
end
end

if starttimer == 1 and FishingswimerY < 150 then
pecktime = pecktime + 0.21 + level/12 - hookkoef/2
if pecktime >= 150 then
Fishingswimer = Fishingswimer_USING1
fishingrod_Using = fishingrod_Using2
EXactive = 0
PadcrossEP = 0
peck = 0
EXactive = 0
PadcrossEP = 0
if SelectedBaiT == 1 then
wormsnomber = wormsnomber - 1
end
if SelectedBaiT == 2 then
cornssnomber = cornssnomber - 1
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber - 1
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber - 1
end
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
pecktime = 0
Ppeck  = 0
starttimer = 0
end
end

end

if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
alerting = 0
LoadbgSTATE = 0
padcross = 0
EXactive = 0
FishingSTAGE = "Vait"
fishingrodX = 150
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
Fishingswimer = Fishingswimer_USING1
peck = 0
pecktime = 0
scroll2 = 0
PadcrossEP = 0
starttimer = 0
Ppeck  = 0
rodhard = 0
end

screen:blit(2,228,Block)
screen:blit(rodhard - 162,230,pecktimelineIMG)
screen:blit(pecktime - 160,250,pecktimelineIMG)
screen:blit(0,222,pecktimeIMG)
if SelectedBaiT == 1 then
screen:fontPrint(snapitcLIT,420,240,wormsnomber,black)
end
if SelectedBaiT == 2 then
screen:fontPrint(snapitcLIT,420,240,cornssnomber,black)
end
if SelectedBaiT == 3 then
screen:fontPrint(snapitcLIT,420,240,motilsnomber,black)
end
if SelectedBaiT == 4 then
screen:fontPrint(snapitcLIT,420,240,oparyshsnomber,black)
end
if alerting == 1 then
screen:fontPrint(snapitcLIT,170,262,"OTSUTSTVUET NAgIVKA",red)
end

if FishingswimerY >= 150 and peck == 0 then
screen:fontPrint(snapitcLIT,170,262,"SL. BLIZKO, PEREZAKINbTE UDOcKU",red)
end

if FishingSTAGE == "Crash" then

screen:fontPrint(snapitcLIT,170,262,"Vw SLOMALI UDOcKU, NOVAJ - ".. (level*130)+100+(rodkoef+luckkoef)*100 .."RUB",red)
if sc1 < (level*130)+100+(rodkoef+luckkoef)*100 then
screen:fontPrint(snapitcBIG,5,120,"U VAS NET ".. (level*130)+100+(rodkoef+luckkoef)*100 .."RUB!, IGRA OKONcENA!",orange)
screen:fontPrint(snapitcBIG,7,122,"U VAS NET ".. (level*130)+100+(rodkoef+luckkoef)*100 .."RUB!, IGRA OKONcENA!",blue)
Gameover = 1
LoadbgSTATE = 0
gameoverfile = io.open("txt/End.txt", "w")
gameoverfile:write("1")
gameoverfile:close()
if pad:cross() and oldpad:cross() ~= pad:cross() or pad:select() then
gamestate = "loading"
FishingSTAGE = "Vait"
alerting = 0
end
end

if sc1 >= (level*130)+100+(rodkoef+luckkoef)*100 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiT == 1 then
wormsnomber = wormsnomber - 1
end
if SelectedBaiT == 2 then
cornssnomber = cornssnomber - 1
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber - 1
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber - 1
end
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
alerting = 0
sc1 = sc1 - ((level*130)+100+(rodkoef+luckkoef)*100)
ScoreWrite()
padcross = 1
FishingSTAGE = "Vait"
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
Fishingswimer = Fishingswimer_USING1
peck = 0
EXactive = 0
pecktime = 0
scroll2 = 0
starttimer = 0
Ppeck  = 0
rodhard = 0
fishkind = 0
end

end

if FishingSTAGE == "End" then
if fishkind == 0 then
if SelectedBaiT == 1 then
wormsnomber = wormsnomber - 1
end
if SelectedBaiT == 2 then
cornssnomber = cornssnomber - 1
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber - 1
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber - 1
end
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()

Endwith(1,1,3)
Endwith(2,3,6)
Endwith(3,6,9)
Endwith(4,9,12)
Endwith(5,12,15)
Endwith(6,15,18)
Endwith(7,18,21)
Endwith(8,21,24)
Endwith(9,24,27)
Endwith(10,27,30)
Endwith(11,30,33)
Endwith(12,33,36)
Endwith(13,36,39)
Endwith(14,39,43)
Endwith(15,44,48)
Endwith(16,48,55)
Endwith(17,56,59)
Endwith(18,60,64)
Endwith(19,65,69)
Endwith(20,70,77)
Endwith(21,1,77)
Endwith(22,1,82)
Endwith(23,78,82)

if weight1 <= 1 then
weight1 = math.random(1,Fishes[Pfish].maxweight)
end
if sc1 < 9999999 and string.len(sc1) <= 8 then
sc1 = sc1 + ((weight1*Fishes[Pfish].stoimost)/1000)
ScoreWrite()
end
fishkind = 1
end

if fishkind == 1 then
screen:blit(90,61,fishIMG)
screen:fontPrint(snapitcLIT,94,75,"aTO " .. Fishes[Pfish].name,black)
screen:fontPrint(snapitcLIT,94,200,"STOIMOSTb - " .. ((weight1*Fishes[Pfish].stoimost)/1000) .."RUB, VES - ".. (weight1) .."G",black)
screen:blit(88,59,bordIMG)
end

if pad:triangle() and oldpad:triangle() ~= pad:triangle() then
padcross = 1
weight1 = 0
FishingSTAGE = "Vait"
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
Fishingswimer = Fishingswimer_USING1
peck = 0
EXactive = 0
pecktime = 0
scroll2 = 0
starttimer = 0
Ppeck  = 0
rodhard = 0
fishkind = 0
end

end
end

function Shopping()
if LoadbgSTATE == 0 then
shopST = 1
bgSTATE = Image.load("images/shop/bg.png")
System.memclean()
LoadbgSTATE = 1 
end
screen:blit(0,0,bgSTATE)
screen:blit(0,65,moneyIMG)
screen:fontPrint(snapitcLIT,10,85,"DENbGI - "..sc1.."RUB",black)
screen:fontPrint(snapitcLIT,10,110,"UR. - "..level.." SLED. - "..levelnext.."RUB",black)

if pad:l() and oldpad:l() ~= pad:l() and shopST > 1 then
shopST = shopST - 1
loadtov = 0
end
if pad:r() and oldpad:r() ~= pad:r() and shopST < 4 then
shopST = shopST + 1
loadtov = 0
end

if shopST == 1 then
shopstage = "buyplayer"
end
if shopST == 2 then
shopstage = "buyworms"
end
if shopST == 3 then
shopstage = "upgrade"
end
if shopST == 4 then
shopstage = "buyfs"
end

if shopstage == "buyplayer" then
screen:blit(273,70,playerIMG)
if playerbought == 0 then
screen:fontPrint(snapitcLIT,70,53,"KUPITb PLEER - 350RUB",black)
if sc1 < 350 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 350RUB",red)
end
else
screen:fontPrint(snapitcLIT,70,53,"PLEER UgE KUPLEN",black)
screen:fontPrint(snapitcLIT,5,220,"SKOPIRUiTE MR3 FAiLw V",black)
screen:fontPrint(snapitcLITeng,200,220,"'MUSIC/music'",black)
screen:fontPrint(snapitcLIT,5,250,"START+LEVO - NAZAD, START+PRAVO - VPEReD, KVADRAT - STOP",black)
end

if pad:cross() and oldpad:cross() ~= pad:cross() then
padcross = padcross + 1
end

if padcross == 2 and sc1 >= 350 and pad:cross() and oldpad:cross() ~= pad:cross() and playerbought == 0 then
sc1 = sc1 - 350
playerbought = 1
Playeractive = io.open("txt/shop/player.txt", "w")
Playeractive:write(playerbought)
Playeractive:close()
ScoreWrite()
PlayMp3()
end


end
if shopstage == "buyworms" then

screen:blit(273,70,fsIMG)

if SelectedBaiT == 1 then
screen:fontPrint(snapitcLIT,70,53,"KUPITb cERVEi - 150RUB(5)",black)
if sc1 < 150 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 150RUB",red)
end

if sc1 >= 150 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiT == 1 then
sc1 = sc1 - 150
wormsnomber = wormsnomber + 5
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 2 then
sc1 = sc1 - 200
cornssnomber = cornssnomber + 5
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
end
ScoreWrite()
end

end
if SelectedBaiT == 2 then
screen:fontPrint(snapitcLIT,70,53,"KUPITb KUKURUZU - 200RUB(5)",black)
if sc1 < 200 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 200RUB",red)
end

if sc1 >= 200 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiT == 1 then
sc1 = sc1 - 150
wormsnomber = wormsnomber + 5
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 2 then
sc1 = sc1 - 200
cornssnomber = cornssnomber + 5
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
end
ScoreWrite()
end

end
if SelectedBaiT == 3 then
screen:fontPrint(snapitcLIT,70,53,"KUPITb MOTwLJ - 120RUB(5)",black)
if sc1 < 120 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 120RUB",red)
end

if sc1 >= 120 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiT == 1 then
sc1 = sc1 - 150
wormsnomber = wormsnomber + 5
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 2 then
sc1 = sc1 - 200
cornssnomber = cornssnomber + 5
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
end
ScoreWrite()
end

end
if SelectedBaiT == 4 then
screen:fontPrint(snapitcLIT,70,53,"KUPITb OPARwQA - 390RUB(5)",black)
if sc1 < 390 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 390RUB",red)
end

if sc1 >= 390 and pad:cross() and oldpad:cross() ~= pad:cross() then
if SelectedBaiT == 1 then
sc1 = sc1 - 150
wormsnomber = wormsnomber + 5
WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(wormsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 2 then
sc1 = sc1 - 200
cornssnomber = cornssnomber + 5
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(cornssnomber)
WORMSFILE:close()
end
if SelectedBaiT == 3 then
motilsnomber = motilsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(motilsnomber)
WORMSFILE:close()
end
if SelectedBaiT == 4 then
oparyshsnomber = oparyshsnomber + 5
sc1 = sc1 - 200
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(oparyshsnomber)
WORMSFILE:close()
end
ScoreWrite()
end

end

if pad:triangle() and oldpad:triangle() ~= pad:triangle() then
ScoreFile2 = io.open("txt/Shop/SelectedBaiT.txt", "w")
ScoreFile2:write(SelectedBaiT)
ScoreFile2:close()
end

if pad:right() and oldpad:right() ~= pad:right() and SelectedBaiT < 4 then
SelectedBaiT = SelectedBaiT + 1
loadtov = 0
ScoreFile2 = io.open("txt/Shop/SelectedBaiT.txt", "w")
ScoreFile2:write(SelectedBaiT)
ScoreFile2:close()
end

if pad:left() and oldpad:left() ~= pad:left() and SelectedBaiT > 1 then
SelectedBaiT = SelectedBaiT - 1
loadtov = 0
ScoreFile2 = io.open("txt/Shop/SelectedBaiT.txt", "w")
ScoreFile2:write(SelectedBaiT)
ScoreFile2:close()
end

screen:fontPrint(snapitcLIT,5,255,"ISPOLbZUiTE LEVUY I PRAVUY KLAVIQw DLJ PROKRUTKI",black)
screen:fontPrint(snapitcLIT,5,215,"TREUGOLINIK - VwBOR",black)
screen:fontPrint(snapitcLIT,5,235,"SEicAS PROSMATR. - "..SelectedBaiT,black)

if SelectedBaiT == 1 then
screen:fontPrint(snapitcLIT,5,195,"cERVI - "..wormsnomber,black)
end
if SelectedBaiT == 2 then
screen:fontPrint(snapitcLIT,5,195,"KUKURUZA - "..cornssnomber,black)
end
if SelectedBaiT == 3 then
screen:fontPrint(snapitcLIT,5,195,"MOTwLb - "..motilsnomber,black)
end
if SelectedBaiT == 4 then
screen:fontPrint(snapitcLIT,5,195,"OPARwQ - "..oparyshsnomber,black)
end


if loadtov == 0 then
fsIMG = Image.load("images/shop/pr/"..SelectedBaiT..".png")
System.memclean()
loadtov = 1
end

end

if shopstage == "upgrade" then
screen:blit(200,60,upgradeIMG)
screen:fontPrint(snapitcLIT,70,53,"ULUcQENIJ",black)
screen:fontPrint(snapitcLIT,205,95,"KREST - KATUQKA",black)
screen:fontPrint(snapitcLIT,205,115,"KRUG - UDOcKA",black)
screen:fontPrint(snapitcLIT,205,135,"TREUGOLbNIK - KRYcOK",black)
screen:fontPrint(snapitcLIT,205,155,"VVERH - UDAcA",black)
screen:fontPrint(snapitcLIT,5,190,"KRYcOK " .. hookkoef*10,black)
screen:fontPrint(snapitcLIT,5,205,"UDAcA " .. luckkoef*10,black)
screen:fontPrint(snapitcLIT,5,220,"KATUQKA " .. reelkoef*10,black)
screen:fontPrint(snapitcLIT,5,235,"UDOcKA " .. rodkoef*10,black)


if sc1 < 1500 and ((hookkoef+luckkoef+reelkoef+rodkoef)*10<16) then
screen:fontPrint(snapitcLIT,12,170,"U VAS NET 1500RUB",red)
end

if hookkoef >= 0.4 then
screen:fontPrint(snapitcLIT,105,190,"MAKSIMUM!",red)
end
if luckkoef >= 0.4 then
screen:fontPrint(snapitcLIT,105,205,"MAKSIMUM!",red)
end
if reelkoef >= 0.4 then
screen:fontPrint(snapitcLIT,105,220,"MAKSIMUM!",red)
end
if rodkoef >= 0.4 then
screen:fontPrint(snapitcLIT,105,235,"MAKSIMUM!",red)
end


if sc1 >= 1500 and hookkoef < 0.4 and pad:triangle() and oldpad:triangle() ~= pad:triangle() then
sc1 = sc1 - 1500
ScoreWrite()
padcross = 1
hookkoef = hookkoef + 0.1
RFILE = io.open("txt/shop/HOOKKOEF.txt", "w")
RFILE:write(hookkoef)
RFILE:close()
end

if sc1 >= 1500 and luckkoef < 0.4 and pad:up() and oldpad:up() ~= pad:up() then
sc1 = sc1 - 1500
ScoreWrite()
padcross = 1
luckkoef = luckkoef + 0.1
RFILE = io.open("txt/shop/LUCKKOEF.txt", "w")
RFILE:write(luckkoef)
RFILE:close()
end

if sc1 >= 1500 and reelkoef < 0.4 and pad:cross() and oldpad:cross() ~= pad:cross() then
sc1 = sc1 - 1500
ScoreWrite()
padcross = 1
reelkoef = reelkoef + 0.1
RFILE = io.open("txt/shop/REELKOEF.txt", "w")
RFILE:write(reelkoef)
RFILE:close()
end

if sc1 >= 1500 and rodkoef < 0.4 and pad:circle() and oldpad:circle() ~= pad:circle() then
sc1 = sc1 - 1500
ScoreWrite()
padcross = 1
rodkoef = rodkoef + 0.1
RFILE = io.open("txt/shop/RODKOEF.txt", "w")
RFILE:write(rodkoef)
RFILE:close()
end

end
if shopstage == "buyfs" then
screen:blit(273,70,fsIMG)
screen:fontPrint(snapitcLIT,70,53,"KUPITb POPLAVKI - 50RUB",black)

if sc1 >= 50 and pad:cross() and oldpad:cross() ~= pad:cross() then
sc1 = sc1 - 50
ScoreWrite()
FlFile = io.open("txt/Shop/fs.txt", "w")
FlFile:write(FsSEL)
FlFile:close()
Fs1 = FsSEL
end

if sc1 < 50 then
screen:fontPrint(snapitcLIT,5,180,"U VAS NET 50RUB",red)
end

screen:fontPrint(snapitcLIT,5,255,"ISPOLbZUiTE LEVUY I PRAVUY KLAVIQw DLJ PROKRUTKI",black)
screen:fontPrint(snapitcLIT,5,220,"SEicAS PROSMATR. - "..FsSEL,black)
screen:fontPrint(snapitcLIT,5,235,"SEicAS VwBR. - "..Fs1,black)


if loadtov == 0 then
fsIMG = Image.load("images/shop/fs/fs"..FsSEL..".png")
System.memclean()
loadtov = 1
end

if FsSEL > 1 and pad:left() and oldpad:left() ~= pad:left() then
FsSEL = FsSEL - 1
loadtov = 0
end

if FsSEL < 3 and pad:right() and oldpad:right() ~= pad:right() then
FsSEL = FsSEL + 1
loadtov = 0
end

end

if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
shopstage = "buyplayer"
LoadbgSTATE = 0
padcross = 0
ScoreWrite()
end

end

function Competitions()

if LoadbgSTATE == 0 then
shopST = 1
bgSTATE = Image.load("images/MoreGames/bg.png")
System.memclean()
LoadbgSTATE = 1 
end
screen:blit(0,0,bgSTATE)

if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
LoadbgSTATE = 0
padcross = 0
end

end

function Settings()

if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/settings/bg.png")
System.memclean()
LoadbgSTATE = 1 
end
screen:blit(0,0,bgSTATE)
screen:fontPrint(snapitcLIT,50,100,"KREST - SBROSITb NASTROiKI I IGROVOi PROFILb",red)
screen:fontPrint(snapitcLIT,50,120,"KVADRAT - IZMENITb IMJ IGROKA",red)
if UseRealTIME == 0 then
screen:fontPrint(snapitcLIT,50,140,"TREUGOLbNIK - ISPOLbZOVATb REALbNOE VREMJ",red)
end
if UseRealTIME == 1 then
screen:fontPrint(snapitcLIT,50,140,"TREUGOLbNIK - ISPOLbZOVATb IGROVOE VREMJ",red)
end

if pad:cross() and oldpad:cross() ~= pad:cross() then
padcross = padcross + 1
end

if pad:triangle() and oldpad:triangle() ~= pad:triangle() then
UseRealTIME = UseRealTIME + 1
if UseRealTIME == 2 then
UseRealTIME = 0
end
DayFile2 = io.open("txt/useTIME.txt", "w")
DayFile2:write(UseRealTIME)
DayFile2:close()
end

if pad:square() and oldpad:square() ~= pad:square() then
PlayerName = System.startOSK(PlayerName,"Your new name")
nameuser = io.open("txt/Name.txt", "w")
nameuser:write(PlayerName)
nameuser:close()

FlFile = io.open("txt/FL.txt", "w")
FlFile:write("0")
FlFile:close()
FirstLaunch = 0
end

if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
LoadbgSTATE = 0
padcross = 0
end

if padcross == 2 and pad:cross() and oldpad:cross() ~= pad:cross() then
screen:fontPrint(snapitcBIG,120,180,"Please vait...",red)

ScoreFile = io.open("txt/Money.txt", "w")
ScoreFile:write("600")
ScoreFile:close()
sc1 = 600

ScoreFile2 = io.open("txt/Shop/SelectedBaiT.txt", "w")
ScoreFile2:write("1")
ScoreFile2:close()
SelectedBaiT = 1

FlFile = io.open("txt/Shop/fs.txt", "w")
FlFile:write("1")
FlFile:close()
Fs1 = 1

FlFile = io.open("txt/FL.txt", "w")
FlFile:write("1")
FlFile:close()
FirstLaunch = 1

DayFile = io.open("txt/Time.txt", "w")
DayFile:write("8")
DayFile:close()
daytimer = 8

DayFile2 = io.open("txt/useTIME.txt", "w")
DayFile2:write("0")
DayFile2:close()

nameuser = io.open("txt/Name.txt", "w")
nameuser:write("User")
nameuser:close()

gameoverfile = io.open("txt/End.txt", "w")
gameoverfile:write("0")
gameoverfile:close()

Playeractive = io.open("txt/shop/player.txt", "w")
Playeractive:write("0")
Playeractive:close()
playerbought = 0
Mp3me.stop()
mp3no = 0

ReelFILE = io.open("txt/shop/REELKOEF.txt", "w")
ReelFILE:write("0.1")
ReelFILE:close()
reelkoef = 0.1

RodFILE = io.open("txt/shop/RODKOEF.txt", "w")
RodFILE:write("0.1")
RodFILE:close()
rodkoef = 0.1

ReelFILE = io.open("txt/shop/HOOKKOEF.txt", "w")
ReelFILE:write("0.1")
ReelFILE:close()
hookkoef = 0.1

RodFILE = io.open("txt/shop/LUCKKOEF.txt", "w")
RodFILE:write("0.1")
RodFILE:close()
luckkoef = 0.1

Gameover = 0
gameoverfile = io.open("txt/End.txt", "w")
gameoverfile:write("0")
gameoverfile:close()

WORMSFILE = io.open("txt/shop/worms.txt", "w")
WORMSFILE:write(25)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/CORNS.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/MOTIL.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
WORMSFILE = io.open("txt/shop/OPARYSH.txt", "w")
WORMSFILE:write(0)
WORMSFILE:close()
wormsnomber = 25
cornssnomber = 0
motilsnomber = 0
oparyshsnomber = 0

mp3 = {}
mp3no = 0
LoadFirst = 0
gamestate = "loading"
Loadingtime = 0
LoadbgSTATE = 0 
MenuX = 480
EXactive = 0
MenuY = 0
TextX = 480
MENUselect = 1
level = 0
padcross = 0
SelectMap1 = 1
FishingSTAGE = "Vait"
daytimer2 = 0
fishingrodX = 150
FishingswimerX = fishingrodX  - 5
FishingswimerY = 80
fishingswMove = 0
scroll1 = 0
peck = 0
Ppeck = 0
pecktime = 0
weight1 = 0
animationEP = 0
PadcrossEP = 0
shopstage = "buyplayer"
FsSEL = 1
loadtov = 0

NetworkSTAGE = "Connect"
HelpSTAGE = "Control"
Fishlist = 1
scroll2 = 0
starttimer = 0
rodhard = 0
LoadnetSTATE = 0
playerselect = 1
SettingsSTATE = "main"
setsel = 1
alerting = 0

FirstLaunch = 1
gamestate = "menu"
LoadbgSTATE = 0
padcross = 0

end

end

function Network()

if LoadbgSTATE == 0 then
Adhoc.init()
Adhoc.connect()
minuteur = Timer.new()
minuteur:start()
Time = minuteur:time()
bgSTATE = Image.load("images/network/bg.png")
System.memclean()
LoadbgSTATE = 1
end

if NetworkSTAGE == "Connect" then
screen:clear()
screen:blit(0,0,bgSTATE)
ImprtADHOC = Adhoc.recv()
Adhoc.send("vaitforgame")
screen:fontPrint(snapitcLIT,10,80,"KOLLEKTIVNAJ IGRA:",black)
screen:fontPrint(snapitcLIT,22,100,"NAgMITE KRUG DLJ OTPRAVKI DENEG(S VAS BUDET SNJTO 100$)",black)

if pad:circle() and oldpad:circle() ~= pad:circle() then
NetworkSTAGE = "SentMoney" 
end

end

if NetworkSTAGE == "Create" then
screen:clear()
screen:blit(0,0,bgSTATE)
ImprtADHOC = Adhoc.recv()
Adhoc.send("create")
end

if NetworkSTAGE == "Join" then
screen:clear()
screen:blit(0,0,bgSTATE)
ImprtADHOC = Adhoc.recv()
Adhoc.send("join")
end

if NetworkSTAGE == "SentMoney" then
screen:clear()
screen:blit(0,0,bgSTATE)
screen:fontPrint(snapitcLIT,22,80,"VAQI DENbGI: " .. sc1 .. "$",black)
screen:fontPrint(snapitcLIT,22,100,"NAgMITE KREST DLJ OTPRAVKI 1$",black)
screen:fontPrint(snapitcLIT,22,120,"NAgMITE KVADRAT DLJ OTPRAVKI 10$",black)
screen:fontPrint(snapitcLIT,22,140,"NAgMITE KRUG DLJ OTPRAVKI 100$",black)
screen:fontPrint(snapitcLIT,22,160,"NAgMITE TREUGOLbNIK DLJ OTPRAVKI 1000$",black)

ImprtADHOC = Adhoc.recv()

if pad:cross() then
if sc1 >= 1 then
Adhoc.send("padcross")
sc1 = sc1 - 1
ScoreWrite()
end
end

if pad:square() then
if sc1 >= 10 then
Adhoc.send("padsquare")
sc1 = sc1 - 10
ScoreWrite()
end
end

if pad:circle() then
if sc1 >= 100 then
Adhoc.send("padcircle")
sc1 = sc1 - 100
ScoreWrite()
end
end

if pad:triangle() then
if sc1 >= 1000 then
Adhoc.send("padtriangle")
sc1 = sc1 - 1000
ScoreWrite()
end
end

if ImprtADHOC == "padcross" then
sc1 = sc1 + 1
ScoreWrite()
end
if ImprtADHOC == "padsquare" then
sc1 = sc1 + 10
ScoreWrite()
end
if ImprtADHOC == "padcircle" then
sc1 = sc1 + 100
ScoreWrite()
end
if ImprtADHOC == "padtriangle" then
sc1 = sc1 + 1000
ScoreWrite()
end

end


if pad:select() and oldpad:select() ~= pad:select() then
Adhoc.term()
gamestate = "menu"
LoadbgSTATE = 0
NetworkSTAGE = "Connect"
padcross = 0
end

end

function Help()
if LoadbgSTATE == 0 then
bgSTATE = Image.load("images/help/main.png")
System.memclean()
bgSTATE2 = Image.load("images/help/f"..Fishlist..".png")
System.memclean()
LoadbgSTATE = 1
end

if pad:l() then
HelpSTAGE = "Control"
end

if pad:r() then
HelpSTAGE = "FishlistV"
end

if HelpSTAGE == "Control" then
screen:blit(0,0,bgSTATE)
end

if HelpSTAGE == "FishlistV" then
screen:blit(0,0,bgSTATE2)

if pad:left() and oldpad:left() ~= pad:left() and Fishlist > 1 then
Fishlist = Fishlist - 1
LoadbgSTATE = 0
end

if pad:right() and oldpad:right() ~= pad:right() and Fishlist < 7 then
Fishlist = Fishlist + 1
LoadbgSTATE = 0
end

end

if pad:select() and oldpad:select() ~= pad:select() then
gamestate = "menu"
LoadbgSTATE = 0
padcross = 0
Fishlist = 1
HelpSTAGE = "Control"
end

end

while true do
pad = Controls.read()

if gamestate == "loading" then
Loading()
end
if gamestate == "menu" then
Menu()
end
if gamestate == "selectmap" then
SelectMap()
end
if gamestate == "fishing" then
Fishing()
end
if gamestate == "competitions" then
Competitions()
end
if gamestate == "shopping" then
Shopping()
end
if gamestate == "network" then
Network()
end
if gamestate == "settings" then
Settings()
end
if gamestate == "help" then
Help()
end

if sc1 >= 0 and sc1 <= 1500 then
level = 0
end
if sc1 >= 1500 and sc1 <= 3500 then
level = 1
end
if sc1 >= 3500 and sc1 <= 5800 then
level = 2
end
if sc1 >= 5800 and sc1 <= 9000 then
level = 3
end
if sc1 >= 9000 and sc1 <= 12570 then
level = 4
end
if sc1 >= 12570 and sc1 <= 18000 then
level = 5
end
if sc1 >= 18000 and sc1 <= 36000 then
level = 6
end
if sc1 >= 36000 and sc1 <= 79000 then
level = 7
end
if sc1 >= 79000 and sc1 <= 99999 then
level = 8
end
if sc1 >= 99999 then
level = 9
end

if level == 0 then
levelnext = 1500
end
if level == 1 then
levelnext = 3500
end
if level == 2 then
levelnext = 5800
end
if level == 3 then
levelnext = 9000
end
if level == 4 then
levelnext = 12570
end
if level == 5 then
levelnext = 18000
end
if level == 6 then
levelnext = 36000
end
if level == 7 then
levelnext = 79000
end
if level == 8 then
levelnext = 99999
end
if level == 9 then
levelnext = "MAKS!"
end

--GameTIME
if UseRealTIME == 0 then
daytimer2 = daytimer2 + 0.01
if daytimer2 > 6 then
daytimer = daytimer + 1
DayFile = io.open("txt/Time.txt", "w")
DayFile:write(daytimer)
DayFile:close()
daytimer2 = 0
end

if daytimer >= 24 then
daytimer = 0
end

screen:blit(0,5,timeIMG)

if daytimer >= 10 then
screen:fontPrint(snapitcLIT,3,20,"VREMJ " .. daytimer ..":".. string.sub(daytimer2, 0, 1).."0",black)
end

if daytimer < 10 then
screen:fontPrint(snapitcLIT,3,20,"VREMJ 0" .. daytimer ..":".. string.sub(daytimer2, 0, 1).."0",black)
end
end

--RealTIME
if UseRealTIME == 1 then
screen:blit(0,5,timeIMG)
time = os.time()
date = os.date("%c", time)
dateInfo = os.date("*t", time)
daytimer = dateInfo.hour + 3
min = dateInfo.min
if min < 10 then
min = "0" .. min
end
if daytimer >= 24 then
daytimer = daytimer - 24
end
if daytimer < 10 then
screen:fontPrint(snapitcLIT,3, 20,"VREMJ 0" .. daytimer .. ":" .. min , black)
end
if daytimer >= 10 then
screen:fontPrint(snapitcLIT,3, 20,"VREMJ " .. daytimer .. ":" .. min, black)
end

end

if Loadingtime >= 14 and playerbought == 1 then
PlayMp3()
end

if SelectedBaiT == 1 then
SelectedBaiTNumbers = wormsnomber
end
if SelectedBaiT == 2 then
SelectedBaiTNumbers = cornssnomber
end
if SelectedBaiT == 3 then
SelectedBaiTNumbers = motilsnomber
end
if SelectedBaiT == 4 then
SelectedBaiTNumbers = oparyshsnomber
end

oldpad = pad
screen.waitVblankStart()
screen.flip()
end

