Exemple #1
0
        public override void HandleCollision(Sprite sprite, Vector2 intersect)
        {
            if (!IsEmpty && hadContainedSprite)
            {
                base.HandleCollision(sprite, intersect);
            }
            else if (IsEmpty && hadContainedSprite)
            {
                return;
            }
            else
            {
                // This brick block is just a normal brick block and thus can be broken.
                // TODO: this should only break the block iff the player is Super or higher

                if (sprite.IsPlayer)
                {
                    Vector2 playerCenter = sprite.Hitbox.Center;
                    float playerYVelocity = sprite.Velocity.Y;
                    float thisBottom = Hitbox.Bounds.Bottom;
                    float thisTop = Hitbox.Bounds.Top;
                    bool isGroundPounding = sprite.HasAttribute("GroundPounding");

                    if (playerCenter.Y > thisBottom)
                    {
                        BreakBlock();
                    }
                    else if (playerCenter.Y < thisTop && isGroundPounding)
                    {
                        BreakBlock();
                    }
                }
                else if (sprite.HasAttribute("ShellSpinning"))
                {
                    Vector2 spriteCenter = sprite.Hitbox.Center;
                    float spriteXVelocity = sprite.Velocity.X;
                    float thisLeft = Hitbox.Bounds.Left;
                    float thisRight = Hitbox.Bounds.Right;

                    if (spriteCenter.X < thisLeft || spriteCenter.X > thisRight)
                    {
                        BreakBlock();
                    }
                }
            }
        }
Exemple #2
0
        public override void HandleCollision(Sprite sprite, Vector2 intersect)
        {
            // The question block is triggered if it's not empty,
            // if the sprite is a player that hits the block from below
            //  (player.Center beneath Bottom, player's Velocity upward)
            // or player is ground pounding from above
            //  (player.Center above Top)
            // or if the sprite has attribute ShellSpinning and hits on the side

            if (IsEmpty) { return; }
            if (sprite.IsPlayer)
            {
                Vector2 playerCenter = sprite.Hitbox.Center;
                float playerYVelocity = sprite.Velocity.Y;
                float thisBottom = Hitbox.Bounds.Bottom;
                float thisTop = Hitbox.Bounds.Top;
                bool isGroundPounding = sprite.HasAttribute("GroundPounding");

                if (playerCenter.Y > thisBottom)
                {
                    OnBlockHit(VerticalDirection.Up);
                }
                else if (playerCenter.Y < thisTop && isGroundPounding)
                {
                    OnBlockHit(VerticalDirection.Down);
                }
            }
            else if (sprite.HasAttribute("ShellSpinning"))
            {
                Vector2 spriteCenter = sprite.Hitbox.Center;
                float spriteXVelocity = sprite.Velocity.X;
                float thisLeft = Hitbox.Bounds.Left;
                float thisRight = Hitbox.Bounds.Right;

                if (spriteCenter.X < thisLeft || spriteCenter.X > thisRight)
                {
                    OnBlockHit(VerticalDirection.Up);
                }
            }
        }