示例#1
0
 public CircleSquareHitbox(Character user, Alignment targetAlignments, bool hitTiles, TileAlignment burstTiles, Loc origin, FiniteEmitter tileEmitter,
                           CircleSquareEmitter emitter, int maxRadius, int speed, int delay, AreaLimit hitArea, Dir8 dir)
     : base(user, origin * GraphicsManager.TileSize, tileEmitter, delay)
 {
     TargetAlignments = targetAlignments;
     HitTiles         = hitTiles;
     BurstTiles       = burstTiles;
     Origin           = origin;
     MaxRadius        = maxRadius;
     Speed            = (speed > 0) ? speed : Math.Max(1, (int)Math.Ceiling(MaxRadius * 1.4142136 * GraphicsManager.MAX_FPS));
     HitArea          = hitArea;
     Dir     = dir;
     Emitter = (CircleSquareEmitter)emitter.Clone();
     Emitter.SetupEmit(MapLoc, user.CharDir, HitArea, MaxRadius * GraphicsManager.TileSize + GraphicsManager.TileSize / 2, Speed * GraphicsManager.TileSize);
 }
示例#2
0
        public static bool IsInCircleSquareHitbox(Loc loc, Loc origin, int radius, int squareRadius, AreaLimit limit, Dir8 dir)
        {
            //check if inside circle and square
            if ((origin - loc).DistSquared() > radius * radius)
            {
                return(false);
            }

            return(IsInSquareHitbox(loc, origin, squareRadius, limit, dir));
        }
示例#3
0
        public static bool IsInSquareHitbox(Loc loc, Loc origin, int squareRadius, AreaLimit limit, Dir8 dir)
        {
            if (loc.X < origin.X - squareRadius || loc.X > origin.X + squareRadius)
            {
                return(false);
            }
            if (loc.Y < origin.Y - squareRadius || loc.Y > origin.Y + squareRadius)
            {
                return(false);
            }

            if (limit == AreaLimit.Cone)
            {
                //check if it's inside the cone

                //get line diff
                Loc diff = loc - origin;

                //get cone vectors
                Dir8 cone1 = DirExt.AddAngles(dir, Dir8.DownRight);
                Dir8 cone2 = DirExt.AddAngles(dir, Dir8.DownLeft);

                //get vector orthogonal1 to first cone line (aka, -second cone line)
                Loc ortho1 = cone2.GetLoc() * -1;

                //get vector orthogonal2 to second cone line ( aka, first cone line)
                Loc ortho2 = cone1.GetLoc();

                //get dot product of diff to orthogonal1; must be less than or equal to 0
                int dot1 = Loc.Dot(diff, ortho1);

                //get dot product of diff to orthogonal2; must be greater than or equal to 0
                int dot2 = Loc.Dot(diff, ortho2);

                if (dot1 > 0 || dot2 < 0)
                {
                    return(false);
                }
            }
            else if (limit == AreaLimit.Sides)
            {
                Loc diff = loc - origin;
                if (dir.IsDiagonal())
                {
                    //get cone vectors
                    Dir8 cone1 = DirExt.AddAngles(dir.Reverse(), Dir8.DownRight);
                    Dir8 cone2 = DirExt.AddAngles(dir.Reverse(), Dir8.DownLeft);

                    //get vector orthogonal1 to first cone line (aka, -second cone line)
                    Loc ortho1 = cone2.GetLoc() * -1;

                    //get vector orthogonal2 to second cone line ( aka, first cone line)
                    Loc ortho2 = cone1.GetLoc();

                    //get dot product of diff to orthogonal1; must be less than or equal to 0
                    int dot1 = Loc.Dot(diff, ortho1);

                    //get dot product of diff to orthogonal2; must be greater than or equal to 0
                    int dot2 = Loc.Dot(diff, ortho2);

                    if (dot1 > 0 || dot2 < 0)
                    {
                        return(false);
                    }

                    //additionally, both dot products cannot be a nonzero
                    if (dot1 != 0 && dot2 != 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    //check if it's inside the sides
                    int dot = Loc.Dot(diff, dir.GetLoc());

                    //check if the other point is EXACTLY perpendicular
                    if (dot != 0)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }