Beispiel #1
0
        public static Pos GetDirPos(Pos start, Pos finish)
        {
            int x = 0;
            int y = 0;

            if (finish.x > start.x)
                x = 1;
            else if (finish.x < start.x)
                x = -1;

            if (finish.y > start.y)
                y = 1;
            else if (finish.y < start.y)
                y = -1;

            return new Pos(x, y);
        }
Beispiel #2
0
        public static bool IsAdjacentTo(Pos one, Pos two, bool countDiag)
        {
            int diffX = one.x - two.x;
            int diffY = one.y - two.y;

            // Out of range
            if (Math.Abs(diffX) > 1)
                return false;
            // Out of range
            if (Math.Abs(diffY) > 1)
                return false;
            // Diagonal
            if (Math.Abs(diffX) == 1 && Math.Abs(diffY) == 1 && countDiag == false)
                return false;

            return true;
        }
Beispiel #3
0
 public bool CanSeeTile(Pos tp, bool useCollisionInsteadOfSight, int radiusToUse)
 {
     return CanSeeTile(tp.x, tp.y, useCollisionInsteadOfSight, radiusToUse);
 }
Beispiel #4
0
 public PathNode()
 {
     pos = Pos.Zero;
     parent = null;
     g = 0;
     h = 0;
 }
Beispiel #5
0
 public static Pos ApplyDirPos(Pos coordPos, Pos dirPos)
 {
     return new Pos(coordPos.x + dirPos.x, coordPos.y + dirPos.y);
 }
Beispiel #6
0
 public bool IsAdjacentTo(Pos other, bool countDiag)
 {
     return Pos.IsAdjacentTo(this, other, countDiag);
 }
Beispiel #7
0
 public PathNode(Pos p, PathNode par, int curG, int calcH)
 {
     pos = p;
     parent = par;
     g = curG;
     h = calcH;
 }
Beispiel #8
0
 public int Distance(Pos other)
 {
     return (int)Math.Sqrt(Math.Pow((other.x - x), 2) + Math.Pow((other.y - y), 2));
 }
Beispiel #9
0
 /// <summary>
 /// This version passes by reference to avoid copying the Pos every call--should help with GC and memory
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CompareRef(ref Pos other)
 {
     if (x == other.x && y == other.y)
         return true;
     else
         return false;
 }
Beispiel #10
0
        public bool CanSeeTile(int tx, int ty, bool useCollisionInsteadOfSight, int radiusToUse)
        {
            bool canSee = false;
            int radius = radiusToUse;
            Pos pos = this;

            if (this.x == tx && this.y == ty)
                return true;

            if (tx < pos.x + radius && tx > pos.x - radius)
            {
                if (ty < pos.y + radius && ty > pos.y - radius)
                {
                    int distance = pos.Distance(new Pos(tx, ty));
                    if (distance <= radius)
                    {
                        int xdir = 0;
                        int ydir = 0;
                        if (tx < pos.x)
                            xdir = -1;
                        if (tx > pos.x)
                            xdir = 1;
                        if (ty < pos.y)
                            ydir = -1;
                        if (ty > pos.y)
                            ydir = 1;
                        int xtravel = Math.Abs(pos.x - tx);
                        int ytravel = Math.Abs(pos.y - ty);
                        Pos cursor = new Pos(pos.x, pos.y);

                        for (int i = 0; i < distance; i++)
                        {
                            cursor.x += xdir;
                            cursor.y += ydir;

                            ytravel--;
                            xtravel--;
                            if (ytravel <= 0)
                                ydir = 0;
                            if (xtravel <= 0)
                                xdir = 0;

                            bool blocked = false;

                            // TODO: implement this
                            //if (useCollisionInsteadOfSight)
                            //    blocked = Game.level.CheckCollision(cursor, true);
                            //else
                            //    blocked = Game.level.CheckBlocksSight(cursor);

                            if (blocked)
                            {
                                if (i == distance - 1)
                                    canSee = true;
                                else
                                    canSee = false;

                                break;
                            }
                            else
                                canSee = true;
                        }
                    }
                }
                else
                {
                    canSee = false;
                }
            }
            else
            {
                canSee = false;
            }

            return canSee;
        }
Beispiel #11
0
 public WorldCollisionType CheckCollision(Entity mover, int x, int y, bool aiCalc, Pos dest)
 {
     return WorldCollisionType.None;
 }
Beispiel #12
0
 public WorldCollisionType CheckCollision(Entity mover, Pos p)
 {
     return CheckCollision(mover, p.x, p.y, false, p);
 }