Exemple #1
0
        private bool HasShootingLine(Vector2i startingPosition)
        {
            var weather = GameMap.CurrentWeather;
            var range   = Barrel.Range;

            if (weather == "raining")
            {
                range /= 2;
            }

            if (startingPosition.DistanceTo(Enemy.Position) > Barrel.Range)
            {
                return(false);
            }

            var shootingLine   = new Line(startingPosition, Enemy.Position);
            var collidingTiles = shootingLine.GetIntersectingPoints();

            foreach (var coords in collidingTiles)
            {
                var tile = GameMap.GetTile(coords);
                if (tile != null && tile.Solid)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #2
0
        public List <Node> FindPath(Vector2i start, Vector2i goal)
        {
            var openList   = new List <Node>();
            var closedList = new List <Node>();

            var current = new Node(start, null, 0, start.DistanceTo(goal));

            openList.Add(current);
            while (openList.Count > 0)
            {
                current = openList
                          .OrderBy(n => n.FCost)
                          .First();
                if (current.Position.Equals(goal))
                {
                    var path = new List <Node>();
                    while (current.Parent != null)
                    {
                        path.Add(current);
                        current = current.Parent;
                    }
                    return(path);
                }

                openList.Remove(current);
                closedList.Add(current);
                for (int i = 0; i < 9; i++)
                {
                    var deltapos = new Vector2i {
                        X = (i % 3) - 1, Y = (i / 3) - 1
                    };
                    var newPos = current.Position + deltapos;
                    var at     = GetTile(newPos);
                    if (at == null || at.Solid)
                    {
                        continue;
                    }

                    if (closedList.Any(n => n.Position == newPos))
                    {
                        continue;
                    }

                    var gCost = current.GCost + current.Position.DistanceTo(newPos);
                    var hCost = newPos.DistanceTo(goal);

                    var node = new Node(newPos, current, gCost, hCost);

                    var existingNode = openList.SingleOrDefault(n => n.Position == newPos);

                    if (existingNode == null)
                    {
                        openList.Add(node);
                    }
                    else if (existingNode != null && node.GCost < existingNode.GCost)
                    {
                        existingNode.Parent = current;
                        existingNode.GCost  = gCost;
                    }
                }
            }
            return(null);
        }
Exemple #3
0
 public bool IsPointInside(Vector2i point)
 {
     return(point.DistanceTo(form.Position + offsetPosition) < BALL_RADIUS);
 }