RecieveHit() protected method

Recieve a hit at a certain damange and returns if the building was destroyed
protected RecieveHit ( float Damage, Tornado tornado ) : float
Damage float
tornado Tornado
return float
Ejemplo n.º 1
0
        /// <summary>
        /// Try and damage our victims with our stats
        /// </summary>
        /// <param name="victimsToCollideWith"></param>
        protected virtual void HitCheck(Victim groundObject)
        {
            if (groundObject.state == State.Ground)
            {
                float diameter = 0.0f;
                if (bounds.Width > bounds.Height)
                {
                    diameter = bounds.Width;
                }
                else
                {
                    diameter = bounds.Height;
                }

                Rectangle2D collideBox = new Rectangle2D(this.bounds.Center.X - (diameter / 2.0f), this.bounds.Center.Y - (diameter / 2.0f), diameter, diameter);

                switch (state)
                {
                    case State.Flying:
                        if (collideBox.Rectangle.Intersects(groundObject.bounds.Rectangle)) //we need to add damage
                        {
                            SoundEffectEngine.Play(soundHit,SoundEffectEngine.Priority.Normal);

                            float damageDone = getDamage(groundObject);

                            float resdamage = groundObject.RecieveHit(damageDone, this.tornado);

                            if (resdamage > 0)
                            {
                                this.TornadoHealth = 0; //If we can't kill the ground
                            }

                            if (this.TornadoHealth <= 0)
                            {
                                state = State.Exploding;
                            }
                        }
                        break;
                }
            }
        }