Ejemplo n.º 1
0
        // Function for collision responses with other collidables
        public override void OnCollision(Collidable obj)
        {
            if (obj is Platform platform)
            {
                if (onGround == false)
                {
                    // Setting the appropriate values upon collision
                    onGround = true;

                    velocity.Y = 0;

                    // Calculating depth to resolve collisions
                    // Method used from Platformer Game from Microsoft XNA Community Game Platform
                    Vector2 depth = RectangleExtensions.GetIntersectionDepth(GetRectangle(), platform.GetRectangle());

                    // If there is some depth,
                    // then push the player appropriately in the Y axis
                    if (depth != Vector2.Zero)
                    {
                        position = new Vector2(position.X, position.Y + depth.Y);
                    }
                }

                // The dash ability resets when
                // the player is on the ground
                canDash = true;
            }
            else if (obj is Pickup pickup)
            {
                switch (pickup.GetPickupType())
                {
                // Refill Health or Magic based on the pickup type
                case PickupType.Health:
                    if (Health + pickup.GetRefillPoints() <= MaxHealth)
                    {
                        Health += pickup.GetRefillPoints();
                    }
                    else
                    {
                        Health = MaxHealth;
                    }
                    break;

                case PickupType.Magic:
                    if (Magic + pickup.GetRefillPoints() <= MaxMagic)
                    {
                        Magic += pickup.GetRefillPoints();
                    }
                    else
                    {
                        Magic = MaxMagic;
                    }
                    break;
                }
            }
            else if (obj is Boss boss)
            {
                Health  -= 10;
                hitTaken = true;
            }
            else if (obj is BlackFogSword sword)
            {
                // Take damage only if the player
                // hasn't taken a hit and if the
                // sword is swinging
                if (sword.Attacked == false &&
                    sword.Swinging == true)
                {
                    Health  -= sword.Damage;
                    hitTaken = true;
                }
            }
            else if (obj is BlackFogShockwave wave)
            {
                // Take damage only when
                // the shockwave is moving
                if (wave.Pounded == true)
                {
                    Health  -= wave.Damage;
                    hitTaken = true;
                }
            }

            // SWAMP CRY COLLISIONS

            else if (obj is SwampCryClub club)
            {
                // Same as the sword, take damage
                // when the club is swinging
                if (club.Attacked == false &&
                    club.Swinging == true)
                {
                    Health  -= club.Damage;
                    hitTaken = true;
                }
            }
            else if (obj is SwampCrySpell spell)
            {
                // Take damage when the spell is thrown
                if (spell.Thrown == true)
                {
                    Health  -= spell.Damage;
                    hitTaken = true;
                }
            }
        }