Example #1
0
        //必须调用!
        public void SetBoundBoxInfor( BoundBox bb)
        {
            float w = bb.Width*0.5f;
            float h = bb.Height*0.5f;
            Vector2 pos = new Vector2(bb.X,bb.Y);
            //			//AABB
            //			aabbPoints[0].SetPosition(new Vector2(-w, -h) + pos);
            //            aabbPoints[1].SetPosition(new Vector2(w, -h) + pos);
            //            aabbPoints[2].SetPosition(new Vector2(w, h) + pos);
            //            aabbPoints[3].SetPosition(new Vector2(-w, h) + pos);
            //			//OBB
            //			if(bb.Obb !=null)
            //			{
            //			  List<Vector2> ps = bb.Obb.GetPoints();
            //			  obbPoints[0].SetPosition(ps[0]);
            //			  obbPoints[1].SetPosition(ps[1]);
            //			  obbPoints[2].SetPosition(ps[2]);
            //			  obbPoints[3].SetPosition(ps[3]);
            //			}
            //Circle
            if (bb.Circle != null)
            {
                circlePoints [0].SetPosition (GameBase.Up * bb.Circle.Radius + pos);
                circlePoints [1].SetPosition (GameBase.Down * bb.Circle.Radius + pos);
                circlePoints [2].SetPosition (GameBase.Left * bb.Circle.Radius + pos);
                circlePoints [3].SetPosition (GameBase.Right * bb.Circle.Radius + pos);

                circlePoints [4].SetPosition ((GameBase.Up + GameBase.Left).Normalize () * bb.Circle.Radius + pos);
                circlePoints [5].SetPosition ((GameBase.Down + GameBase.Left).Normalize () * bb.Circle.Radius + pos);
                circlePoints [6].SetPosition ((GameBase.Up + GameBase.Right).Normalize () * bb.Circle.Radius + pos);
                circlePoints [7].SetPosition ((GameBase.Down + GameBase.Right).Normalize () * bb.Circle.Radius + pos);
            }
        }
Example #2
0
        //必须调用!
        public void SetBoundBoxInfor(BoundBox bb)
        {
            float   w   = bb.Width * 0.5f;
            float   h   = bb.Height * 0.5f;
            Vector2 pos = new Vector2(bb.X, bb.Y);

//			//AABB
//			aabbPoints[0].SetPosition(new Vector2(-w, -h) + pos);
//            aabbPoints[1].SetPosition(new Vector2(w, -h) + pos);
//            aabbPoints[2].SetPosition(new Vector2(w, h) + pos);
//            aabbPoints[3].SetPosition(new Vector2(-w, h) + pos);
//			//OBB
//			if(bb.Obb !=null)
//			{
//			  List<Vector2> ps = bb.Obb.GetPoints();
//			  obbPoints[0].SetPosition(ps[0]);
//			  obbPoints[1].SetPosition(ps[1]);
//			  obbPoints[2].SetPosition(ps[2]);
//			  obbPoints[3].SetPosition(ps[3]);
//			}
            //Circle
            if (bb.Circle != null)
            {
                circlePoints [0].SetPosition(GameBase.Up * bb.Circle.Radius + pos);
                circlePoints [1].SetPosition(GameBase.Down * bb.Circle.Radius + pos);
                circlePoints [2].SetPosition(GameBase.Left * bb.Circle.Radius + pos);
                circlePoints [3].SetPosition(GameBase.Right * bb.Circle.Radius + pos);

                circlePoints [4].SetPosition((GameBase.Up + GameBase.Left).Normalize() * bb.Circle.Radius + pos);
                circlePoints [5].SetPosition((GameBase.Down + GameBase.Left).Normalize() * bb.Circle.Radius + pos);
                circlePoints [6].SetPosition((GameBase.Up + GameBase.Right).Normalize() * bb.Circle.Radius + pos);
                circlePoints [7].SetPosition((GameBase.Down + GameBase.Right).Normalize() * bb.Circle.Radius + pos);
            }
        }
Example #3
0
        //碰撞检测
        //获取包围盒
        public virtual BoundBox GetBoundBox()
        {
            BoundBox bb = new BoundBox(Center.X, Center.Y, Width, Heigth);

            //drawBoundBox.SetBoundBoxInfor(bb);

            return(bb);
        }
Example #4
0
        //碰见检测,主动init--被动pass
        private void Contacting(List <LiveObject> init, List <LiveObject> pass)
        {
            foreach (LiveObject oinit in init)
            {
                foreach (LiveObject opass in pass)
                {
                    if (oinit.status == ObjectStatus.Die ||
                        opass.status == ObjectStatus.Die)
                    {
                        return;
                    }

                    BoundBox bbInit = oinit.GetBoundBox();
                    BoundBox bbPass = opass.GetBoundBox();
                    bool     isc    = false;

                    if (bbInit == null || bbPass == null)
                    {
                        return;
                    }

                    //用什么检测
                    if (bbInit.IsUseCircle == true || bbPass.IsUseCircle == true)
                    {                    //用圆形
                        isc = Circle.IsContacted(bbInit.Circle, bbPass.Circle);
                    }
                    else
                    {                    //用AABB
                        isc = BoundBox.IsContacted(bbInit, bbPass);
                    }
                    if (isc == true)
                    {
                        oinit.ToContact(opass);
                        opass.BeContact(oinit);
                    }
//					3中检测
//					AABB
//					bool iscaabb = BoundBox.IsContacted (oinit.GetBoundBox (), opass.GetBoundBox ());
//
//					bool iscobb = false;
//					if (iscaabb == true && oinit.GetBoundBox ().Obb != null &&
//					   opass.GetBoundBox ().Obb != null)
//					{//有OBB
//						iscobb = OBB.IsContacted (oinit.GetBoundBox ().Obb, opass.GetBoundBox ().Obb);
//					}
//
//					bool iscc = Circle.IsContacted (oinit.GetBoundBox ().Circle, opass.GetBoundBox ().Circle);
//
//					if (iscaabb == true || iscobb == true || iscc == true)
//					{
//						oinit.ToContact (opass);
//						opass.BeContact (oinit);
//					}
                }
            }
        }
Example #5
0
        /// <summary>
        /// AABB
        /// </summary>
        public static bool IsContacted(BoundBox aabb1,BoundBox aabb2)
        {
            float x1 = (aabb1.X*2 + aabb1.Width)/2;
            float x2 = (aabb2.X*2 + aabb2.Width)/2;
            float y1 = (aabb1.Y*2 + aabb1.Height)/2;
            float y2 = (aabb2.Y*2 + aabb2.Height)/2;

            if(Math.Abs(x2-x1) <= (aabb1.Width + aabb2.Width)/2 && Math.Abs(y2-y1)
               <= (aabb1.Height + aabb2.Height)/2)
                return true;
            else
                return false;
        }
Example #6
0
 /// <summary>
 /// PSVX精灵类
 /// </summary>
 /// <param name='scene'>
 /// 精灵所在场景
 /// </param>
 /// <param name='path'>
 /// 精灵纹理
 /// </param>
 /// <param name='vector'>
 /// 精灵坐标
 /// </param>
 /// <param name='rectangle'>
 /// 切分的矩形.
 /// </param>
 public SpriteX(Node node, string path, Vector2 vector, BoundBox rectangle)
 {
     if (System.IO.File.Exists(@"/Application/Content/Pic/" + path))
     {
         this.TextureInfo = new TextureInfo(CutTexture(@"/Application/Content/Pic/" + path, rectangle));
     }
     else
     {
         DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
     }
     this.Quad.S = TextureInfo.TextureSizef;
     this.CenterSprite(TRS.Local.TopLeft);
     this.Position   = new Vector2(vector.X, 544.0f - vector.Y);
     this.fatherNode = node;
     node.AddChild(this);
 }
Example #7
0
        /// <summary>
        /// AABB
        /// </summary>
        public static bool IsContacted(BoundBox aabb1, BoundBox aabb2)
        {
            float x1 = (aabb1.X * 2 + aabb1.Width) / 2;
            float x2 = (aabb2.X * 2 + aabb2.Width) / 2;
            float y1 = (aabb1.Y * 2 + aabb1.Height) / 2;
            float y2 = (aabb2.Y * 2 + aabb2.Height) / 2;

            if (Math.Abs(x2 - x1) <= (aabb1.Width + aabb2.Width) / 2 && Math.Abs(y2 - y1)
                <= (aabb1.Height + aabb2.Height) / 2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        private Texture2D CutTexture(string path, BoundBox rectangle)
        {
            ImageRect imageRect = new ImageRect((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);

            if (System.IO.File.Exists(@"/Application/Content/Pic/" + path))
            {
                Image image = new Image(@"/Application/Content/Pic/" + path);
                image.Decode();

                texture = new Texture2D((int)rectangle.Width, (int)rectangle.Height, false, PixelFormat.Rgba);
                texture.SetPixels(0, image.Crop(imageRect).ToBuffer());
                image.Dispose();
            }
            else
            {
                DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
            }
            return(texture);
        }
Example #9
0
        private Texture2D CutTexture(string path, BoundBox rectangle)
        {
            ImageRect imageRect = new ImageRect ((int)rectangle.X, (int)rectangle.Y, (int)rectangle.Width, (int)rectangle.Height);
            if(System.IO.File.Exists(@"/Application/Content/Pic/" + path))
            {
                Image image = new Image (@"/Application/Content/Pic/" + path);
                image.Decode ();

            texture = new Texture2D ((int)rectangle.Width, (int)rectangle.Height, false, PixelFormat.Rgba);
            texture.SetPixels (0, image.Crop (imageRect).ToBuffer ());
            image.Dispose ();
            }
            else
                DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
            return texture;
        }
Example #10
0
 /// <summary>
 /// PSVX精灵类
 /// </summary>
 /// <param name='scene'>
 /// 精灵所在场景
 /// </param>
 /// <param name='path'>
 /// 精灵纹理
 /// </param>
 /// <param name='vector'>
 /// 精灵坐标
 /// </param>
 /// <param name='rectangle'>
 /// 切分的矩形.
 /// </param>
 public SpriteX(Node node, string path, Vector2 vector, BoundBox rectangle)
 {
     if(System.IO.File.Exists(@"/Application/Content/Pic/" + path))
         this.TextureInfo = new TextureInfo (CutTexture (@"/Application/Content/Pic/" + path, rectangle));
     else
         DebugScene.Instance.WriteLine("未找到文件:Pic/" + path);
     this.Quad.S = TextureInfo.TextureSizef;
     this.CenterSprite (TRS.Local.TopLeft);
     this.Position = new Vector2 (vector.X, 544.0f - vector.Y);
     this.fatherNode = node;
     node.AddChild (this);
 }
Example #11
0
        //碰撞检测
        //获取包围盒
        public virtual BoundBox GetBoundBox()
        {
            BoundBox bb =new BoundBox(Center.X,Center.Y,Width,Heigth);
            //drawBoundBox.SetBoundBoxInfor(bb);

            return bb;
        }
Example #12
0
        /// <summary>
        /// 绘制一个新的精灵,可设置坐标及显示部分
        /// </summary>
        /// <returns>
        /// 创建的精灵
        /// </returns>
        /// <param name='name'>
        /// 精灵名称
        /// </param>
        /// <param name='path'>
        /// 纹理地址
        /// </param>
        /// <param name='vector'>
        /// 精灵坐标
        /// </param>
        /// <param name='rectangle'>
        /// 表示显示起始坐标及结束坐标的矩形
        /// </param>
        public SpriteX DrawImage(Layer layer, string name, string path, Vector2 vector, BoundBox rectangle)
        {
            var sprite = new SpriteX(layer, path, vector, rectangle);

            sprite.Name = name;
            spriteDictionary.Add(name, sprite);
            return(sprite);
        }
Example #13
0
        /// <summary>
        /// 同Draw,但精灵不显示
        /// </summary>
        /// <returns>
        /// 创建的精灵
        /// </returns>
        /// <param name='name'>
        /// 精灵名称
        /// </param>
        /// <param name='path'>
        /// 纹理地址
        /// </param>
        /// <param name='vector'>
        /// 精灵坐标
        /// </param>
        /// <param name='rectangle'>
        /// 表示显示起始坐标及结束坐标的矩形
        /// </param>
        public SpriteX LoadImage(Layer layer, string name, string path, Vector2 vector, BoundBox rectangle)
        {
            SpriteX sprite = DrawImage(layer, name, path, vector, rectangle);

            sprite.Visible = false;
            return(sprite);
        }
Example #14
0
        public override BoundBox GetBoundBox()
        {
            if(NoContactTime >0)
                return null;

            BoundBox bb = null;
            base.Center = body.GetPosition ();
            //爆炸后检测范围扩大
            if (isBomb == true)
            {
                bb = new BoundBox(Center.X,Center.Y,Width*6f,Heigth*6f);
            }
            else
            {
                bb = base.GetBoundBox ();
            }
            bb.IsUseCircle = true;
            //base.drawBoundBox.SetBoundBoxInfor(bb);

            return bb;
        }
Example #15
0
 /// <summary>
 /// 同Draw,但精灵不显示
 /// </summary>
 /// <returns>
 /// 创建的精灵
 /// </returns>
 /// <param name='name'>
 /// 精灵名称
 /// </param>
 /// <param name='path'>
 /// 纹理地址
 /// </param>
 /// <param name='vector'>
 /// 精灵坐标
 /// </param>
 /// <param name='rectangle'>
 /// 表示显示起始坐标及结束坐标的矩形
 /// </param>
 public SpriteX LoadImage(Layer layer,string name,string path,Vector2 vector,BoundBox rectangle)
 {
     SpriteX sprite = DrawImage(layer,name,path,vector,rectangle);
     sprite.Visible = false;
     return sprite;
 }
Example #16
0
 /// <summary>
 /// 绘制一个新的精灵,可设置坐标及显示部分
 /// </summary>
 /// <returns>
 /// 创建的精灵
 /// </returns>
 /// <param name='name'>
 /// 精灵名称
 /// </param>
 /// <param name='path'>
 /// 纹理地址
 /// </param>
 /// <param name='vector'>
 /// 精灵坐标
 /// </param>
 /// <param name='rectangle'>
 /// 表示显示起始坐标及结束坐标的矩形
 /// </param>
 public SpriteX DrawImage(Layer layer,string name,string path,Vector2 vector,BoundBox rectangle)
 {
     var sprite = new SpriteX(layer,path,vector,rectangle);
     sprite.Name = name;
     spriteDictionary.Add(name,sprite);
     return sprite;
 }