using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input.Touch;

namespace SpaceWinnie
{
	public class Winnie
	{
		Main game;
		Model winnie;

		Rectangle left, right;

		float x, gox;

		public float X { get { return gox; } set { gox = value; } }

		public Winnie ( Game game )
		{
			winnie = game.Content.Load<Model> ( "rocket2" );
			this.game = game as Main;
			x = gox = 0;

			left = new Rectangle ( 0, 0, 400, 480 );
			right = new Rectangle ( 401, 0, 400, 480 );
		}

		public void Update ( GameTime gameTime )
		{
			foreach ( TouchLocation loc in TouchPanel.GetState () )
			{
				if ( loc.State == TouchLocationState.Pressed )
				{
					Rectangle t = new Rectangle ( ( int ) loc.Position.X, ( int ) loc.Position.Y, 1, 1 );
					if ( left.Intersects ( t ) )
						if ( X != -1.5f )
							X -= 1.5f;
					if ( right.Intersects ( t ) )
						if ( X != 1.5f )
							X += 1.5f;
				}
			}

			if ( gox > x )
				x += 0.375f;
			else if ( gox < x )
				x -= 0.375f;
		}

		public void Draw ( GameTime gameTime )
		{
			foreach ( ModelMesh m in winnie.Meshes )
			{
				foreach ( BasicEffect b in m.Effects )
				{
					b.EnableDefaultLighting ();
					b.World = Matrix.CreateScale ( 0.01f ) * Matrix.CreateTranslation ( x, 0, -2 );
					b.View = ( game as Main ).Camera.ViewMatrix;
					b.Projection = ( game as Main ).Camera.ProjectionMatrix;
				}

				m.Draw ();
			}
		}
	}
}
