Exemplo n.º 1
0
        /// <summary>
        /// Clone this component.
        /// </summary>
        /// <returns>Cloned ship controller.</returns>
        public override BaseComponent Clone()
        {
            AsteroidControls ret = new AsteroidControls();

            ret._scaleFactor = _scaleFactor;
            ret._speedFactor = _speedFactor;
            ret._maxHp       = _maxHp;
            ret._hp          = _hp;
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Split this asteroid into two, or destroy it if too small.
        /// </summary>
        private void SplitMeteor()
        {
            // get base size
            RigidBody body     = _GameObject.GetComponent <RigidBody>();
            float     currSize = body.Scale.X;

            // create explosion effect
            GameObject explosion = Managers.Prototypes.Spawn("explosion");

            explosion.SceneNode.Position = _GameObject.SceneNode.WorldPosition;
            explosion.Parent             = _GameObject.Parent;

            // too small? destroy
            if (currSize < 1.5f)
            {
                _GameObject.Destroy();
                return;
            }

            // split the meteor
            for (int i = -1; i <= 1; i += 2)
            {
                // create the meteor split
                GameObject split = _GameObject.Clone();

                // override some meteor controls properties before it spawns
                AsteroidControls splitControls = split.GetComponent <AsteroidControls>();
                RigidBody        splitBody     = split.GetComponent <RigidBody>();

                // set clonsed hp and scale factor
                splitControls._hp    = _maxHp / 2;
                splitControls._maxHp = _hp;

                // set scale and velocity
                Vector3 newScale = body.Scale * 0.75f;
                splitBody.Scale            = newScale;
                splitControls._scaleFactor = newScale.X;
                splitBody.ConstVelocity    = body.ConstVelocity.Value + new Vector3(i * 2f, 0, 0);

                // so we won't init the split from spawn and override its settings
                splitControls._alreadyInit = true;

                // add to scene (this will invoke spawn event)
                split.Parent = _GameObject.Parent;
            }

            // destroy self
            _GameObject.Destroy();
        }