Category5.Victim.RecieveHit C# (CSharp) Method

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
        protected virtual float RecieveHit(float Damage, Tornado tornado)
        {
            float tempvar = this.GroundHealth - Damage; //How much damage we would do negative is overkill

            switch (this.state)
            {
                case State.Ground:
                    if (tempvar <= 0)
                    {
                        if (soundHit != "" && Damage > 0)
                            SoundEffectEngine.Play(soundHit, SoundEffectEngine.Priority.Normal);
                        //INFO: Inform object it is dead change state to flying and get picked up by tornado

                        this.GroundHealth = 0;
                        this.tornado = tornado;
                        this.state = State.Flying;
                        Victim newVictim = this.Clone();
                        newVictim.requestRemoveFromMegaTile = true;
                        newVictim.megatile = null;
                        tornado.AddVictim(newVictim);
                        this.state = State.Stump;
                        //if (megatile != null)
                        //{
                            this.requestRemoveFromMegaTile = removeFromMegaTileOnDeath;
                        //}
                    }
                    else
                    {
                        this.GroundHealth = tempvar;
                    }
                    break;
            }

            return tempvar;
        }

Usage Example

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;
                }
            }
        }