Пример #1
0
        protected override void OnUpdate(GameTime gameTime)
        {
            //  model moves to the position
            if (this.veclocity != Vector3.Zero)
            {
                Vector3 velocityPerFrame =
                    CalculateVelocityPerFrame(gameTime, this.veclocity);

                AddPosition(velocityPerFrame);
            }

            //  Updates collision mesh
            if (modelCollide != null)
            {
                modelCollide.Transform(TransformedMatrix);
            }

            //  If Animated bones
            if (this is GameAnimateModel)
            {
                //  If this is root bone,
                //  the world transformed matrix weight with only root bone
                this.ModelData.model.Root.Transform *= this.TransformedMatrix;
            }
            //  If no animated bones (static bones)
            else
            {   // Set the world matrix as the root transform of the model.
                this.ModelData.model.Root.Transform = this.TransformedMatrix;
            }

            // Look up combined bone matrices for the entire the model.
            this.ModelData.model.CopyAbsoluteBoneTransformsTo(this.boneTransforms);
        }
Пример #2
0
        /// <summary>
        /// processes the current state finfo.
        /// If dropped onto the world, only one model gets rotated.
        /// </summary>
        protected override void OnUpdate(GameTime gameTime)
        {
            //  In world ?
            if (InWorld)
            {
                //  Drawable weapon model is one
                GameModel droppedWeapon = this.modelWeapon[0];

                // will be enable the first weapon model.
                droppedWeapon.Enabled = true;
                droppedWeapon.Visible = true;

                //  moves first weapon model to new position
                droppedWeapon.Position = this.Position;

                //  disables the second weapon model.
                //
                for (int i = 1; i < modelWeapon.Length; i++)
                {
                    this.modelWeapon[i].Enabled = false;
                    this.modelWeapon[i].Visible = false;
                }

                rotateAngleAccm += rotateAnglePerSecond *
                                   (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (rotateAngleAccm > 360.0f)
                {
                    rotateAngleAccm = 0.0f;
                }

                //  rotates weapon's model in the world.
                droppedWeapon.WorldTransform =
                    Matrix.CreateRotationY(MathHelper.ToRadians(rotateAngleAccm)) *
                    TransformedMatrix;

                //  updates collision.
                if (modelCollide != null)
                {
                    modelCollide.Transform(TransformedMatrix);
                }
            }

            switch (this.state)
            {
            //  ready now.
            case WeaponState.Ready:
            {
                this.actionElapsedTime = 0.0f;
            }
            break;

            //  firing now.
            case WeaponState.Firing:
            {
                //  Finished firing
                if (this.specData.FireIntervalTime <= this.actionElapsedTime)
                {
                    this.fireCount++;

                    if (this.fireCount >= this.specData.FireCount)
                    {
                        this.state     = WeaponState.Ready;
                        this.fireCount = 0;
                    }
                    else
                    {
                        this.OwnerUnit.WeaponFire();
                    }

                    this.actionElapsedTime = 0.0f;
                }
                //  Firing now
                else
                {
                    this.actionElapsedTime +=
                        (float)FrameworkCore.ElapsedDeltaTime.TotalSeconds;
                }
            }
            break;

            //  reloading now.
            case WeaponState.Reloading:
            {
                //  Finished reloading
                if (this.specData.ReloadIntervalTime <= this.actionElapsedTime)
                {
                    //  Unlimited ammo
                    if (this.specData.TotalBulletCount == -1)
                    {
                        this.currentAmmo = specData.ReloadBulletCount;
                        this.remainAmmo  = specData.ReloadBulletCount;
                    }
                    //  When the number of the total bullets is sufficient
                    if (this.specData.ReloadBulletCount - this.currentAmmo
                        <= this.remainAmmo)
                    {
                        int supplyAmmo = specData.ReloadBulletCount
                                         - this.currentAmmo;

                        this.remainAmmo  -= supplyAmmo;
                        this.currentAmmo += supplyAmmo;
                    }
                    //  When the no. of the reload bullets is smaller than
                    //  the no. of total bullets,
                    else
                    {
                        int supplyAmmo = this.remainAmmo;

                        this.remainAmmo  -= supplyAmmo;
                        this.currentAmmo += supplyAmmo;
                    }

                    this.state             = WeaponState.Ready;
                    this.actionElapsedTime = 0.0f;
                }
                //  Reloading now
                else
                {
                    this.actionElapsedTime +=
                        (float)FrameworkCore.ElapsedDeltaTime.TotalSeconds;
                }
            }
            break;
            }

            base.OnUpdate(gameTime);
        }