示例#1
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;
     }
 }
示例#2
0
文件: Actor.cs 项目: zx8326123/LGame
        public virtual bool Intersects(Actor other)
        {
            int thisBounds1;

            if (this.image == null)
            {
                if (other.image != null)
                {
                    thisBounds1 = this.gameLayer.GetCellSize();
                    return(other.ContainsPoint(location.X() * thisBounds1
                                               + thisBounds1 / 2, location.Y() * thisBounds1
                                               + thisBounds1 / 2));
                }
                else
                {
                    return(location.x == other.location.x &&
                           location.y == other.location.y);
                }
            }
            else if (other.image == null)
            {
                thisBounds1 = this.gameLayer.GetCellSize();
                return(this.ContainsPoint(other.location.X() * thisBounds1
                                          + thisBounds1 / 2, other.location.Y() * thisBounds1
                                          + thisBounds1 / 2));
            }
            else
            {
                RectBox thisBounds  = this.GetBoundingRect();
                RectBox otherBounds = other.GetBoundingRect();
                if (this.rotation == 0 && other.rotation == 0)
                {
                    return(thisBounds.Intersects(otherBounds));
                }
                else if (!thisBounds.Intersects(otherBounds))
                {
                    return(false);
                }
                else
                {
                    float[] myX    = this.xs;
                    float[] myY    = this.ys;
                    float[] otherX = other.xs;
                    float[] otherY = other.ys;
                    return((CheckOutside(myX, myY, otherX, otherY)) ? false
                        : !CheckOutside(otherX, otherY, myX, myY));
                }
            }
        }
示例#3
0
        public override void Update(long elapsedTime)
        {
            if (!complete)
            {
                if (timer.Action(elapsedTime))
                {
                    switch (direction)
                    {
                    case Config.LEFT:
                    case Config.RIGHT:
                    case Config.TLEFT:
                    case Config.TRIGHT:
                        v1.Move_multiples(Config.TLEFT, multiples);
                        v2.Move_multiples(Config.TRIGHT, multiples);
                        break;

                    case Config.UP:
                    case Config.DOWN:
                    case Config.TUP:
                    case Config.TDOWN:
                        v1.Move_multiples(Config.TUP, multiples);
                        v2.Move_multiples(Config.TDOWN, multiples);
                        break;
                    }

                    if (special)
                    {
                        if (!limit.Intersects(v1.x, v1.y, halfHeight, halfWidth) &&
                            !limit.Intersects(v2.x, v2.y, halfHeight,
                                              halfWidth))
                        {
                            this.complete = true;
                        }
                    }
                    else if (!limit.Intersects(v1.x, v1.y, halfWidth, halfHeight) &&
                             !limit.Intersects(v2.x, v2.y, halfWidth, halfHeight))
                    {
                        this.complete = true;
                    }
                }
            }
        }
示例#4
0
        public bool IsCollision(SpriteBatchObject o)
        {
            RectBox src = GetCollisionArea();
            RectBox dst = o.GetCollisionArea();

            if (src.Intersects(dst))
            {
                return(true);
            }
            return(false);
        }
示例#5
0
        public override void Update(long elapsedTime)
        {
            if (!complete)
            {
                switch (type)
                {
                case Config.DOWN:
                    Move_45D_down(multiples);
                    break;

                case Config.UP:
                    Move_45D_up(multiples);
                    break;

                case Config.LEFT:
                    Move_45D_left(multiples);
                    break;

                case Config.RIGHT:
                    Move_45D_right(multiples);
                    break;

                case Config.TDOWN:
                    Move_down(multiples);
                    break;

                case Config.TUP:
                    Move_up(multiples);
                    break;

                case Config.TLEFT:
                    Move_left(multiples);
                    break;

                case Config.TRIGHT:
                    Move_right(multiples);
                    break;
                }
                if (!limit.Intersects(X(), Y(), width, height))
                {
                    complete = true;
                }
            }
        }
示例#6
0
 /// <summary>
 /// 检查两个矩形是否发生了碰撞
 /// </summary>
 ///
 /// <param name="rect1"></param>
 /// <param name="rect2"></param>
 /// <returns></returns>
 public static bool IsRectToRect(RectBox rect1, RectBox rect2)
 {
     return(rect1.Intersects(rect2));
 }
示例#7
0
 public bool CheckBoundingBoxCollision(CollisionMask other)
 {
     return(rect.Intersects(other.GetBounds()) ||
            rect.Contains(other.GetBounds()));
 }
示例#8
0
 public bool Intersects(float x, float y, float w, float h)
 {
     return(visibleRect.Intersects(x, y, w, h));
 }