Пример #1
0
        public void Handle(IEntity entity, IEntity target, Side side)
        {
            IProjectile fireball = (IProjectile)entity;

            // Fireball is colliding into a block
            if (target is IBlock)
            {
                IBlock block = (IBlock)target;
                // Fireball bounces on the top side of all kinds of blocks except hidden block
                if (side == Side.TOP && block.Type != "HiddenBlock")
                {
                    fireball.Bounce();
                }
                // Fire booms when colliding into a block if it is not a hidden block
                else if (block.Type != "HiddenBlock")
                {
                    SoundEffects.Instance.PlayBumpSound();
                    fireball.Boom();
                }
            }
            // Fireball is colliding into an enemy
            else if (target is IEnemy)
            {
                IEnemy enemy = (IEnemy)target;
                fireball.Attack(enemy);
                SoundEffects.Instance.PlayKickSound();
                fireball.Boom();
            }
        }
        public void HandleCollision()
        {
            collision.ResolveOverlap(fireball, side);

            if (side is TopSideCollision && !(block.State is HiddenBlockState))
            {
                fireball.Bounce();
            }
            else if (!(block.State is HiddenBlockState))
            {
                fireball.Explode();
            }
        }
        public static void ProjectileBlockCollision(IProjectile proj, Block block) {

            Vector2 direction = GetCollisionDirection(proj.Bounds, block.Bounds);
            int penetration = GetPenetration(proj.Bounds, block.Bounds, direction);
            proj.Position += direction * penetration;

            proj.Bounce(direction);
        }