Exemplo n.º 1
0
        /// <summary>
        /// Handles rock collisions and damages the player appropriately.
        /// </summary>
        /// <param name="fallingObjectComponent">The <see cref="FallingObjectComponent"/> that manages creation and movement of falling objects.</param>
        private void HandleRocks(FallingObjectComponent fallingObjectComponent)
        {
            // Handle rocks that may hit the player
            foreach (Rock rock in fallingObjectComponent.Objects.Where(p => p is Rock))
            {
                if (!rock.IsOnGround && !rock.HasHit && rock.CollisionBounds.IntersectsWith(this.Game.Character.CollisionBounds))
                {
                    this.Game.Character.Hitpoints -= rock.Ore.GetRockDamage();
                    rock.HasHit = true;

                    this.Game.Sound.Play(SoundComponent.Sound.Hurt);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles healing crates and restores the player's health appropriately.
        /// </summary>
        /// <param name="fallingObjectComponent">The <see cref="FallingObjectComponent"/> that manages creation and movement of falling objects.</param>
        private void HandleHealingCrates(FallingObjectComponent fallingObjectComponent)
        {
            // For each crate, check if it collided with the player, and if so, heal them
            foreach (MedicalCrate crate in fallingObjectComponent.Objects.Where(p => p is MedicalCrate))
            {
                if (crate.CollisionBounds.IntersectsWith(this.Game.Character.CollisionBounds))
                {
                    // Heal the dwarf!
                    crate.Heal(this.Game.Character);
                }
            }

            // Remove the ones we crashed into
            fallingObjectComponent.Objects.RemoveAll(p => p is MedicalCrate && ((MedicalCrate)p).Healing <= 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles nitroglycerin crates and awards the player vials of nitroglycerin appropriately.
        /// </summary>
        /// <param name="fallingObjectComponent">The <see cref="FallingObjectComponent"/> that manages creation and movement of falling objects.</param>
        private void HandleNitroglycerinCrates(FallingObjectComponent fallingObjectComponent)
        {
            // For each crate, check if it collided with the player, and if so, give them another vial of nitroglycerin
            foreach (NitroglycerinCrate nitroCrates in fallingObjectComponent.Objects.Where(p => p is NitroglycerinCrate))
            {
                if (nitroCrates.CollisionBounds.IntersectsWith(this.Game.Character.CollisionBounds) && nitroCrates.ContainsVial)
                {
                    nitroCrates.Loot(this.Game.Character);
                }
            }

            // Remove the ones we crashed into
            fallingObjectComponent.Objects.RemoveAll(p => p is NitroglycerinCrate && !((NitroglycerinCrate)p).ContainsVial);
        }