using System;
using System.Collections;

using Icarus.Logic;
using Icarus.Logic.Physics;
using Icarus.Logic.GameEngine;
using Icarus.Input;
using Icarus.Renderer;
using Icarus.Graphics.Animation;

using TuxHunter.UI;

namespace TuxHunter.GameStates
{
	/// <summary>
	/// This state represents the state of playing the game. Hopefully, most time of a player will be spent here. :) Note that for every level, a new state should be created.
	/// </summary>
	public class GameplayState : GameStateAdapter
	{
		/// <summary>
		/// The level we are currently playing.
		/// </summary>
		private Level mGameLevel;

		/// <summary>
		/// The thing that will be rendering the level.
		/// </summary>
		private ViewRenderer mViewRenderer;

		/// <summary>
		/// The UI stuff that shows the player what's goin' on.
		/// </summary>
		private InGameHud mInfoDisplay;

		/// <summary>
		/// Initializes the gameplay state.
		/// </summary>
		/// <param name="l">Which level should we be playing?</param>
		public GameplayState(Level l)
		{
			this.mGameLevel = l;
            PhysicsEngine.Instance.currentLevel = l;

			mInfoDisplay = new InGameHud();
			mInfoDisplay.Location = new System.Drawing.Point(10, 10);
			mInfoDisplay.IsVisible = true;
		}

		/// <summary>
		/// Gets the level we are currently playing.
		/// </summary>
		public Level Level
		{
			get { return mGameLevel; }
		}

		/// <summary>
		/// Gets the view renderer.
		/// </summary>
		public ViewRenderer ViewRenderer
		{
			get { return mViewRenderer; }
		}

		/// <summary>
		/// Performs the necessary initializations upon entering the state.
		/// </summary>
		public override void Enter()
		{
			this.mViewRenderer = new ViewRenderer();
			this.Unpause();
		}

		public override void Unpause()
		{
			InputEngine.Instance.StartListening();
		}

		/// <summary>
		/// Updates the state of the world.
		/// </summary>
		/// <param name="millis"></param>
		public override void Step(int millis)
		{
			PhysicsEngine.Instance.updateWorld(this.Level.CurrStage.actorList);
		}

		/// <summary>
		/// Renders the level.
		/// </summary>
		/// <param name="parameters"></param>
		public override void RenderState(IRenderParameters parameters)
		{
			this.mViewRenderer.Render(this.Level, parameters);

			// Set the health bar display:
			mInfoDisplay.PlayerHealth = (int) Level.CurrStage.PlayerActor.GameStats.Health;

			this.mInfoDisplay.Render(new System.Drawing.Point(0, 0), parameters);
		}

		public override void Pause()
		{
			InputEngine.Instance.StopListening();
		}

		public override void Exit()
		{
			this.Pause();
		}

		private void ProcessInputs()
		{
		}
	}
}
