예제 #1
0
        private void CollisionDetected(object sender, CollisionEventArgs e)
        {
            //DestroyEntity();

            if (e.CollisionResolved)
            {
                return;
            }

            GameEntity otherEntity = e.OtherEntity(this);

            if (otherEntity is Asteroid.Asteroid)
            {
                // handle collision with asteroid
                otherEntity.Velocity += _shotToAsteroidImpact;
                this.DestroyEntity();
                e.CollisionResolved = true;
            }
            if (otherEntity is Enemy && _firedBy != FiredBy.Enemy)
            {
                otherEntity.DestroyEntity();
                this.DestroyEntity();
                e.CollisionResolved = true;
            }
            if (otherEntity is Player && _firedBy != FiredBy.Player)
            {
                ((Player)otherEntity).Hit(_damage);
                this.DestroyEntity();
                e.CollisionResolved = true;
            }
        }
예제 #2
0
        private void ShotCollision(object sender, CollisionEventArgs e)
        {
            if (e.OtherEntity(this) is Player)
            {
                return;
            }
            if (e.OtherEntity(this) is Shot)
            {
                return;
            }

            ShotCollisionEventArgs args = new ShotCollisionEventArgs
            {
                Shot        = this,
                OtherEntity = e.OtherEntity(this)
            };

            OnShotCollision?.Invoke(this, args);
            this.DestroyEntity();
        }
예제 #3
0
        private void CollisionDetected(object sender, CollisionEventArgs e)
        {
            if (e.CollisionResolved)
            {
                return;
            }

            GameEntity otherEntity = e.OtherEntity(this);

            if (otherEntity is Asteroid.Asteroid)
            {
                otherEntity.DestroyEntity();
                this.DestroyEntity();
                e.CollisionResolved = true;
            }
            if (otherEntity is Enemy)
            {
                otherEntity.DestroyEntity();
                this.DestroyEntity();
                e.CollisionResolved = true;
            }
        }