コード例 #1
0
        private void HandleHitCollisions()
        {
            foreach (Entity damager in
                     Utilities.Chain(
                         this.Scene.EntityManager.FindAllByTag(Constants.Tags.Bullet),
                         this.Scene.EntityManager.FindAllByTag(Constants.Tags.Sword)))
            {
                RectangleCollider damagerCollider = damager.FindComponent <RectangleCollider>();
                foreach (Entity other in
                         Utilities.Chain(
                             this.Scene.EntityManager.FindAllByTag(Constants.Tags.Wall),
                             this.Scene.EntityManager.FindAllByTag(Constants.Tags.Member)))
                {
                    RectangleCollider otherCollider = other.FindComponent <RectangleCollider>();

                    if (damagerCollider.Intersects(otherCollider))
                    {
                        bool isGhost = false;
                        if (other.Tag == Constants.Tags.Member)
                        {
                            CharacterBehavior behavior = other.FindComponent <CharacterBehavior>(isExactType: false);
                            if (!behavior.DealDamageToMemberOrFail(this.GetDamageSender(behavior), damager.Tag))
                            {
                                isGhost = true;
                            }
                        }

                        if (!isGhost && damager.Tag == Constants.Tags.Bullet)
                        {
                            damager.FindComponent <BulletBehavior>().MarkAsDead();
                        }
                    }
                }
            }
        }