--Por Nickobelit
--Si lo usas en algún otro lado solo déjame créditos

function onGameOver()
setProperty('GodP.alpha', 0)
canPause = false
end

function onSongStart()
pauseCustom = false
canPause = true
doTweenAlpha('holaGod', 'GodP', 1, 0.2,'linear')
end

function onEndSong()
	setProperty('GodP.alpha', 0)
	canPause = false
end

function onPause()
	return Function_Stop;
end

function onCreate()  
        makeLuaSprite('greyBG', '', 0, 0);
        makeGraphic('greyBG',screenWidth,screenHeight,'000000')
	    setObjectCamera('greyBG','other')
        addLuaSprite('greyBG', false);
        setProperty('greyBG.alpha',0)
    
        makeLuaSprite('cuadroPause', 'pauseLoud/PauseCuadro', 160,50)
        addLuaSprite('cuadroPause', true)
        scaleObject('cuadroPause',0.6,0.6)
        setObjectCamera('cuadroPause', 'other')
        setProperty('cuadroPause.alpha', 0)
        
        makeLuaSprite('GodP', 'pauseLoud/PauseThing', 0, 660);
		addLuaSprite('GodP', true);
		scaleObject('GodP', 0.6,0.6);
		setProperty('GodP.alpha', 0)
		setObjectCamera('GodP', 'other')
end

function onUpdatePost(elapsed)
	if (getMouseX('camHUD') > 0 and getMouseX('camHUD') < 70) and (getMouseY('camHUD') > 635 and getMouseY('camHUD') < 720 and mouseClicked('left')) and pauseCustom == false and not getPropertyFromClass('flixel.FlxG', 'keys.justPressed.SPACE') and canPause or keyJustPressed('accept') and pauseCustom == false and not getPropertyFromClass('flixel.FlxG', 'keys.justPressed.SPACE') and canPause then
	   doTweenAlpha('holaGrey', 'greyBG', 0.7, 0.2,'linear')      
       doTweenAlpha('holaCuadro', 'cuadroPause', 1, 0.2,'linear')      
       doTweenAlpha('adiosGod', 'GodP', 0, 0.2,'linear')      
       setProperty('GodP.alpha', 0)
       runTimer('hola',0.2)
       pauseCustom = true
       setPropertyFromClass('flixel.FlxG','mouse.visible',true);
end
    
   if (getMouseX('camHUD') > 395 and getMouseX('camHUD') < 490) and (getMouseY('camHUD') > 450 and getMouseY('camHUD') < 530 and mouseClicked('left')) and pauseCustom == true and continue == true then   
      doTweenAlpha('adiosGrey', 'greyBG', 0, 0.2,'linear')         
      doTweenAlpha('adiosCuadro', 'cuadroPause', 0, 0.2,'linear')      
      doTweenAlpha('holaGod', 'GodP', 1, 0.2,'linear')      
      runTimer('adios',0.2)
      pauseCustom = false
      setPropertyFromClass('flixel.FlxG','mouse.visible',false);
        end
        
     
      if (getMouseX('camHUD') > 560 and getMouseX('camHUD') < 665) and (getMouseY('camHUD') > 450 and getMouseY('camHUD') < 530 and mouseClicked('left')) and pauseCustom == true and restart == true then     
		continue = false
		exit = false
		restart = false
		doTweenAlpha('adiosHud', 'camHUD', 0, 1,'quartOut')
		doTweenAlpha('adiosGame', 'camGame', 0, 1,'quartOut')
		doTweenAlpha('adiosOther', 'camOther', 0, 1,'quartOut')
		runTimer('restart',1)
		setPropertyFromClass('flixel.FlxG','mouse.visible',false);
end

if (getMouseX('camHUD') > 735 and getMouseX('camHUD') < 840) and (getMouseY('camHUD') > 450 and getMouseY('camHUD') < 530 and mouseClicked('left')) and pauseCustom == true and exit == true then
		continue = false
		exit = false
		restart = false
		exitSong(true)
		setPropertyFromClass('flixel.FlxG','mouse.visible',false);
end

      if pauseCustom == true then
		setPropertyFromClass('Conductor', 'songPosition', getPropertyFromClass('Conductor', 'songPosition') - elapsed * 1000)
		setPropertyFromClass('flixel.FlxG', 'sound.music.time', getPropertyFromClass('Conductor', 'songPosition'))
		setProperty('vocals.time', getPropertyFromClass('Conductor', 'songPosition'))
		setPropertyFromClass('flixel.FlxG', 'sound.music.volume', 0)
		setProperty('vocals.volume', 0)
		setPropertyFromClass('PlayState', 'instance.generatedMusic', false)
	elseif pauseCustom == false and canPause then
		setPropertyFromClass('flixel.FlxG', 'sound.music.volume', 1)
		setPropertyFromClass('PlayState', 'instance.generatedMusic', true)
	end
end

function onTimerCompleted(tag, loops, loopsLeft)
if tag == 'hola' then
        continue = true
		exit = true
		restart = true
		
end 

if tag == 'adios' then
        continue = false
		exit = false
		restart = false
end 

if tag == 'restart' then 
		restartSong(true)
	end
end