-- Items to use
-- 06_button 07_button

function OnSceneLoad(screen)
    LoadData(screen)
    DefaultOnSceneLoad('data/Scenes/Minigames/07_lock.lua', 'quest', 'data/Scenes/07_Atelier_Main.lua')
    
    AddNoteToNotebook('SALON')
    
    if HasGameState('ToolFound', '07_button') then
        AddNoteToNotebook('SALON_2')
    end
    
	minigame_states = {}
	minigame_states.active = true
	minigame_states.skip = false
	minigame_states.screen = screen
	minigame_states.status = 0
		
	minigame_states.screen:GetObject('lapki_top_open'):SetOpacity(0.0)
	minigame_states.screen:GetObject('lapki_down_open'):SetOpacity(0.0)
	minigame_states.screen:GetObject('blue_2'):SetOpacity(0.0)
	minigame_states.screen:GetObject('green_1'):SetOpacity(0.0)
	
	-- Variables
	OBJECTS_NUM = 25
	LINES_NUM = 5
	PIXELS = 90.0
	DELTA = 10.0
	
	Objects = {}
	ObjectsPos = {}
	Field = {}
	local Colors = {"blue", "green", "red", "purple", "yellow"}
	local CellsPos = {13, 16, 22,11, 10, 
                      24, 7,  19, 9,  5,
                       4,17,  1, 14, 21,
                      25,12, 18,  8,  2,
                      15, 3, 23,  6, 20}
	
	-- Init
	for i = 1, OBJECTS_NUM do
		Objects[i] = {}
		Objects[i].Active = true
	end

	for i = 1, LINES_NUM do
	    for j = 1, LINES_NUM do
    		Objects[(i-1)*LINES_NUM+j].Entity = screen:GetObject(Colors[i].."_"..j)
	    	Objects[(i-1)*LINES_NUM+j].Type = i
	    	ObjectsPos[(i-1)*LINES_NUM+j] = Objects[(i-1)*LINES_NUM+j].Entity:GetPosition()
		end
	end
		
	for i = 1, LINES_NUM do
        Field[i] = {}
        for j = 1, LINES_NUM do
            Field[i][j] = {}
        end
    end
	
	for i = 1, OBJECTS_NUM do
		local ind = CellsPos[i]
		Objects[i].Entity:SetXY(ObjectsPos[ind].x, ObjectsPos[ind].y)
		Objects[i].SlotX = (ind - 1) % LINES_NUM + 1
		Objects[i].SlotY = math.floor((ind - 1) / LINES_NUM) + 1
		Field[Objects[i].SlotX][Objects[i].SlotY] = Objects[i]
		Objects[i].Index = ind
	end
	
	RegisterButton1ToolApply()
	RegisterButton2ToolApply()
	
	if minigame_states.status == 0 then
        ShowMonolog('C_07_HINT_NO_LOCK_PART_1', 'C_07_HINT_NO_LOCK_PART_1')
    elseif minigame_states.status == 1 then
        ShowMonolog('C_07_HINT_NO_LOCK_PART_2', 'C_07_HINT_NO_LOCK_PART_2')
    end
	
	LoadGame()
end

function SaveGame()
	for i = 1, OBJECTS_NUM do
		for j = 1, OBJECTS_NUM do
			if HasGameState('MINI_GAME_07_STATE_1_'..i, ''..j) then
				RemoveGameState('MINI_GAME_07_STATE_1_'..i, ''..j)
			end
			if HasGameState('MINI_GAME_07_STATE_2_'..i, ''..j) then
				RemoveGameState('MINI_GAME_07_STATE_2_'..i, ''..j)
			end
		end
	end
	
	for i = 1, OBJECTS_NUM do
		AddGameState('MINI_GAME_07_STATE_1_'..i, ''..Objects[i].Index)
		
		if HasGameState('MINI_GAME_07_STATE_2_'..i, '1') then
			RemoveGameState('MINI_GAME_07_STATE_2_'..i, '1')
		end
		if HasGameState('MINI_GAME_07_STATE_2_'..i, '0') then
			RemoveGameState('MINI_GAME_07_STATE_2_'..i, '0')
		end
			
		if(Objects[i].Active) then
			AddGameState('MINI_GAME_07_STATE_2_'..i, '1')
		else
			AddGameState('MINI_GAME_07_STATE_2_'..i, '0')
		end
	end
end

function LoadGame()
    for i = 1, OBJECTS_NUM do
		for j = 1, OBJECTS_NUM do
			if HasGameState('MINI_GAME_07_STATE_1_'..i, ''..j) then
				Objects[i].Index = j
				Objects[i].Entity:SetXY(ObjectsPos[j].x, ObjectsPos[j].y)
				Objects[i].SlotX =(j - 1) % LINES_NUM + 1
				Objects[i].SlotY = math.floor((j - 1) / LINES_NUM) + 1
				Field[Objects[i].SlotX][Objects[i].SlotY] = Objects[i]
				if(HasGameState('MINI_GAME_07_STATE_2_'..i, '1')) then
					Objects[i].Active = true
				end
				if(HasGameState('MINI_GAME_07_STATE_2_'..i, '0')) then
					Objects[i].Active = false
					Objects[i].Entity:SetVisible(false)
				end
			end
		end
	end
end

function RegisterButton1ToolApply()
    RegisterToolApplyInfo('06_button', 'area_green', nil,  nil,  function(tool_name)        
																	minigame_states.screen:GetObject('blue_2'):ChangeOpacity(0.0, 1.0, 0.4)
																	minigame_states.screen:GetObject('blue_2'):ChangeScale(0.5, 1.0, 0.4)
																	minigame_states.status = minigame_states.status + 1
																	if(minigame_states.status == 2) then
																		StartGame_mg()
																	else
																	    RegisterButton2ToolApply()
																	end
																	
																	PlaySound('07_PlaceCell')
                                                                end,
                                                                function(tool_name)                                                                 
                                                                    minigame_states.screen:GetObject('blue_2'):SetOpacity(1.0)
                                                                    minigame_states.status = minigame_states.status + 1
                                                                    if(minigame_states.status == 2) then
																	    StartGame_mg()
																	end
                                                                end,
                                                                function()
                                                                end)
end

function RegisterButton2ToolApply()
    RegisterToolApplyInfo('07_button', 'area_green', nil,  nil,  function(tool_name)        
																	minigame_states.screen:GetObject('green_1'):ChangeOpacity(0.0, 1.0, 0.4)
																	minigame_states.screen:GetObject('green_1'):ChangeScale(0.5, 1.0, 0.4)
																	minigame_states.status = minigame_states.status + 1
																	if(minigame_states.status == 2) then
																		StartGame_mg()
																    else
																        RegisterButton1ToolApply()
																	end
																	
																	PlaySound('07_PlaceCell')
                                                                end,
                                                                function(tool_name)                                                                 
																	minigame_states.screen:GetObject('green_1'):SetOpacity(1.0)
																	minigame_states.status = minigame_states.status + 1
																	if(minigame_states.status == 2) then
																		StartGame_mg()
																	end
                                                                end,
                                                                function()
                                                                end)
end

function StartGame_mg()
	minigame_states.screen:GetObject('area_green'):SetVisible(false)
	minigame_states.screen:IgnoreOnTestPoint("area_green")
	level_mode = 'mini_game'
	play_field:GetLevelScreen():GetPanel():SetMode(PM_MINIGAME)
	ShowMonolog('C_07_HINT_LOCK_START', 'C_07_HINT_LOCK_START')
	TimerDoString('UpdateGame()', 0.4, minigame_states.screen:GetTimer())
end

----------------------------------------------

function OnSceneFree(screen)
    DefaultOnSceneFree()
    FreeData(screen)
end

function OnUpdate(dt)
    DefaultOnUpdate(dt)
end

function OnAllItemsFound()
    DefaultOnAllItemsFound()
end

function OnLose()
    DefaultOnLose()
end

function OnExit()
    DefaultOnExit()
end

function OnClose()
    DefaultOnClose()
end

function OnObjectMouseEnter(object)
    DefaultOnObjectMouseEnter(object)
end

function OnObjectMouseLeave(object)
    DefaultOnObjectMouseLeave(object)
end

----------------------------------------------------------------------------------------------------------------------------------------------------

function FinalAnimation()
	if not HasGameState('MiniGameCompleted', '07_lock') then
        AddGameState('MiniGameCompleted', '07_lock')
        AddGameState('ClosedScene', game_state.scene_path)
    end
    
	minigame_states.screen:GetObject('zaschelka_top'):Move(0.0, 50.0, 0.4)
	minigame_states.screen:GetObject('zaschelka_down'):Move(0.0, -50.0, 0.4)
	
	-- Whells rotating animation
	local whells = 8
	local count = 1
	local whells_obj = {}
	for i = 1, whells, 2 do
	    whells_obj[i] = minigame_states.screen:GetObject('zvezda_'..count)
	    whells_obj[i+1] = minigame_states.screen:GetObject('zvezda_'..count..'_shadow')
	    count = count + 1
	end
	
	for i = 1, whells do
	    local af = CreateAnimationEffector()
		af:AttachTo(whells_obj[i])
		af:SetMode(_ANIM_FWD  + _ANIM_NOLOOP)
		af:SetKey(_TRACK_A, 0.0, whells_obj[i]:GetAngle())
		af:SetKey(_TRACK_A, 1.5, whells_obj[i]:GetAngle() + M_PI_OVER_2)
		af:Play()
	end
	
	-- Objects moved animation
	TimerDoString('minigame_states.screen:GetObject("zasov"):Move(-100.0, 0.0, 0.5)', 1.0, minigame_states.screen:GetTimer())
	TimerDoString('minigame_states.screen:GetObject("lapki_top_closed"):ChangeOpacity(1.0, 0.0, 0.5)', 0.5, minigame_states.screen:GetTimer())
	TimerDoString('minigame_states.screen:GetObject("lapki_down_closed"):ChangeOpacity(1.0, 0.0, 0.5)', 0.5, minigame_states.screen:GetTimer())
	TimerDoString('minigame_states.screen:GetObject("lapki_top_open"):ChangeOpacity(0.0, 1.0, 0.5)', 0.5, minigame_states.screen:GetTimer())
	TimerDoString('minigame_states.screen:GetObject("lapki_down_open"):ChangeOpacity(0.0, 1.0, 0.5)', 0.5, minigame_states.screen:GetTimer())
	
	PlaySound('07_OpenLock')
	
	TimerDoString("StartLevel('data/Scenes/07_Atelier_Main.lua')", 1.5, minigame_states.screen:GetTimer())
end

function SkipMiniGame()
	if(minigame_states.skip == false) then
		minigame_states.skip = true
		
		for i = 1, OBJECTS_NUM do
			if(Objects[i].Active == true) then
				Objects[i].Entity:ChangeOpacity(1.0, 0.0, 0.3)
				Objects[i].Active = false
			end
		end
		
		FinalAnimation()
		SaveGame()
	end
end

function IsCompleted()
	for i = 1, OBJECTS_NUM do
		if(Objects[i] ~= nil and Objects[i].Active == true) then
			return false
		end
	end
	
	return true
end

function GetObjectByName(obj_name)
	for i = 1, OBJECTS_NUM do
		if(obj_name == Objects[i].Entity:GetName()) then
			return Objects[i]
		end
	end
	
	return nil
end

function GetFillLine()
    -- Colums
    local fill = true
        
	for i = 1, LINES_NUM do
	    fill = true
	    for j = 1, LINES_NUM-1 do
	        if (Field[i][j] ~= nil and Field[i][j+1] ~= nil) then
    	        if (Field[i][j].Active == false or Field[i][j+1].Active == false or Field[i][j].Type ~= Field[i][j+1].Type) then
	                fill = false
	                break
	            end
	        end
	    end
	    if fill == true then
	        return i + LINES_NUM
        end
	end
		
	-- Rows (lines)
	for i = 1, LINES_NUM do
	    fill = true
	    for j = 1, LINES_NUM-1 do
	        if (Field[j][i] ~= nil and Field[j+1][i] ~= nil) then
	            if (Field[j][i].Active == false or Field[j+1][i].Active == false or Field[j][i].Type ~= Field[j+1][i].Type) then
	                fill = false
    	            break
	            end
	        end
	    end
	    if fill == true then
	        return i
        end
	end	
		
	return 0
end

function ReplaceCells(obj_1, obj_2)
    if obj_1 == nil or obj_2 == nil or obj_1 == obj_2 then return nil end
    
    Field[obj_1.SlotX][obj_1.SlotY] = obj_2
	Field[obj_2.SlotX][obj_2.SlotY] = obj_1
				
	local Xbuf = obj_1.SlotX
	local Ybuf = obj_1.SlotY
	local index = obj_1.Index
	
	obj_1.SlotX = obj_2.SlotX
	obj_1.SlotY = obj_2.SlotY
	obj_1.Index = obj_2.Index
	obj_2.SlotX = Xbuf
	obj_2.SlotY = Ybuf
	obj_2.Index = index
end

function UpdateGame()
	local line_number = GetFillLine()
	
	if line_number > 0 then
		if line_number < LINES_NUM+1 then
			KillRow(line_number)
			TimerDoString('UpdateGame()', 0.4, minigame_states.screen:GetTimer())
		else
			KillColumn(line_number - LINES_NUM)
			TimerDoString('UpdateGame()', 0.4, minigame_states.screen:GetTimer())
		end
	else
		if IsCompleted() then
			FinalAnimation()
		end
		minigame_states.active = true
	end
	
	SaveGame()
end

function KillRow(index)
	for i = 1, LINES_NUM do
		Field[i][index].Entity:ChangeOpacity(1.0, 0.0, 0.3)
		Field[i][index].Active = false
	end
	
	if index < 5 then
	    MoveRow(index+1)
	end
		
	SaveGame()
end

function KillColumn(index)
	for i = 1, LINES_NUM do
		Field[index][i].Entity:ChangeOpacity(1.0, 0.0, 0.3)
		Field[index][i].Active = false
	end
	
	if index <5 then
	    MoveColumn(index+1)
	end
		
	SaveGame()
end

function MoveRow(index)
	for i = 1, LINES_NUM do
	    for j = index, LINES_NUM do
	        Field[i][j].Entity:Move(0.0, -PIXELS, 0.3)
	        ReplaceCells(Field[i][j], Field[i][j-1])
	    end
	end
		
	PlaySound('07_MoveCell')
	SaveGame()
end

function MoveColumn(index)
	for i = 1, LINES_NUM do
	    for j = index, LINES_NUM do
	        Field[j][i].Entity:Move(-PIXELS, 0.0, 0.3)
	       	ReplaceCells(Field[j-1][i], Field[j][i])
	    end
	end
			
	PlaySound('07_MoveCell')
	SaveGame()
end

function CanMove(obj_1, obj_2)
    if obj_1 == obj_2 then return false end
            
    local x = math.abs(obj_1.Entity:GetX() - obj_2.Entity:GetX())
    local y = math.abs(obj_1.Entity:GetY() - obj_2.Entity:GetY())
    
    if (x > PIXELS-DELTA and x < PIXELS+DELTA and y > -DELTA and y < DELTA) or (x > -DELTA and x < DELTA and y > PIXELS-DELTA and y < PIXELS+DELTA) then
        return true
    end
            
    return false
end


----------------------------------------------------------------------------------------------------------------------------------------------------

function OnObjectMouseDown(object)
    local is_wrong_click = not DefaultOnObjectMouseDown(object)
    local obj_name = object:GetName()
    local pf = play_field
    
    local Obj = GetObjectByName(obj_name)
	
	if Obj ~= nil and minigame_states.active == true and minigame_states.status == 2 and minigame_states.skip == false then
		if(ActiveObject ~= nil) then
			if CanMove(Obj, ActiveObject) then
				Obj.Entity:Move(ActiveObject.Entity:GetX() - Obj.Entity:GetX(), ActiveObject.Entity:GetY() - Obj.Entity:GetY(), 0.4)
				ActiveObject.Entity:Move(Obj.Entity:GetX() - ActiveObject.Entity:GetX(), Obj.Entity:GetY() - ActiveObject.Entity:GetY(), 0.4)
								
				ReplaceCells(Obj, ActiveObject)
				
				minigame_states.active = false
				TimerDoString('UpdateGame()', 0.4, minigame_states.screen:GetTimer())
				
				PlaySound('07_MoveCell')
				
				ActiveObject.Entity:GetAnimation():SetColor('0xFFFFFFFF')
			    ActiveObject = nil
			else
			    ActiveObject.Entity:GetAnimation():SetColor('0xFFFFFFFF')
			    ActiveObject = Obj
			    ActiveObject.Entity:GetAnimation():SetColor('0xAAFFFFFF')
			    PlaySound('07_SelectCell')		
			end
		else
			ActiveObject = Obj
			ActiveObject.Entity:GetAnimation():SetColor('0xAAFFFFFF')
			PlaySound('07_SelectCell')
		end
	end
	
    if obj_name == 'area_green' then
        if minigame_states.status == 0 then
            ShowMonolog('C_07_HINT_NO_LOCK_PART_1', 'C_07_HINT_NO_LOCK_PART_1')
        elseif minigame_states.status == 1 then
            ShowMonolog('C_07_HINT_NO_LOCK_PART_2', 'C_07_HINT_NO_LOCK_PART_2')
        end
    end
	
    DefaultOnObjectMouseDownProcessed(is_wrong_click)
end

function OnObjectMouseUp(object)
    DefaultOnObjectMouseUp(object)
end

function OnObjectFound(object)
    DefaultOnObjectFound(object)
end

function OnToolFound(tool)
    DefaultOnToolFound(tool)
end

function OnToolApply(tool, object)
    DefaultOnToolApply(tool, object)
end

function OnObjectReachPanel(object)
    DefaultOnObjectReachPanel(object)
end

function OnButtonPress(title)
    DefaultOnButtonPress(title)
end

function OnMouseMove(previous_pos, current_pos)
    DefaultOnMouseMove(previous_pos, current_pos)
end

function OnSetTool(tool)
    DefaultOnSetTool(tool)
end

function LevelLoaded(level)

end

function OnSceneDestroy(playfield)
    DefaultOnSceneDestroy(playfield)
end

--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function LoadData(screen)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/background.jpg',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('background',anim,512,384,95,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/frontset.png',0,0,800,705,1,0)
	anim:SetHotSpot(400,352)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('frontset',anim,514,387,105,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/lapki_down_closed.png',0,0,215,125,1,0)
	anim:SetHotSpot(107,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('lapki_down_closed',anim,412,694,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/lapki_down_open.png',0,0,225,145,1,0)
	anim:SetHotSpot(112,72)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('lapki_down_open',anim,417,694,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/lapki_top_closed.png',0,0,216,125,1,0)
	anim:SetHotSpot(108,62)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('lapki_top_closed',anim,414,106,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/lapki_top_open.png',0,0,223,145,1,0)
	anim:SetHotSpot(111,72)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('lapki_top_open',anim,416,97,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/shesterenka_1.png',0,0,85,85,1,0)
	anim:SetHotSpot(42,42)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('shesterenka_1',anim,728,260,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/skoba.png',0,0,308,560,1,0)
	anim:SetHotSpot(154,280)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('skoba',anim,874,394,104,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zaschelka_down.png',0,0,52,63,1,0)
	anim:SetHotSpot(26,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zaschelka_down',anim,420,684,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zaschelka_top.png',0,0,52,63,1,0)
	anim:SetHotSpot(26,31)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zaschelka_top',anim,419,99,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zasov.png',0,0,441,211,1,0)
	anim:SetHotSpot(220,105)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zasov',anim,758,402,103,0,1,1)
	local anim = CreateAnimation('data/Texture/Scenes/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,4)
	anim:SetBlendMode(2)
	anim:SetColor('0x01FFFFFF')
	screen:CreateObject('area_green',anim,432,387,115,0,70,70)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_blue.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('blue_1',anim,247,207,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_blue.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('blue_2',anim,337,207,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_blue.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('blue_3',anim,427,207,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_blue.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('blue_4',anim,517,207,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_blue.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('blue_5',anim,607,207,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_green.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('green_1',anim,247,297,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_green.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('green_2',anim,337,297,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_green.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('green_3',anim,427,297,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_green.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('green_4',anim,517,297,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_green.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('green_5',anim,607,297,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_red.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('red_1',anim,247,387,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_red.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('red_2',anim,337,387,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_red.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('red_3',anim,427,387,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_red.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('red_4',anim,517,387,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_red.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('red_5',anim,607,387,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_purple.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('purple_1',anim,247,477,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_purple.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('purple_2',anim,337,477,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_purple.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('purple_3',anim,427,477,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_purple.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('purple_4',anim,517,477,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_purple.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('purple_5',anim,607,477,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_yellow.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('yellow_1',anim,247,567,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_yellow.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('yellow_2',anim,337,567,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_yellow.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('yellow_3',anim,427,567,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_yellow.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('yellow_4',anim,517,567,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Cells/button_yellow.png',0,0,93,93,1,0)
	anim:SetHotSpot(46,46)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('yellow_5',anim,607,567,110,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_1.png',0,0,180,179,1,0)
	anim:SetHotSpot(90,89)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_1',anim,346,203,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_1_shadow.png',0,0,184,185,1,0)
	anim:SetHotSpot(92,92)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_1_shadow',anim,337,205,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_2.png',0,0,157,160,1,0)
	anim:SetHotSpot(78,80)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_2',anim,553,516,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_2_shadow.png',0,0,162,165,1,0)
	anim:SetHotSpot(81,82)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_2_shadow',anim,549,516,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_3.png',0,0,102,102,1,0)
	anim:SetHotSpot(51,51)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_3',anim,442,463,101,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_3_shadow.png',0,0,105,104,1,0)
	anim:SetHotSpot(52,52)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_3_shadow',anim,439,466,100,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_4.png',0,0,152,152,1,0)
	anim:SetHotSpot(76,76)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_4',anim,467,348,102,0,1,1)
	local anim = CreateAnimation('data/Texture/Minigames/07_lock/Layers/zvezda_4_shadow.png',0,0,155,155,1,0)
	anim:SetHotSpot(77,77)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('zvezda_4_shadow',anim,462,351,101,0,1,1)
end

function FreeData(screen)
end
-- CLEAR_ON_SAVE_END
