예제 #1
0
 public void Hit(int nid, float x, float y, bool flag)
 {
     if (flag)
     {
         if (nid == id)
         {
             onClick = bounds.Contains(x, y);
             if (_monitor != null)
             {
                 if (onClick)
                 {
                     _monitor.Call();
                 }
             }
         }
     }
     else
     {
         if (!onClick)
         {
             onClick = bounds.Contains(x, y);
             id      = nid;
             if (onClick && _monitor != null)
             {
                 _monitor.Call();
             }
         }
     }
 }
예제 #2
0
 public void Hit(int nid, int x, int y)
 {
     onClick = bounds.Contains(x, y) ||
               bounds.Intersects(x, y, bounds.width / 2, bounds.height / 4);
     if (nid == id)
     {
         click = false;
     }
     if (!disabled && !click)
     {
         SetPointerId(nid);
         click = onClick;
     }
 }
예제 #3
0
        protected virtual internal bool IsNotMoveInScreen(int x, int y)
        {
            if (!this._limitMove)
            {
                return(false);
            }
            int width  = (GetWidth() - _screenRect.width);
            int height = (GetHeight() - _screenRect.height);
            int limitX = x + width;
            int limitY = y + height;

            if (GetWidth() >= _screenRect.width)
            {
                if (limitX >= width - 1)
                {
                    return(true);
                }
                else if (limitX <= 1)
                {
                    return(true);
                }
            }
            else
            {
                if (!_screenRect.Contains(x, y, GetWidth(), GetHeight()))
                {
                    return(true);
                }
            }
            if (GetHeight() >= _screenRect.height)
            {
                if (limitY >= height - 1)
                {
                    return(true);
                }
                else if (limitY <= 1)
                {
                    return(true);
                }
            }
            else
            {
                if (!_screenRect.Contains(x, y, GetWidth(), GetHeight()))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
파일: LComponent.cs 프로젝트: vb0067/LGame
        protected internal bool IsNotMoveInScreen(int x, int y)
        {
            if (!this.isLimitMove)
            {
                return(false);
            }
            int width_0  = GetWidth() - screenRect.width;
            int height_1 = GetHeight() - screenRect.height;
            int limitX   = x + width_0;
            int limitY   = y + height_1;

            if (GetWidth() >= screenRect.width)
            {
                if (limitX >= width_0 - 1)
                {
                    return(true);
                }
                else if (limitX <= 1)
                {
                    return(true);
                }
            }
            else
            {
                if (!screenRect.Contains(x, y, GetWidth(), GetHeight()))
                {
                    return(true);
                }
            }
            if (GetHeight() >= screenRect.height)
            {
                if (limitY >= height_1 - 1)
                {
                    return(true);
                }
                else if (limitY <= 1)
                {
                    return(true);
                }
            }
            else
            {
                if (!screenRect.Contains(x, y, GetWidth(), GetHeight()))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #5
0
파일: Sprites.cs 프로젝트: vb0067/LGame
 /// <summary>
 /// 查找指定位置的精灵对象
 /// </summary>
 ///
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public ISprite Find(int x, int y)
 {
     ISprite[] snapshot = sprites;
     for (int i = snapshot.Length - 1; i >= 0; i--)
     {
         ISprite child = snapshot[i];
         RectBox rect  = child.GetCollisionBox();
         if (rect != null && rect.Contains(x, y))
         {
             return(child);
         }
     }
     return(null);
 }
예제 #6
0
        public void AddObject(Actor actor)
        {
            RectBox bounds = this.GetActorBounds(actor);
            float   by;

            if (this.bspTree == null)
            {
                byte treeArea;
                if (bounds.width > bounds.height)
                {
                    treeArea = 0;
                    by       = bounds.GetMiddleX();
                }
                else
                {
                    treeArea = 1;
                    by       = bounds.GetMiddleY();
                }

                this.bspTree = GetBSPNode();
                this.bspTree.GetArea().Copy(bounds);
                this.bspTree.SetSplitAxis(treeArea);
                this.bspTree.SetSplitPos(by);
                this.bspTree.AddActor(actor);
            }
            else
            {
                int     idx       = 0;
                RectBox treeArea1 = this.bspTree.GetArea();
                RectBox result1   = new RectBox();
                RectBox result2   = new RectBox();
                for (; !treeArea1.Contains(bounds) && idx < MAX_SIZE;)
                {
                    RectBox          newArea;
                    BSPCollisionNode newTop;
                    if (bounds.GetX() < treeArea1.GetX())
                    {
                        by      = (treeArea1.GetX() - treeArea1.width);
                        newArea = new RectBox(by, treeArea1.GetY(),
                                              treeArea1.GetRight() - by, treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetX());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetRight() > treeArea1.GetRight())
                    {
                        by      = (treeArea1.GetRight() + treeArea1.width);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                              by - treeArea1.GetX(), treeArea1.height);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(0);
                        newTop.SetSplitPos(treeArea1.GetRight());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetY() < treeArea1.GetY())
                    {
                        by      = (treeArea1.GetY() - treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), by,
                                              treeArea1.width, treeArea1.GetBottom() - by);
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetY());
                        newTop.SetChild(1, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    if (bounds.GetBottom() > treeArea1.GetBottom())
                    {
                        by      = (treeArea1.GetBottom() + treeArea1.height);
                        newArea = new RectBox(treeArea1.GetX(), treeArea1.GetY(),
                                              treeArea1.width, by - treeArea1.GetY());
                        newTop = GetBSPNode();
                        newTop.GetArea().Copy(newArea);
                        newTop.SetSplitAxis(1);
                        newTop.SetSplitPos(treeArea1.GetBottom());
                        newTop.SetChild(0, this.bspTree);
                        this.bspTree = newTop;
                        treeArea1    = newArea;
                    }
                    idx++;
                }

                this.InsertObject(actor, bounds, bounds, treeArea1, this.bspTree,
                                  result1, result2);
            }
        }
예제 #7
0
 public bool CheckBoundingBoxCollision(CollisionMask other)
 {
     return(rect.Intersects(other.GetBounds()) ||
            rect.Contains(other.GetBounds()));
 }
예제 #8
0
 public void Hit(int nid, float x, float y)
 {
     onClick = bounds.Contains(x, y);
     id      = nid;
 }
예제 #9
0
 public void UpdateCamera()
 {
     if (follow != null &&
         !moveRect.Contains(follow.GetX() + follow.GetWidth() / 2,
                            follow.GetY() + follow.GetHeight() / 2))
     {
         float targetCX = follow.GetX() - (this.renderWidth / 2);
         float targetCY = follow.GetY() - (this.renderHeight / 2);
         if (maxSpeed != null)
         {
             if (MathUtils.Abs(targetCX - cameraX) > maxSpeed.x)
             {
                 if (targetCX > cameraX)
                 {
                     cameraX += maxSpeed.x * 2;
                 }
                 else
                 {
                     cameraX -= maxSpeed.x * 2;
                 }
             }
             else
             {
                 cameraX = targetCX;
             }
             if (MathUtils.Abs(targetCY - cameraY) > maxSpeed.y)
             {
                 if (targetCY > cameraY)
                 {
                     cameraY += maxSpeed.y * 2;
                 }
                 else
                 {
                     cameraY -= maxSpeed.y * 2;
                 }
             }
             else
             {
                 cameraY = targetCY;
             }
         }
         else
         {
             cameraX = targetCX;
             cameraY = targetCY;
         }
     }
     if (cameraX < 0)
     {
         cameraX = 0;
     }
     if (cameraX + renderWidth > cameraRect.GetWidth())
     {
         cameraX = cameraRect.GetWidth() - renderWidth + 1;
     }
     if (cameraY < 0)
     {
         cameraY = 0;
     }
     if (cameraY + renderHeight > cameraRect.GetHeight())
     {
         cameraY = cameraRect.GetHeight() - renderHeight + 1;
     }
     visibleRect.SetBounds(cameraX - horBorderPixel, cameraY
                           - vertBorderPixel, renderWidth + horBorderPixel, renderHeight
                           + vertBorderPixel);
     moveRect.SetBounds(cameraX + horBorderPixel / 2 - speedX, cameraY
                        + vertBorderPixel / 2, renderWidth - horBorderPixel + speedY,
                        renderHeight - vertBorderPixel);
 }
예제 #10
0
 public bool Contains(float x, float y, float w, float h)
 {
     return(visibleRect.Contains(x, y, w, h));
 }