예제 #1
0
        private void checkCollision(ICollidable i_Source)
        {
            if (i_Source.Visible)
            {
                List<ICollidable> collidedComponents = new List<ICollidable>();

                // finding who collided with i_Source:

                foreach (ICollidable target in m_Collidables)
                {
                    if (i_Source != target && target.Visible)
                    {
                        if (target.CheckCollision(i_Source))
                        {
                            collidedComponents.Add(target);
                        }
                    }
                }

                // Informing i_Source and all the collided targets about the collision:
                foreach (ICollidable target in collidedComponents)
                {
                    target.Collided(i_Source);
                    i_Source.Collided(target);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Determines what should happen when a collision occurs.
        /// </summary>
        /// <param name="other"></param>
        public void CollideWith(ICollidable other)
        {
            Invader invader = other as Invader;
            if (invader != null)
            {

            }
        }
예제 #3
0
 public override void Collided(ICollidable i_Collidable)
 {
     if (!IsDying)
     {
         if (i_Collidable is Bullet)
         {
             handleDeath();
         }
     }
 }
예제 #4
0
 public override void Collided(ICollidable i_Collidable)
 {
     if (i_Collidable is Bullet)
     {
         if ((i_Collidable as Bullet).Shooter is PlayerShip)
         {
             handleDeath();
         }
      }
 }
예제 #5
0
 public void AddObjectToMonitor(ICollidable i_Collidable)
 {
     if (!this.m_Collidables.Contains(i_Collidable))
     {
         this.m_Collidables.Add(i_Collidable);
         i_Collidable.PositionChanged += collidable_Changed;
         i_Collidable.SizeChanged += collidable_Changed;
         i_Collidable.VisibleChanged += collidable_Changed;
         i_Collidable.Disposed += collidable_Disposed;
     }
 }
예제 #6
0
        public override void Collided(ICollidable i_Collidable)
        {
            bool thisBulletShouldBeDisposed = true;
            bool thisBulletHasHitAnotherCollidable = true;
            bool thisIsAPlayerBullet = this.Shooter is PlayerShip;

            if (i_Collidable is Bullet)
            {
                bool otherColliadbleIsAPlayerBullet = (i_Collidable as Bullet).Shooter is PlayerShip;

                if (thisIsAPlayerBullet != otherColliadbleIsAPlayerBullet)
                {
                    if (!thisIsAPlayerBullet)
                    {
                        int randomDecision = new Random().Next(0, 2);
                        if (randomDecision == 0)
                        {
                            thisBulletShouldBeDisposed = false;
                        }
                    }
                }
                else
                {
                    thisBulletShouldBeDisposed = false;
                }
            }

            if ((!thisIsAPlayerBullet && i_Collidable is Alien) || (thisIsAPlayerBullet && i_Collidable is PlayerShip))
            {
                thisBulletShouldBeDisposed = false;
                thisBulletHasHitAnotherCollidable = false;
            }

            if (thisBulletHasHitAnotherCollidable && Hit != null)
            {
                Hit(this, i_Collidable as GameComponent);
            }

            if (thisBulletShouldBeDisposed)
            {
                OnDispose();
            }
        }
예제 #7
0
        public override void Collided(ICollidable i_OtherCollidable)
        {
            if (CollidingPoints.Count != 0)
            {
                if (i_OtherCollidable is Bullet)
                {
                    handleBulletCollision(i_OtherCollidable as Bullet);
                }

                if (i_OtherCollidable is Alien)
                {
                    foreach (Point point in CollidingPoints)
                    {
                        SpritePixelMatrix.ChangePixelAlpha(point.X, point.Y, 0);
                    }
                }

                CollidingPoints.Clear();
            }
        }
예제 #8
0
        public virtual bool CheckCollision(ICollidable i_OtherCollidable)
        {
            bool collided = false;
            ICollidable2D otherCollidable = i_OtherCollidable as ICollidable2D;

            if (otherCollidable != null)
            {
                if (i_OtherCollidable.IsCurrentlyCollidable() && this.IsCurrentlyCollidable())
                {
                if (otherCollidable.Bounds.Intersects(this.Bounds) || otherCollidable.Bounds.Contains(this.Bounds))
                {
                    if (this.IsPixelCollidable)
                    {
                        m_CollidingPoints = getCollidingPixels(otherCollidable);
                        if (m_CollidingPoints.Count != 0)
                        {
                            collided = true;
                        }
                    }
                    else if (otherCollidable.IsPixelCollidable)
                    {
                        collided = otherCollidable.CheckCollision(this);
                    }
                    else
                    {
                        collided = true;
                    }
                }
            }
            }
            else
            {
                throw new ArgumentException("Collidable sprite only works with ICollidable2D");
            }

            return collided;
        }
예제 #9
0
 public void CollideWith(ICollidable other)
 {
 }
예제 #10
0
 public abstract void Collided(ICollidable i_Collidable);