
function GameScreen:InitScreen()
    self:LoadScreen()
    HUDScreen:SetMiniGameMode()
    
    self.clock_arrow = { 
        {"husky_hand_small", "husky_hand_big"}, {"qt_hand_small", "qt_hand_big"}, {"filltoto_hand_big", "filltoto_hand_small"}, 
        {"ettiro_hand_big", "ettiro_hand_small"}, {"classic_hand_big", "classic_hand_small"}, {"koyla_hand_big", "koyla_hand_small"}, 
        {"roadmod_hand_big", "roadmod_hand_small"}, {"komrad_hand_big", "komrad_hand_small"}}
    
    self.diods = {
        "diode_husky", "diode_qt", "diode_filltoto", "diode_ettiro", "diode_classic", "diode_koyla", "diode_roadmod", "diode_komrad"
    }
    
    
    for key, value in pairs(self.clock_arrow) do
        if(GetState(CURRENT_SCREEN, value[1]) ~= "") then
            ItemSetAngle(value[1], tonumber(GetState(CURRENT_SCREEN, value[1])));
        end
        if(GetState(CURRENT_SCREEN, value[2]) ~= "") then
            ItemSetAngle(value[2], tonumber(GetState(CURRENT_SCREEN, value[2])));
        end
    end
    
    self.arrow_angle = {
        {M_PI + M_PI / 5 * 2, M_PI / 2 - M_PI / 8}, {0, M_PI + M_PI / 6}, {M_PI, M_PI + M_PI / 7 * 2},
        {M_PI / 2 - M_PI / 6, M_PI + M_PI / 2}, {0, M_PI + M_PI / 2}, {M_PI / 6, M_PI + M_PI / 3},
        {M_PI - M_PI / 6, M_PI + M_PI / 3 * 2}, {M_PI * 2 - M_PI / 4, M_PI / 2 - M_PI / 6}
    }
    --[[
    ItemSetAngle("husky_hand_big", M_PI / 2 - M_PI / 8)
    ItemSetAngle("husky_hand_small", M_PI + M_PI / 5 * 2)
    ItemSetAngle("qt_hand_big", M_PI + M_PI / 6)
    ItemSetAngle("qt_hand_small", 0)
    ItemSetAngle("filltoto_hand_big", M_PI)
    ItemSetAngle("filltoto_hand_small", M_PI + M_PI / 7 * 2)
    ItemSetAngle("ettiro_hand_big", M_PI / 2 - M_PI / 6)
    ItemSetAngle("ettiro_hand_small", M_PI + M_PI / 2)
    ItemSetAngle("classic_hand_big", 0)
    ItemSetAngle("classic_hand_small", M_PI + M_PI / 2)
    ItemSetAngle("koyla_hand_big", M_PI / 6)
    ItemSetAngle("koyla_hand_small", M_PI + M_PI / 3)
    ItemSetAngle("roadmod_hand_big", M_PI - M_PI / 6)
    ItemSetAngle("roadmod_hand_small", M_PI + M_PI / 3 * 2)
    ItemSetAngle("komrad_hand_big", M_PI * 2 - M_PI / 4)
    ItemSetAngle("komrad_hand_small", M_PI / 2 - M_PI / 6)
    --]]
    self.minigame_active = true
    
    self:diod_update()
    
    HUDScreen:ShowHintText({path = "graphics/screens/06_basement/location/Hint_06a", x = 308, y = 1109, loop = true})
    MusicPlay({"sound/ambient/20_ambient.ogg", "sound/music/basement.ogg"}, 6) 
    
    HUDScreen:CreateBackButton("006_basement")
end
------------------------------------------------------------------------------------------------------
function GameScreen:diod_update()

    for key, value in pairs(self.clock_arrow) do     
        ItemSetOpacity(self.diods[key], 0.0)
        if(self.rotate_item == nil or (value[1] ~= self.rotate_item and value[2] ~= self.rotate_item)) then--стрелку не тягаем
            if( (math.abs(ItemGetAngle(value[1]) - self.arrow_angle[key][1]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[1]) - 2 * M_PI - self.arrow_angle[key][1]) < M_PI / 10) and 
                (math.abs(ItemGetAngle(value[2]) - self.arrow_angle[key][2]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[2]) - 2 * M_PI - self.arrow_angle[key][2]) < M_PI / 10)) then
                  ItemSetOpacity(self.diods[key], 1.0)  
             end
             if( (math.abs(ItemGetAngle(value[1]) - self.arrow_angle[key][2]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[1]) - 2 * M_PI - self.arrow_angle[key][2]) < M_PI / 10) and 
                (math.abs(ItemGetAngle(value[2]) - self.arrow_angle[key][1]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[2]) - 2 * M_PI - self.arrow_angle[key][1]) < M_PI / 10)) then
                  ItemSetOpacity(self.diods[key], 1.0)  
             end
        end
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:IsMinigameCompleted()
    for key, value in pairs(self.clock_arrow) do     
        local flag = false;
        if(self.rotate_item == nil or (value[1] ~= self.rotate_item and value[2] ~= self.rotate_item)) then--стрелку не тягаем
            if( (math.abs(ItemGetAngle(value[1]) - self.arrow_angle[key][1]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[1]) - 2 * M_PI - self.arrow_angle[key][1]) < M_PI / 10) and 
                (math.abs(ItemGetAngle(value[2]) - self.arrow_angle[key][2]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[2]) - 2 * M_PI - self.arrow_angle[key][2]) < M_PI / 10)) then
                  flag = true 
             end
             if( (math.abs(ItemGetAngle(value[1]) - self.arrow_angle[key][2]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[1]) - 2 * M_PI - self.arrow_angle[key][2]) < M_PI / 10) and 
                (math.abs(ItemGetAngle(value[2]) - self.arrow_angle[key][1]) < M_PI / 10 or
                math.abs(ItemGetAngle(value[2]) - 2 * M_PI - self.arrow_angle[key][1]) < M_PI / 10)) then
                  flag = true  
             end
        end
        
        if(flag == false) then
            return false;
        end
    end
    
    return true
end
------------------------------------------------------------------------------------------------------
function GameScreen:is_arrow(item_name)
    for key, value in pairs(self.clock_arrow) do
        if(item_name == value[1] or item_name == value[2]) then
            return true;
        end
    end
    
    return false;
end
------------------------------------------------------------------------------------------------------
function GameScreen:OnSkip()
    SetState("screen_006_basement", "bomb", "activation")
    DelayedExec(1.0, function() 
        clApplication:LoadLocation("006_basement")
    end, 113)
end

function GameScreen:onObjectClick(item_name)
    if(not self.minigame_active) then return end
    
    if(self.rotate_item) then
        SetState(CURRENT_SCREEN, self.rotate_item, ""..ItemGetAngle(self.rotate_item))
        self.rotate_item = nil
        self:diod_update()
        if(self:IsMinigameCompleted()) then
            SetState("screen_006_basement", "bomb", "activation")
            DelayedExec(1.0, function()
                clApplication:LoadLocation("006_basement")
            end, 113)
        end
    elseif(self:is_arrow(item_name)) then
        self.rotate_item = item_name;
        self:diod_update()
    end
end
------------------------------------------------------------------------------------------------------
function GameScreen:Update()
    if(clApplication.game_pause) then return end
    
    if(self.rotate_item) then
        
        local pos_x = ItemGetX(self.rotate_item) + ItemGetHotSpotX(self.rotate_item)
        local pos_y = ItemGetY(self.rotate_item) + ItemGetHotSpotY(self.rotate_item)
        
        local angle = -math.atan2((messenger_table.mouse_X - pos_x), (messenger_table.mouse_Y - pos_y)) + M_PI;
        if(angle < 0) then angle = M_PI * 2 - angle end
        if(angle > M_PI * 2) then angle = angle - M_PI * 2 end
        
        ItemSetAngle(self.rotate_item, angle)
    end
end------------------------------------------------------------------------------------------------------
-------------------------------------------Mouse functions--------------------------------------------
------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------
function GameScreen:LoadScreen()
	--[[---Background---]]--
	self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "06_bomb", "graphics/minigames/06_bomb/06_bomb", 0, 0);	
   --[[
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "husky_02", "graphics/minigames/06_bomb/husky_02", 967, 964);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "husky_01", "graphics/minigames/06_bomb/husky_01", 842, 1009);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "koyla_02", "graphics/minigames/06_bomb/koyla_02", 341, 800);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "koyla_01", "graphics/minigames/06_bomb/koyla_01", 202, 920);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ettiro_02", "graphics/minigames/06_bomb/ettiro_02", 671, 722);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ettiro_01", "graphics/minigames/06_bomb/ettiro_01", 599, 753);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "qt_02", "graphics/minigames/06_bomb/qt_02", 855, 661);      
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "qt_01", "graphics/minigames/06_bomb/qt_01", 906, 552);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "classic_02", "graphics/minigames/06_bomb/classic_02", 605, 316);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "classic_01", "graphics/minigames/06_bomb/classic_01", 542, 373);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "roadmod_02", "graphics/minigames/06_bomb/roadmod_02", 292, 489);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "roadmod_01", "graphics/minigames/06_bomb/roadmod_01", 219, 430);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "filltoto_02", "graphics/minigames/06_bomb/filltoto_02",863, 244);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "filltoto_01", "graphics/minigames/06_bomb/filltoto_01", 792, 211);     
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "komrad_02", "graphics/minigames/06_bomb/komrad_02", 329, 140);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "komrad_01", "graphics/minigames/06_bomb/komrad_01", 459, 143);
    --]]
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "husky_hand_small", "graphics/minigames/06_bomb/husky_hand_small", 920, 936);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "husky_hand_big", "graphics/minigames/06_bomb/husky_hand_big", 920, 921);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "qt_hand_small", "graphics/minigames/06_bomb/qt_hand_small", 908, 561);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "qt_hand_big", "graphics/minigames/06_bomb/qt_hand_big", 908, 522);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "filltoto_hand_big", "graphics/minigames/06_bomb/filltoto_hand_big", 867, 126);     
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "filltoto_hand_small", "graphics/minigames/06_bomb/filltoto_hand_small", 867, 150);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ettiro_hand_big", "graphics/minigames/06_bomb/ettiro_hand_big", 639, 706);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "ettiro_hand_small", "graphics/minigames/06_bomb/ettiro_hand_small", 639, 722);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "classic_hand_big", "graphics/minigames/06_bomb/classic_hand_big", 615, 275);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "classic_hand_small", "graphics/minigames/06_bomb/classic_hand_small", 615, 311);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "koyla_hand_big", "graphics/minigames/06_bomb/koyla_hand_big", 304, 734);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "koyla_hand_small", "graphics/minigames/06_bomb/koyla_hand_small", 305, 765); 
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "roadmod_hand_big", "graphics/minigames/06_bomb/roadmod_hand_big", 276, 412);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "roadmod_hand_small", "graphics/minigames/06_bomb/roadmod_hand_small", 276, 429);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "komrad_hand_big", "graphics/minigames/06_bomb/komrad_hand_big", 395, 83);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "komrad_hand_small", "graphics/minigames/06_bomb/komrad_hand_small", 395, 134);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_husky", "graphics/minigames/06_bomb/diode_husky", 928, 786);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_koyla", "graphics/minigames/06_bomb/diode_koyla", 457, 1010);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_qt", "graphics/minigames/06_bomb/diode_qt", 1012, 671);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_ettiro", "graphics/minigames/06_bomb/diode_ettiro", 472, 646);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_classic", "graphics/minigames/06_bomb/diode_classic", 482, 479);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_roadmod", "graphics/minigames/06_bomb/diode_roadmod", 124, 550);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_filltoto", "graphics/minigames/06_bomb/diode_filltoto", 991, 95);
    self:CreateObj(OBJ_TYPE.ACTIVE_ALL, "diode_komrad", "graphics/minigames/06_bomb/diode_komrad", 530, 152);

    ItemSetHotSpot("husky_hand_small", 5, 61)
    ItemSetHotSpot("husky_hand_big", 5, 77)
    ItemSetHotSpot("qt_hand_small", 9, 72)
    ItemSetHotSpot("qt_hand_big", 9, 112)
    ItemSetHotSpot("filltoto_hand_big", 10, 81)
    ItemSetHotSpot("filltoto_hand_small", 10, 57)
    ItemSetHotSpot("ettiro_hand_big", 7, 55)
    ItemSetHotSpot("ettiro_hand_small", 7, 38)
    ItemSetHotSpot("classic_hand_big", 5, 110)
    ItemSetHotSpot("classic_hand_small", 5, 74)
    ItemSetHotSpot("koyla_hand_big", 7, 153)
    ItemSetHotSpot("koyla_hand_small", 7, 124)
    ItemSetHotSpot("roadmod_hand_big", 7, 57)
    ItemSetHotSpot("roadmod_hand_small", 7, 41)
    ItemSetHotSpot("komrad_hand_big", 8, 103)
    ItemSetHotSpot("komrad_hand_small", 8, 52)
    
    
    clScreenManager:add_screen("hud") 
end