Exemple #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();
             }
         }
     }
 }
Exemple #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;
     }
 }
Exemple #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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 /// <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);
 }
Exemple #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);
            }
        }
Exemple #7
0
 public bool CheckBoundingBoxCollision(CollisionMask other)
 {
     return(rect.Intersects(other.GetBounds()) ||
            rect.Contains(other.GetBounds()));
 }
Exemple #8
0
 public void Hit(int nid, float x, float y)
 {
     onClick = bounds.Contains(x, y);
     id      = nid;
 }
Exemple #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);
 }
Exemple #10
0
 public bool Contains(float x, float y, float w, float h)
 {
     return(visibleRect.Contains(x, y, w, h));
 }