//-----------------------------------------------------
// Name: Die()
// Desc: When the player dies
//-----------------------------------------------------
Die(x, y)
{
	// Make the player spin round and fall
	static PlayerSpin = 0;
	static SpinTotal  = 0;
	static float: DeathCount = 0.00;
	static float: MusicFade  = 255.00;
	static float: GameOverAlpha = 0.00;
	// Fade the music out
	MusicFade -= 100 * GetTimeDelta();
	if (MusicFade < 50)
		MusicFade = 50.00;
	SetMusicVolume( floatround(MusicFade) );
		
	
	// Fade the screen to almost black
	FadeTo(100,100,100,100);
	
	// Increment the death count
	DeathCount += 1200 * GetTimeDelta();
	if ( DeathCount > 100 )
	{
		DeathCount = 0.00;
		PlayerSpin+=1;
	}
	
	if ( PlayerSpin >= 4 )
	{
		PlayerSpin = 0;
		SpinTotal+=1;
	}
	
	if ( SpinTotal > 4 )
	{
		// The game should reach this point after the gameover screen, as the game will
		// Become unpaused again, this is our chance to reset the players data
		if (GetPauseLevel() == 0 && !sentfairy)
		{
			// Game over screen is done - player is probably back at last continuation point
			SpinTotal = 0;
			PlayerSpin = 0;
			DeathCount = 0.00
			SetState("this", standing);
			SetDeadFlag("this", false);
			SetHealth("this", 300);
			FadeTo(255,255,255,200);
			SetMusicVolume( 255 );
			MusicFade = 255.00;
			GameOverAlpha = 0.00;
			SetSpeedMod("this", 0);
			return;
		}
		else if(GetState("DeathFairy") == dying && sentfairy)
		{
			SpinTotal = 0;
			PlayerSpin = 0;
			DeathCount = 0.00
			MusicFade = 255.00;
			GameOverAlpha = 0.00;
			SetState("this", standing);
			SetDeadFlag("this", false);
			SetSpeedMod("this", 0);
			FadeTo(255,255,255,200);
			SetMusicVolume( 255 );
			FlashCount = 2.00;
			Flashing = true;
			sentfairy = false;
			return;
		}
		// Draw the player on the ground
		if (isVisible("this"))
			PutSprite(playerDead, x, y, y + 16, 0, 255, 255, 255, 200);
		new fairystat;
		fairystat = CallFunction("DeathFairy", 0, "SendDeathFairy", "NULL");
		if(fairystat == -1)
		{
			// Make the GAME OVER sprites fade in
			GameOverAlpha += 35 * GetTimeDelta();
			if (GameOverAlpha >= 255)
				GameOverAlpha = 255.00;
			DrawImage("_gameover", 280, 150, 255, 255, 255, floatround(GameOverAlpha), 0, 200);
			GameOver();
			Restart = true;
			fairystat = 0;
		}
		else if (fairystat == 2)
		{
			sentfairy = true;
			fairystat = 0;
		}
	}
	else
	{
		// Get the width and height of the Current Image
		new height = GetHeight(playerStand[PlayerSpin]);
		
		// Draw the Body and the Head images
		if (isVisible("this"))
		{
			PutSprite(playerStand[PlayerSpin], x, y, y + height);
			PutSprite(playerHead[PlayerSpin], x, y - headDist, y + height);
			PutSprite("shadow1", x, y, 2, 0, 255, 255, 255, SHADOW);
		}
	}
}
