package  
{
	import net.flashpunk.Entity
	import net.flashpunk.FP
	import net.flashpunk.World
	import net.flashpunk.graphics.Image
	import net.flashpunk.tweens.misc.VarTween
	import net.flashpunk.utils.Input
	import net.flashpunk.utils.Ease
	import net.flashpunk.Sfx;
	
	public class TitleWorld extends World
	{
		protected var touched:Boolean = false;
		protected var title:Entity;
		protected var button:Entity;
		protected var buttonSelect:Entity;
		
		/*title world graphics*/
		[Embed(source = '../assets/gfx/title_screen.png')]
		public static const GFX_TITLE:Class;
		[Embed(source = '../assets/gfx/button.png')]
		public static const GFX_BUTTON:Class;
		[Embed(source = '../assets/gfx/buttonSelect.png')]
		public static const GFX_BUTTON_SELECT:Class;
		/************************************************************/
		/*title world sounds*/
		[Embed(source = '../assets/sfx/Megadeth - Never Dead.mp3')] 
		private const INTRO:Class;
		public var Intro:Sfx = new Sfx(INTRO);
		/************************************************************/
		public function TitleWorld() 
		{
			super();
		}
		
		override public function begin():void
		{
			Intro.loop();
			
			//adds images to the screen
			buttonSelect = addGraphic(new Image(GFX_BUTTON_SELECT));
			buttonSelect.y = (FP.screen.height / 4) * 3;
			buttonSelect.x = FP.screen.width / 2;
			
			title = addGraphic(new Image(GFX_TITLE));
			title.x = 0;
			title.y = 0;
			
			button = addGraphic(new Image(GFX_BUTTON));
			button.y = (FP.screen.height / 4) * 3;
			button.x = FP.screen.width / 2;
		}
		
		override public function update():void
		{
				if (mouseX > (FP.screen.width / 2) && mouseX < (FP.screen.width / 2 + 124))
				{
					if (mouseY > ((FP.screen.height / 4) * 3) && mouseY < (((FP.screen.height / 4) * 3) +59))
					{
						touched = true;
						sendBackward(title);
						if (Input.mousePressed)
						{
							Intro.stop();
							//handle condition for going to next world
							FP.world = new CharacterWorld();
						}
					}
					else
					{
						if (touched)
						{
							bringForward(title);
							touched = false;
						}
					}
				}
				else
				{
					if (touched)
					{
						bringForward(title);
						touched = false;
					}
				}
		}
		
		
	}

}