Esempio n. 1
0
        /// <summary>
        /// takes the destruction action.
        /// </summary>
        /// <param name="attackerPosition">the position of attacker</param>
        public override void ActionDead(Vector3 attackerPosition)
        {
            engageAction = Action.Dead;

            MoveStop();

            //  Remove collision
            colLayerEnemyMech.RemoveCollide(this.Collide);
            colLayerAllMech.RemoveCollide(this.Collide);

            GameSound.Stop(soundMove);
            soundDestroy1 = GameSound.Play3D(SoundTrack.DestroyHeavyMech1, this);

            Matrix world = Matrix.CreateTranslation(WorldTransform.Translation);

            GameParticle.PlayParticle(ParticleType.DestroyTank1, world,
                                      Matrix.Identity);

            Material.alpha              = 1.0f;
            Material.diffuseColor       = Color.Black;
            Material.specularColor      = Color.Black;
            Material.emissiveColor      = Color.Black;
            Material.vertexColorEnabled = true;

            this.SourceBlend      = Blend.SourceAlpha;
            this.DestinationBlend = Blend.InverseSourceAlpha;
            this.AlphaBlendEnable = true;
            this.ReferenceAlpha   = 0;

            //  AI process stop
            AIContext.Enabled = false;

            turretAngleSpeed = 0.0f;
        }
Esempio n. 2
0
        /// <summary>
        /// takes the idle action.
        /// </summary>
        public override void ActionIdle()
        {
            if (GameSound.IsPlaying(soundMove))
            {
                GameSound.Stop(soundMove);
            }

            engageAction = Action.Idle;
        }
Esempio n. 3
0
        /// <summary>
        /// takes the destruction action.
        /// </summary>
        /// <param name="attackerPosition">the position of attacker</param>
        public override void ActionDead(Vector3 attackerPosition)
        {
            Vector3 dir = Vector3.Normalize(attackerPosition - Position);

            float FrontDot = Vector3.Dot(Direction, dir);
            float RightDot = Vector3.Dot(Right, dir);

            if (FrontDot > 0.5f)
            {
                // Hit from front
                engageAction = Action.BackwardDead;
            }
            else if (FrontDot < -0.5f)
            {
                // Hit from back
                engageAction = Action.ForwardDead;
            }
            else if (RightDot >= 0.0f)
            {
                //  Hit from right
                engageAction = Action.LeftDead;
            }
            else if (RightDot < 0.0f)
            {
                //  Hit from left
                engageAction = Action.RightDead;
            }

            soundDestroy1 = GameSound.Play3D(SoundTrack.DestroyHeavyMech1, this);

            Matrix world = Matrix.CreateTranslation(WorldTransform.Translation);

            GameParticle.PlayParticle(ParticleType.DestroyHeavyMech1,
                                      world, Matrix.Identity);

            //  Remove collision
            colLayerEnemyMech.RemoveCollide(Collide);

            MoveStop();

            GameSound.Stop(soundMove);

            Material.alpha              = 1.0f;
            Material.diffuseColor       = Color.Black;
            Material.specularColor      = Color.Black;
            Material.emissiveColor      = Color.Black;
            Material.vertexColorEnabled = true;

            this.SourceBlend      = Blend.SourceAlpha;
            this.DestinationBlend = Blend.InverseSourceAlpha;
            this.AlphaBlendEnable = true;
            this.ReferenceAlpha   = 0;

            //  AI process stop
            AIContext.Enabled = false;
        }
Esempio n. 4
0
        /// <summary>
        /// stops reloading sound.
        /// </summary>
        /// <returns></returns>
        public bool StopReloadSound()
        {
            if (GameSound.IsPlaying(soundReload))
            {
                GameSound.Stop(soundReload);
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        /// <summary>
        /// stops firing sound.
        /// </summary>
        /// <returns></returns>
        public bool StopFireSound()
        {
            if (GameSound.IsPlaying(soundFire))
            {
                GameSound.Stop(soundFire);
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// takes the idle action.
        /// </summary>
        public override void ActionIdle()
        {
            if (GameSound.IsPlaying(soundMove))
            {
                GameSound.Stop(soundMove);
            }

            engageAction = Action.Idle;

            this.actionElapsedTime    = 0.0f;
            this.fireDelayElapsedTime = 0.0f;
        }
Esempio n. 7
0
        /// <summary>
        /// tank's A.I. function.
        /// moves to the position and stops when collides with others.
        /// </summary>
        /// <param name="aiBase">current A.I.</param>
        /// <param name="gameTime"></param>
        public override void OnAIMoveEvent(AIBase aiBase, GameTime gameTime)
        {
            if (aiBase.IsActive)
            {
                Vector3 vMoveVelocity = new Vector3(0.0f, 0.0f, SpecData.MoveSpeed);

                CollisionResult result = MoveHitTest(gameTime, vMoveVelocity);
                if (result != null)
                {
                    if (GameSound.IsPlaying(soundMove))
                    {
                        GameSound.Stop(soundMove);
                    }

                    MoveStop();     //  Cannot move
                }
                else
                {
                    Move(vMoveVelocity);

                    if (!GameSound.IsPlaying(soundMove))
                    {
                        soundMove = GameSound.Play3D(SoundTrack.TankMove, this);
                    }
                }
            }
            else
            {
                if (GameSound.IsPlaying(soundMove))
                {
                    GameSound.Stop(soundMove);
                }

                MoveStop();

                turretAngleSpeed = 0.0f;

                SetNextAI(AIType.Search, HelperMath.RandomNormal());
            }
        }
Esempio n. 8
0
        /// <summary>
        /// reloads weapon.
        /// plays reloading particle depending on unit type.
        /// </summary>
        /// <param name="type">unit type</param>
        /// <returns></returns>
        public bool Reload(UnitTypeId type)
        {
            this.state = WeaponState.Reloading;

            ParticleType reloadParticle = ParticleType.Count;
            SoundTrack   reloadSound    = SoundTrack.Count;

            switch (this.WeaponType)
            {
            case WeaponType.PlayerMachineGun:
            {
                reloadParticle = ParticleType.PlayerMachineGunReload;

                switch (type)
                {
                case UnitTypeId.Grund:
                case UnitTypeId.Kiev:
                    reloadSound = SoundTrack.PlayerMachineGunGrundReload;
                    break;

                case UnitTypeId.Mark:
                case UnitTypeId.Yager:
                    reloadSound = SoundTrack.PlayerMachineGunMarkReload;
                    break;
                }
            }
            break;

            case WeaponType.PlayerShotgun:
            {
                //  Shotgun reload is no particle
                reloadSound = SoundTrack.PlayerShotgunReload;
            }
            break;

            case WeaponType.PlayerHandgun:
            {
                reloadParticle = ParticleType.PlayerHandgunReload;
                reloadSound    = SoundTrack.PlayerHandgunReload;
            }
            break;
            }

            //  Play a reloading particle
            if (reloadParticle != ParticleType.Count)
            {
                for (int i = 0; i < SpecData.ModelCount; i++)
                {
                    int boneIdx = -1;

                    Matrix boneTransform = Matrix.Identity;

                    boneIdx       = this.indexWeaponFireDummy[i];
                    boneTransform = modelWeapon[i].BoneTransforms[boneIdx];

                    if (reloadParticle != ParticleType.Count)
                    {
                        GameParticle.PlayParticle(reloadParticle, boneTransform,
                                                  Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)));
                    }
                }
            }

            switch (this.WeaponType)
            {
            case WeaponType.PlayerMachineGun:
            {
                if (GameSound.IsPlaying(soundFire))
                {
                    GameSound.Stop(soundFire);
                }
            }
            break;
            }

            //  Play a reload sound
            if (reloadSound != SoundTrack.Count)
            {
                if (RobotGameGame.CurrentGameLevel.Info.GamePlayType ==
                    GamePlayTypeId.Versus)
                {
                    soundReload = GameSound.Play3D(reloadSound,
                                                   RobotGameGame.SinglePlayer.Emitter);
                }
                else
                {
                    soundReload = GameSound.Play3D(reloadSound, this.OwnerUnit.Emitter);
                }
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// decides the moving animation according to velocity.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="vMoveVelocity"></param>
        public void ActionMovement(GameTime gameTime, Vector3 vMoveVelocity)
        {
            bool canMove = true;

            //  Forward
            if (vMoveVelocity.Z > 0.0f)
            {
                if (CurrentAction != Action.ForwardWalk)
                {
                    engageAction = Action.ForwardWalk;
                }
            }
            //  Backward
            else if (vMoveVelocity.Z < 0.0f)
            {
                if (CurrentAction != Action.BackwardWalk)
                {
                    engageAction = Action.BackwardWalk;
                }
            }
            else if (vMoveVelocity.X > 0.0f)
            {
                if (CurrentAction != Action.RightWalk)
                {
                    engageAction = Action.RightWalk;
                }
            }
            //  Backward
            else if (vMoveVelocity.X < 0.0f)
            {
                if (CurrentAction != Action.LeftWalk)
                {
                    engageAction = Action.LeftWalk;
                }
            }
            //  Move Stop
            else
            {
                canMove = false;

                ActionIdle();
            }

            if (canMove)
            {
                //  Play a moving sound
                if (engageAction == Action.ForwardWalk ||
                    engageAction == Action.BackwardWalk ||
                    engageAction == Action.RightWalk ||
                    engageAction == Action.LeftWalk)
                {
                    if ((CurrentAction != Action.ForwardWalk &&
                         CurrentAction != Action.BackwardWalk &&
                         CurrentAction != Action.RightWalk &&
                         CurrentAction != Action.LeftWalk) || moveElapsedTime == 0.0f)
                    {
                        GameSound.Stop(soundMove);
                        soundMove = GameSound.Play3D(SoundTrack.BossWalk, this);

                        moveElapsedTime = 0.0f;
                    }

                    //  Calculate run animation playing time for run sound
                    if (moveDurationTime > moveElapsedTime)
                    {
                        moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        moveElapsedTime = 0.0f;
                    }
                }
            }
            else
            {
                if (GameSound.IsPlaying(soundMove))
                {
                    GameSound.Stop(soundMove);
                }
            }
        }
        /// <summary>
        /// checks the winning condition of the versus play.
        /// Any player who has destroyed the other as many as the kill point wins.
        /// </summary>
        protected override void CheckMission(GameTime gameTime)
        {
            if (isFinishedVersus == false)
            {
                for (int i = 0; i < GameLevel.PlayerCountInLevel; i++)
                {
                    GamePlayer player = GameLevel.GetPlayerInLevel(i);

                    //  Whoever wins the set points first, the versus mode will end.
                    if (RobotGameGame.VersusGameInfo.killPoint <= player.KillPoint)
                    {
                        isFinishedVersus = true;
                    }
                }
            }

            if (isFinishedVersus)
            {
                //  Visible mission result image
                if (missionResultElapsedTime > MissionResultVisibleTime)
                {
                    this.spriteObjHudVersusWin.Visible  = true;
                    this.spriteObjHudVersusLose.Visible = true;
                }
                else
                {
                    if (missionResultElapsedTime < MissionResultVisibleTime)
                    {
                        missionResultElapsedTime +=
                            (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }

                    this.spriteObjHudVersusWin.Visible  = false;
                    this.spriteObjHudVersusLose.Visible = false;
                }

                if (GameSound.IsPlaying(soundBGM))
                {
                    float scaleFactor = 1.0f;
                    if (GameLevel.Info.GamePlayType == GamePlayTypeId.Versus)
                    {
                        scaleFactor = 0.8f;
                    }

                    //  Scale the image size and position for screen resolution
                    Vector2 sizeScale =
                        new Vector2((float)FrameworkCore.ViewWidth * scaleFactor /
                                    (float)ViewerWidth.Width1080,
                                    (float)FrameworkCore.ViewHeight * scaleFactor /
                                    (float)ViewerHeight.Height1080);

                    for (int i = 0; i < GameLevel.PlayerCountInLevel; i++)
                    {
                        GamePlayer player = GameLevel.GetPlayerInLevel(i);

                        //  Player sound and action stop
                        player.MissionEnd();

                        //  Win!!
                        if (RobotGameGame.VersusGameInfo.killPoint <= player.KillPoint)
                        {
                            int scaledWidth =
                                (int)((float)imageWinWidth * sizeScale.X);
                            int scaledHeight =
                                (int)((float)imageWinHeight * sizeScale.Y);

                            int posX = (int)((FrameworkCore.ViewWidth / 2) -
                                             (scaledWidth / 2));

                            int posY = (int)((FrameworkCore.ViewHeight / 2) -
                                             (scaledHeight / 2));

                            if (player.PlayerIndex == PlayerIndex.One)
                            {
                                posY -= FrameworkCore.ViewHeight / 4;
                            }
                            else if (player.PlayerIndex == PlayerIndex.Two)
                            {
                                posY += FrameworkCore.ViewHeight / 4;
                            }

                            this.spriteObjHudVersusWin.ScreenRectangle = new Rectangle(
                                posX, posY,
                                scaledWidth, scaledHeight);
                        }
                        //  Lose!!
                        else
                        {
                            int scaledWidth =
                                (int)((float)imageLoseWidth * sizeScale.X);
                            int scaledHeight =
                                (int)((float)imageLoseHeight * sizeScale.Y);

                            int posX = (int)((FrameworkCore.ViewWidth / 2) -
                                             (scaledWidth / 2));

                            int posY = (int)((FrameworkCore.ViewHeight / 2) -
                                             (scaledHeight / 2));

                            if (player.PlayerIndex == PlayerIndex.One)
                            {
                                posY -= FrameworkCore.ViewHeight / 4;
                            }
                            else if (player.PlayerIndex == PlayerIndex.Two)
                            {
                                posY += FrameworkCore.ViewHeight / 4;
                            }

                            this.spriteObjHudVersusLose.ScreenRectangle = new Rectangle(
                                posX, posY,
                                scaledWidth, scaledHeight);
                        }
                    }

                    //  Stop background music
                    GameSound.Stop(soundBGM);

                    //  Play success music
                    GameSound.Play(SoundTrack.MissionClear);

                    //  Invisible all of the Hud
                    SetVisibleHud(false);

                    //  Go to main menu
                    NextScreen        = new VersusReadyScreen();
                    TransitionOffTime = TimeSpan.FromSeconds(8.0f);
                    ExitScreen();
                }
            }
            else
            {
                // Respawns a destroyed player in the game.
                for (int i = 0; i < GameLevel.PlayerCountInLevel; i++)
                {
                    GamePlayer player = GameLevel.GetPlayerInLevel(i);

                    if (player.IsFinishedDead)
                    {
                        int otherSidePlayerIndex = -1;

                        if (i == 0)
                        {
                            otherSidePlayerIndex = 1;
                        }
                        else if (i == 1)
                        {
                            otherSidePlayerIndex = 0;
                        }

                        GamePlayer otherSidePlayer =
                            GameLevel.GetPlayerInLevel(otherSidePlayerIndex);

                        //  Find the farthest positions for enemy positions.
                        RespawnInLevel respawn = GameLevel.FindRespawnMostFar(
                            otherSidePlayer.WorldTransform.Translation);

                        //  Set to respawn position
                        player.SpawnPoint = Matrix.CreateRotationY(
                            MathHelper.ToRadians(respawn.SpawnAngle)) *
                                            Matrix.CreateTranslation(respawn.SpawnPoint);

                        //  Reset the player info
                        player.Reset(true);
                    }
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// determines the animation according to velocity.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="vMoveVelocity"></param>
        public void ActionMovement(GameTime gameTime, Vector3 vMoveVelocity)
        {
            bool canMove = true;

            //  Forward
            if (vMoveVelocity.Z > 0.0f)
            {
                if (CurrentAction != Action.ForwardWalk)
                {
                    engageAction = Action.ForwardWalk;
                }
            }
            //  Backward
            else if (vMoveVelocity.Z < 0.0f)
            {
                if (CurrentAction != Action.BackwardWalk)
                {
                    engageAction = Action.BackwardWalk;
                }
            }
            else if (vMoveVelocity.X > 0.0f)
            {
                if (CurrentAction != Action.RightWalk)
                {
                    engageAction = Action.RightWalk;
                }
            }
            //  Backward
            else if (vMoveVelocity.X < 0.0f)
            {
                if (CurrentAction != Action.LeftWalk)
                {
                    engageAction = Action.LeftWalk;
                }
            }
            //  Move Stop
            else
            {
                canMove = false;

                ActionIdle();
            }

            SoundTrack moveSound = SoundTrack.CameleerWalk;

            switch (this.UnitType)
            {
            case UnitTypeId.Cameleer: moveSound = SoundTrack.CameleerWalk; break;

            case UnitTypeId.Maoming: moveSound = SoundTrack.MaomingWalk; break;

            case UnitTypeId.Duskmas: moveSound = SoundTrack.DuskmasWalk; break;

            case UnitTypeId.Tiger: moveSound = SoundTrack.TankMove; break;

            case UnitTypeId.Hammer: moveSound = SoundTrack.HammerWalk; break;
            }

            if (canMove)
            {
                //  Play a moving sound
                if (engageAction == Action.ForwardWalk ||
                    engageAction == Action.BackwardWalk ||
                    engageAction == Action.RightWalk ||
                    engageAction == Action.LeftWalk)
                {
                    if ((CurrentAction != Action.ForwardWalk &&
                         CurrentAction != Action.BackwardWalk &&
                         CurrentAction != Action.RightWalk &&
                         CurrentAction != Action.LeftWalk) || moveElapsedTime == 0.0f)
                    {
                        GameSound.Stop(soundMove);
                        soundMove = GameSound.Play3D(moveSound, this);

                        moveElapsedTime = 0.0f;
                    }

                    //  Calculate run animation playing time for run sound
                    if (moveDurationTime > moveElapsedTime)
                    {
                        moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        moveElapsedTime = 0.0f;
                    }
                }
            }
            else
            {
                if (GameSound.IsPlaying(soundMove))
                {
                    GameSound.Stop(soundMove);
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        /// checks the mission objective during the game play.
        /// Moves to the next stage after the mission gets cleared, 
        /// and when the mission is failed, returns to the main menu.
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void CheckMission(GameTime gameTime)
        {
            //  Checking mission
            if (IsMissionFailed == false)
            {
                IsMissionFailed = GameLevel.IsMissionFailed();
            }

            if (IsMissionClear == false)
            {
                IsMissionClear = gameLevel.IsMissionClear();
            }

            //  Mission complete!!
            if (IsMissionClear )
            {
                if (GameSound.IsPlaying(soundBGM))
                {
                    SetVisibleHud(false);

                    //  The volume for the sound effects besides the 
                    //  background music will be lowered.
                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Default.ToString(), 0.4f);

                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Effect.ToString(), 0.4f);

                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Music.ToString(), 1.0f);

                    //  Stop background music
                    GameSound.Stop(soundBGM);

                    //  Play victory music
                    GameSound.Play(SoundTrack.MissionClear);

                    //  Player stop
                    for (int i = 0; i < GameLevel.PlayerCountInLevel; i++)
                    {
                        GamePlayer player = GameLevel.GetPlayerInLevel(i);

                        player.MissionEnd();
                    }

                    if (NextScreen == null)
                        throw new InvalidOperationException("Please set to next screen");

                    //  Go to next stage
                    ExitScreen();
                }

                //  display the clear image
                if (missionResultElapsedTime > MissionResultVisibleTime)
                {
                    this.spriteObjMissionClear.Visible = true;
                }
                else
                {
                    if (missionResultElapsedTime < MissionResultVisibleTime)
                    {
                        missionResultElapsedTime +=
                                    (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }

                    this.spriteObjMissionClear.Visible = false;
                }
            }
            //  Mission failed
            else if (IsMissionFailed )
            {
                if (GameSound.IsPlaying(soundBGM))
                {
                    SetVisibleHud(false);

                    //  The volume for the sound effects besides the 
                    //  background music will be lowered.
                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Default.ToString(), 0.4f);

                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Effect.ToString(), 0.4f);

                    FrameworkCore.SoundManager.SetVolume(
                                        SoundCategory.Music.ToString(), 1.0f);

                    //  Stop background music
                    GameSound.Stop(soundBGM);

                    //  Play fail music
                    GameSound.Play(SoundTrack.MissionFail);

                    //  Player sound and action stop
                    for (int i = 0; i < GameLevel.PlayerCountInLevel; i++)
                    {
                        GamePlayer player = GameLevel.GetPlayerInLevel(i);

                        player.MissionEnd();
                    }

                    //  Go to main menu
                    NextScreen = new MainMenuScreen();
                    TransitionOffTime = TimeSpan.FromSeconds(8.0f);
                    ExitScreen();
                }

                //  display the failed image
                if (missionResultElapsedTime > MissionResultVisibleTime)
                {
                    this.spriteObjMissionFailed.Visible = true;
                }
                else
                {
                    if (missionResultElapsedTime < MissionResultVisibleTime)
                    {
                        missionResultElapsedTime +=
                                        (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }

                    this.spriteObjMissionFailed.Visible = false;
                }
            }
        }