package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
//import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.math.FlxMath;
using flixel.util.FlxSpriteUtil;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxTween;
import flixel.tweens.FlxEase;
import flixel.util.FlxTimer;
import flixel.system.FlxSound;
/**
 * A FlxState which can be used for the game's menu.
 */
class MenuState extends FlxState
{

	// public var _music:FlxSound;

	//private var _playButton:FlxButton;
	/**
	 * Function that is called up when to state is created to set it up. 
	 */
	override public function create():Void
	{
		// _music = FlxG.sound.load("assets/music/pig-si-bonne.wav",1);

		FlxG.camera.flash(0x00000000,.5);
		FlxG.sound.playMusic("assets/music/music.wav", 1, true);
		

		var _bg:FlxSprite = new FlxSprite(0,0);
		_bg.loadGraphic("assets/images/menu.png",false,320,180);
		add(_bg);

		
		super.create();
		}
	
	/**
	 * Function that is called when this state is destroyed - you might want to 
	 * consider setting all objects this state uses to null to help garbage collection.
	 */
	override public function destroy():Void
	{
		super.destroy();
	}

	/**
	 * Function that is called once every frame.
	 */
	override public function update(elapsed:Float):Void
	{
		

		checkEnterButton();

			super.update(elapsed);

	}	

		private function playGame():Void
	{
		FlxG.log.add("switching state 1");
		FlxG.switchState(new PlayState());
		FlxG.log.add("switching state 2");
	}	

	private function checkEnterButton():Void
	{

		if(FlxG.keys.anyJustReleased([SPACE]) )
		{
		playGame();
		FlxG.log.add("enter pressed");
		}
	}
}