Beispiel #1
0
        public bool Insert(Point point)
        {
            // Provided point is outside Tree external boundaries
            if (!Boundaries.Contains(point))
            {
                return(false);
            }

            return(Insert(QTRoot, point));
        }
Beispiel #2
0
        /// <summary>
        /// Adds a new content element. Subdivides the node, if required.
        /// </summary>
        /// <param name="content">The content to add.</param>
        /// <returns>True if the content could be added, false if not.</returns>
        public bool Add(TContent content)
        {
            //if (WorldChunk.gDebug) { //Debug.Log ("Trying to add " + content.Position.ToString ()); }
            // Check if the content can be put in this node, location-wise
            if (!Boundaries.Contains(content.Position))
            {
                //if (WorldChunk.gDebug) {  //Debug.Log ("Boundaries don't contain object"); }
                return(false);
            }

            // If there are no children yet...
            if (Children == null)
            {
                if (Content == null)
                {
                    Content = new List <TContent> ();
                }

                // ... and the content still fits in
                if (Content.Count < MaxContent)
                {
                    // Add the content.
                    Content.Add(content);
                    return(true);
                }
            }

            // The content does not fit in. Subdivide into 4 nodes, if not yet done
            if (Children == null)
            {
                //if (WorldChunk.gDebug) { //Debug.Log ("The content does not fit in. Subdivide into 4 nodes"); }
                Subdivide();
            }

            // Try to add the content to each of the four children. One must accept it.
            for (int i = 0; i < Children.Length; i++)
            {
                //if (WorldChunk.gDebug) { //Debug.Log ("Trying to add to child " + i.ToString ()); }
                if (Children [i].Add(content))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        public void MoveOrTurn(Direction direction, IEnumerable <Coordinate> impassable, Boundaries boundaries)
        {
            if ((DateTime.Now - LastMovement).TotalMilliseconds > MovementSpeed)
            {
                if (Facing == direction)
                {
                    var location = Location.Shifted(direction);

                    if (!impassable.Any(l => l.Equals(location)) && boundaries.Contains(location))
                    {
                        Location = location;
                    }
                }
                else
                {
                    Facing = direction;
                }
                LastMovement = DateTime.Now;
            }
        }
Beispiel #4
0
        private void ProjectilesTick()
        {
            var toRemove = new List <Projectile>();

            foreach (var projectile in projectiles)
            {
                projectile.Tick();

                var obstacle = obstacles.Find(o => o.Location.Equals(projectile.Location));

                if (obstacle != null)
                {
                    toRemove.Add(projectile);
                    obstacle.Hit();
                    if (obstacle.Destroyed)
                    {
                        obstacles.Remove(obstacle);
                    }
                }

                var tank = tanks.Find(t => t.Location.Equals(projectile.Location));

                if (tank != null && !ReferenceEquals(tank, projectile.Owner))
                {
                    toRemove.Add(projectile);
                    tank.Hit();
                    if (tank.Destroyed)
                    {
                        tanks.Remove(tank);
                    }
                }

                if (!boundaries.Contains(projectile.Location))
                {
                    toRemove.Add(projectile);
                }
            }

            projectiles.RemoveAll(i => toRemove.Contains(i));
        }