import backend.MusicBeatState;

function onGameOver()
{
	CustomSubstate.openCustomSubstate('gameover', true);
	return Function_Stop;
}

function onCustomSubstateCreate(state)
{
	//
	
	FlxG.sound.play(Paths.sound('axomfuckingdies'));
	
	var death = 'death' + FlxG.random.int(1, 3);
	var sprite = new FlxSprite().loadFromSheet(Paths.getSparrowAtlas('gameovers/' + death), death);
	sprite.cameras = [camOther];
	sprite.animation.curAnim.looped = false;
	sprite.setGraphicSize(FlxG.width);
	sprite.updateHitbox();
	sprite.scrollFactor.set();
	sprite.screenCenter();
	
	CustomSubstate.instance.add(sprite);
	
	sprite.visible = false;
	sprite.active = false;
	
	FlxTimer.wait(2, () -> {
		sprite.active = sprite.visible = true;
	});
	
	camOther._fxFadeColor = FlxColor.BLACK;
	
	sprite.animation.onFinish.addOnce((anim) -> {
		FlxTween.tween(camOther, {_fxFadeAlpha: 1}, 2,
			{
				onComplete: Void -> {
					MusicBeatState.resetState();
				}
			});
	});
}
