--[[

PROGRAM NAME:	LUA SINGE ENGINE
VERSION:		3.32b
AUTHOR:			KARIS (2021)

This file is part of LUA SINGE ENGINE.

	LUA SINGE ENGINE is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation.

	LUA SINGE ENGINE is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

	Thanks to Scott Duensing, RDG.

]]--

iSecs = 0
iLimit = 0
lastSeconds = 0
thisSeconds = 0

sprText = nil
sprShadow = nil
sLastText = nil
iLastColor = -1
iLastShadow = -1

tSecs = 0
tLimit = 0
tlastSeconds = 0
tthisSeconds = 0
bTommy = false

bGunMute = false
iMuteFrames = 0
MUTE_DELAY = 35

heartbeat = false
blinkSecs = 0
lastBlinkSecs = 0

iRevFrames = 0
REV_DELAY = 10
bReversePointer = false
revsetx = 0; revsety = 0

iFrameStart = 0; iFrameEnd = 0

CHANNEL_LEFT = 1
CHANNEL_RIGHT = 2
ALL_CHANNELS = 3
bMuteAttract = false

RED = 0
BLUE = 1
YELLOW = 2
GREEN = 3
ORANGE = 4
WHITE = 5
GREY = 6; GRAY = 6
LIGHTBLUE = 7
BLACK = 8
PINK = 9
MISC = 10


function blinkTimer(thisMS)

	-- Function blinks every second.

	blinkSecs = os.clock()
	
	if bPause then
	
		lastBlinkSecs = blinkSecs
		
	else

		if (blinkSecs - lastBlinkSecs > thisMS) then
			heartbeat = not heartbeat
			lastBlinkSecs = blinkSecs

		end
		
	end	
	
end

function goTimer(thisMS)

	blinkSecs = os.clock()
	
	if bPause then
	
		lastBlinkSecs = blinkSecs
		
	else

		if (blinkSecs - lastBlinkSecs > thisMS) then
			heartbeat = true
			lastBlinkSecs = blinkSecs

		end
		
	end	
	
end

function timerOFF()

	iSecs = 0
	iLimit = 0
	
end

function timerON(thisLong)

	iSecs = 0
	iLimit = thisLong
	lastSeconds = os.clock()
	
end

function timerDue()
	
	thisSeconds = os.clock()
	
	if bPause then
		
		lastSeconds = thisSeconds 
		
	else
		
		if (thisSeconds ~= lastSeconds) then		
			
			iSecs = iSecs + thisSeconds - lastSeconds
			lastSeconds = thisSeconds 		
						
		end
		
		if (iSecs >= iLimit) then

			timerOFF()
			return true
			
		else		
			
			return false
		
		end	
	
	end

end


function muteSound()
	
	iMuteFrames = 0
	bGunMute = true

end

function blinkRev()

	iRevFrames = 0
	bReversePointer = true

end

function setupClip(thisA, thisB)

	iFrameStart = thisA
	iFrameEnd = thisB
	
	discSkipToFrame(thisA)					

end

function monoAudio (thisChannel)

	if thisChannel == CHANNEL_LEFT then
	
		discAudio (2, false)
		discAudio (1, true)
		
	elseif thisChannel == CHANNEL_RIGHT then
	
		discAudio (1, false)
		discAudio (2, true)
		
	end

end

function resetChannels()

	discAudio(1, true)
	discAudio(2, true)
	
end

function muteAudio()

	discAudio(1, false)
	discAudio(2, false)

end

function setFontColor(thisColor)

	if thisColor == 1 then
	
		colorForeground(255, 255, 255)

	elseif thisColor == 2 then

		colorForeground(255, 0, 0)
	
	elseif thisColor == 3 then
	
		colorForeground(0, 0, 255)
	
	elseif thisColor == 4 then
	
		colorForeground(255, 255, 0)
	
	elseif thisColor == 5 then
	
		colorForeground(0, 255, 0)
	
	elseif thisColor == 6 then
	
		colorForeground(255, 150, 0)

	elseif thisColor == 7 then
	
		colorForeground(252,0,148)

	elseif thisColor == 8 then
	
		colorForeground(127,0,255)

	elseif thisColor == 9 then
	
		colorForeground(30, 160, 250)
			
	elseif thisColor == 10 then
	
		colorForeground(128, 128, 128)
	
	elseif thisColor == 11 then

		colorForeground(1,0,0)

	elseif thisColor == 12 then
	
		colorForeground(miscR,miscG,miscB)
	
	end

end

function textPrint(thisMsg, thisx, thisy, thisFont, thisColor, thisShadow)	
	
	fontSelect(thisFont)
	setFontColor(thisColor)
	fontPrint(thisx,thisy,thisMsg)

end

function getMiddle(thisPhrase)

	local x = 0
	local y = 0
	local phrase = fontToSprite(thisPhrase)

	x = OVLW/2 - spriteGetWidth(phrase) * 0.5

	spriteUnload(phrase)
	
	return x

end
