using System;
using System.Collections.Generic;
using System.Text;
using DxLibDLL;

using Box2DX.Dynamics.Controllers;
using Box2DX.Collision;
using Box2DX.Dynamics;
using Box2DX.Common;

namespace Nlgp1.B2DX
{
	public class CevTest : ContactEvent
	{
		public static bool isRaycast=false;

		public override void Persist(ContactPoint point)
		{
			base.Persist(point);
			if (((myUserData)point.Shape1.GetBody().GetUserData()).name == "player")
				playerhit(point.Shape1, point.Shape2);
			if (((myUserData)point.Shape2.GetBody().GetUserData()).name == "player")
				playerhit(point.Shape2, point.Shape1);
		}

		public override void Add(ContactPoint point)
		{
			base.Add(point);
			Shape s1 = point.Shape1, s2 = point.Shape2;
			if (((myUserData)s1.GetBody().GetUserData()).name == "player" && ((float)(int)point.Position.Y == CalcfromShape.GetBottom(s2)))
				playerhit(s1,s2);
			if (((myUserData)s2.GetBody().GetUserData()).name == "player" && ((float)(int)point.Position.Y == CalcfromShape.GetBottom(s1)))
				playerhit(s2,s1);
		}
		void playerhit(Shape player,Shape another)
		{
			if (((myUserData)another.GetBody().GetUserData()).name == "sail")
			//todo myUserdataにRaycastとかさせるべきか				
			{
				myUserData data=(myUserData)player.GetBody().GetUserData();
				data.filter.MaskBits = Convert.ToUInt16("100000", 2);
				isRaycast = true;
				//dataはplayerである、下から当たった場合、playerはマスクビットを変更する、
				//当たった物の高さ分上にRayをあて、Rayに当たったものがそれなら、マスクビットを元に戻す
			}
		}

		

	}
}