using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using Library2D;

namespace GraveyardGraph
{
	public class Player : CircleCollidable
	{
		public Player (Vector2 center)
		{
			this.Center = center;
			this.Radius = 16;
		}

		public override void CalculateNewVel(CircleCollidable that)
		{
			if (that.GetType() == typeof(Wave))
			{
				//wave physics
				Wave wave = (Wave) that;
				float mass1 = this.Radius;
				float x1 = this.Velocity.X;
				float y1 = this.Velocity.Y;
				Vector2 direction = (this.Center - wave.Center);
				direction.Normalize();

				/*
				float newX1 = (x1 * (mass1 - wave.getForce()) + (2 * wave.getForce() * direction.X) / (mass1 + wave.getForce()));
				float newY1 = (y1 * (mass1 - wave.getForce()) + (2 * wave.getForce() * direction.Y) / (mass1 + wave.getForce()));

				Vector2 newVec1 = new Vector2(newX1, newY1);
				if (newVec1.Length() > 1000 * Wave.DELTA)
				{
					newVec1.Normalize();
					newVec1 *= 1 * Wave.DELTA;
				}
				this.AttemptedMotion = newVec1 * Math.Min((this.AttemptedMotion.Length() / newVec1.Length()), 1);
				this.Velocity = newVec1;*/
				this.Velocity += direction * wave.getForce();
				if (this.Velocity.Length() > 1000 * Wave.DELTA)
				{
					this.Velocity.Normalize();
					this.Velocity *= 1000 * Wave.DELTA;
				}
			}
		}

		public override void Draw(Rectangle drawArea, SpriteBatch sb, GameTime time)
		{
			sb.Draw(ArtFetcher.AnimatedJelly.GetFrame(time), new Rectangle((int) Game1.CenterToUpperLeft(Center).X,
															  (int) Game1.CenterToUpperLeft(Center).Y,
																	Game1.TILE_SIZE,
																	Game1.TILE_SIZE), Color.White);
		}
	}
}

