function onCreate()
	luaDebugMode = true;
	runHaxeCode([[
		import substates.GameOverSubstate;
		function setOverStuff() {
			GameOverSubstate.instance.boyfriend.animation.callback = function(n, f) {
				parentLua.call('deadFrame', [n, f]);
			}
		}
	]]);
	
	makeAnimatedLuaSprite('deathRetry', 'characters/retry');
	addAnimationByPrefix('deathRetry', 'idle', 'Idle', 0, false);
	addAnimationByPrefix('deathRetry', 'loop', 'Loop');
	addAnimationByPrefix('deathRetry', 'retry', 'Retry', 24, false);
	addOffset('deathRetry', 'idle', 0, 0);
	addOffset('deathRetry', 'loop', 19, 2);
	addOffset('deathRetry', 'retry', 89, 94);
	setScrollFactor('deathRetry');
	addLuaSprite('deathRetry');
	screenCenter('deathRetry');
	setProperty('deathRetry.y', getProperty('deathRetry.y') - 40);
	setProperty('deathRetry.antialiasing', false);
	setProperty('deathRetry.alpha', 0.00001);
end

function onSongStart() setProperty('deathRetry.alpha', 0); end

local iconToDeath = {
	['zephthanks'] = 'feast-zeph-dead',
	['godz'] = 'feast-z-dead',
	['tenma'] = 'feast-tenma-dead'
};
function killCheck(c)
	local c = iconToDeath[c];
	local loopMus = ((c == iconToDeath['tenma']) and 'loop-tenma' or 'loop');
	setPropertyFromClass('substates.GameOverSubstate', 'characterName', c);
	setPropertyFromClass('substates.GameOverSubstate', 'deathSoundName', 'start-feast');
	setPropertyFromClass('substates.GameOverSubstate', 'loopSoundName', loopMus);
	setPropertyFromClass('substates.GameOverSubstate', 'endSoundName', 'end-feast');
end

function onGameOverStart()
	runHaxeFunction('setOverStuff');
	removeLuaSprite('deathRetry', false);
	addLuaSprite('deathRetry');
end

function onUpdatePost()
	if inGameOver then setProperty('camGame.followLerp', 0); end
end

local otherAnim = true;
function deadFrame(n, f)
	if n == 'firstDeath' then
		if f > 34 then setProperty('deathRetry.alpha', ((f - 35) / 23)); end
	elseif otherAnim then
		if n == 'deathLoop' then playAnim('deathRetry', 'loop'); end
		otherAnim = false;
		setProperty('deathRetry.alpha', 1);
	end
end

function onGameOverConfirm(t)
	if t then playAnim('deathRetry', 'retry'); end
end
