Esempio n. 1
0
 /// <summary>
 /// when space detects collision with another debris, after debris movement, it will call this
 /// </summary>
 /// <param name="otherDebris"></param>
 public void Collide(Debris otherDebris)
 {
     if (otherDebris != null && CollisionConsumer != null)
     {
         CollisionConsumer.Invoke(otherDebris);
     }
 }
Esempio n. 2
0
        public Debris DeployDebris(long positionX, long positionY, long positionZ, int extent)
        {
            Debris debris = new Debris(positionX, positionY, positionZ, extent);

            allDebrisInSpace.Add(debris);

            return(debris);
        }
Esempio n. 3
0
 /// <summary>
 /// Will determine the maximum distance in one coordiate.
 /// This is interesting, as it is relevant for how close another debris is.
 /// if it is far away in only one coordinate, it is far away.
 /// Imagine there is one lightyear between you and stgh else in z coordinate and others are just same
 /// </summary>
 /// <param name="anotherDebris"></param>
 /// <returns></returns>
 private long MaxDistanceCoordinate(Debris anotherDebris)
 {
     long[] distances = new long[]
     {
         Math.Abs(anotherDebris.PositionX - PositionX),
         Math.Abs(anotherDebris.PositionY - PositionY),
         Math.Abs(anotherDebris.PositionZ - PositionZ)
     };
     return(distances.Max());
 }
Esempio n. 4
0
        public Space DeployDebris(Debris debris)
        {
            if (allDebrisInSpace.Contains(debris))
            {
                throw new ArgumentException();
            }

            allDebrisInSpace.Add(debris);

            return(this);
        }
Esempio n. 5
0
        public bool IsCloseTo(Debris anotherDebris)
        {
            if (anotherDebris == null || this == anotherDebris)
            {
                // this is not a collision, it is the same debris!
                return(false);
            }

            long distance = MaxDistanceCoordinate(anotherDebris);

            return((distance - Extent) <= Close);
        }
Esempio n. 6
0
        public bool IsCollision(Debris anotherDebris)
        {
            if (anotherDebris == null || this == anotherDebris)
            {
                // this is not a collision, it is the same debris!
                return(false);
            }

            long distance = MaxDistanceCoordinate(anotherDebris);

            int myRadius    = (int)Math.Ceiling((double)Extent / 2d);
            int otherRadius = (int)Math.Ceiling((double)anotherDebris.Extent / 2d);
            int bothRadius  = myRadius + otherRadius;

            return((distance - bothRadius) <= 0);
        }
Esempio n. 7
0
        /// <summary>
        /// Debris should only be moved by this method, so that we can call their collision methods
        /// </summary>
        /// <param name="debris"></param>
        /// <param name="deltaX"></param>
        /// <param name="deltaY"></param>
        /// <param name="deltaZ"></param>
        public void MoveDebris(Debris debris, int deltaX, int deltaY, int deltaZ)
        {
            Contract.Requires(debris != null);

            if (Math.Abs(deltaX) > 1 || Math.Abs(deltaY) > 1 || Math.Abs(deltaZ) > 1)
            {
                throw new ArgumentException("can move debris only slowly, 1 unit per time");
            }

            debris.Move(deltaX, deltaY, deltaZ);

            IEnumerable <Debris> collidingDebris = allDebrisInSpace.Where(d => d.IsCollision(debris));

            foreach (Debris d in collidingDebris)
            {
                d.Collide(debris);
                debris.Collide(d);
            }

            foreach (IDebrisMovementObserver observer in allDebrisMovementObserver)
            {
                observer.DebrisHasMoved(debris);
            }
        }
Esempio n. 8
0
        public bool WillDebrisMaybeCollideSoonWithAnyOtherDebris(Debris input)
        {
            Contract.Requires(input != null);

            return(allDebrisInSpace.Where(d => input.IsCloseTo(d)).Any());
        }