示例#1
0
        public void PlayCue(
            string name,
            AudioListener listener,
            AudioEmitter emitter
            )
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (!INTERNAL_cueData.ContainsKey(name))
            {
                throw new InvalidOperationException("name not found!");
            }
            Cue newCue = new Cue(
                INTERNAL_baseEngine,
                INTERNAL_waveBankNames,
                name,
                INTERNAL_cueData[name],
                true
                );

            newCue.Apply3D(listener, emitter);
            newCue.Play();
        }
示例#2
0
        /// <summary>
        /// Plays a cue with static 3D positional information.
        /// </summary>
        /// <remarks>
        /// Commonly used for short lived effects.  To dynamically change the 3D
        /// positional information on a cue over time use <see cref="GetCue"/> and <see cref="Cue.Apply3D"/>.</remarks>
        /// <param name="name">The name of the cue to play.</param>
        /// <param name="listener">The listener state.</param>
        /// <param name="emitter">The cue emitter state.</param>
        public void PlayCue(string name, AudioListener listener, AudioEmitter emitter)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            XactSound[] sounds;
            if (!_sounds.TryGetValue(name, out sounds))
            {
                throw new InvalidOperationException();
            }

            float [] probs;
            if (!_probabilities.TryGetValue(name, out probs))
            {
                throw new ArgumentException();
            }

            IsInUse = true;

            var cue = new Cue(_audioengine, name, sounds, probs);

            cue.Prepare();
            cue.Apply3D(listener, emitter);
            cue.Play();
        }
示例#3
0
文件: Audio.cs 项目: bradleat/trafps
 public void Apply3DPosition(Cue cue, AudioListener listener, AudioEmitter emitter,
     Vector3 listenerPosition, Vector3 emitterPosition)
 {
     listenerPosition = listener.Position;
     emitterPosition = emitter.Position;
     cue.Apply3D(listener, emitter);
 }
示例#4
0
文件: Audio.cs 项目: bradleat/trafps
 public void Apply3DAll(Cue cue, AudioListener listener, AudioEmitter emitter, Vector3 listenerPosition,
     Vector3 emitterPosition, Vector3 listenerVelocity, Vector3 emitterVelocity)
 {
     listenerPosition = listener.Position;
     emitterPosition = emitter.Position;
     listener.Velocity = listener.Velocity;
     emitter.Velocity = emitter.Velocity;
     cue.Apply3D(listener, emitter);
 }
示例#5
0
        public void PlayCue(
			string name,
			AudioListener listener,
			AudioEmitter emitter
		)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (!INTERNAL_cueData.ContainsKey(name))
            {
                throw new InvalidOperationException("name not found!");
            }
            Cue newCue = new Cue(
                INTERNAL_baseEngine,
                INTERNAL_waveBankNames,
                name,
                INTERNAL_cueData[name],
                true
            );
            newCue.Apply3D(listener, emitter);
            newCue.Play();
        }
示例#6
0
文件: Audio.cs 项目: bradleat/trafps
 public void Apply3DVelocity(Cue cue, AudioListener listener, AudioEmitter emitter, Vector3 emitterVelocity, Vector3 listenerVelocity)
 {
     listenerVelocity = listener.Velocity;
     emitterVelocity = emitter.Velocity;
     cue.Apply3D(listener, emitter);
 }
示例#7
0
文件: Audio.cs 项目: bradleat/trafps
 public void Apply3D(Cue cue, AudioListener listener, AudioEmitter emitter)
 {
     cue.Apply3D(listener, emitter);
 }
示例#8
0
        /// <summary>
        /// Handles input for the specified player. In local game modes, this is called
        /// just once for the controlling player. In network modes, it can be called
        /// more than once if there are multiple profiles playing on the local machine.
        /// Returns true if we should continue to handle input for subsequent players,
        /// or false if this player has paused the game.
        /// </summary>
        bool HandlePlayerInput(InputState input, PlayerIndex playerIndex)
        {
            // Look up inputs for the specified player profile.
            KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[(int)playerIndex];

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!
            bool gamePadDisconnected = !gamePadState.IsConnected &&
                                       input.GamePadWasConnected[(int)playerIndex];

            if (input.IsPauseGame(playerIndex) || gamePadDisconnected)
            {
                if (sessionState == SessionState.Started)
                {
                    ScreenManager.AddScreen(new PauseMenuScreen(networkSession), playerIndex);

                    ScreenManager.menu_change.Play();

                    return false;
                }

                if (sessionState == SessionState.Complete)
                {
                    Exit();
                }
            }

            if (sessionState == SessionState.Started
                || sessionState == SessionState.Edit)
            {
                float timeDifference = (float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;

                Player.HandleInput(timeDifference);

                PlayerIndex pI = PlayerIndex.Four;
                if (input.IsNewKeyPress(Keys.Space, playerIndex, out pI)
                    ||
                    input.IsNewButtonPress(Buttons.RightTrigger, playerIndex, out pI))
                {
                    if (!parentGame.NormalMode)
                    {
                        if (TimeRemaining > 0)
                            FireBullet();
                    }
                    else
                        FireBullet();
                }

                float thumbRX = gamePadState.ThumbSticks.Right.X;
                if (thumbRX != 0)
                {
                    Player.turretRotationValue -= 0.05f * thumbRX;
                    float value = MathHelper.ToDegrees(Player.turretRotationValue);
                    value = (float)Math.Round(value, 0);
                    if (value % 10 == 0)
                    {
                        if (!RotateCue.IsPlaying)
                        {
                            RotateCue = parentGame.soundBank.GetCue("rotate");
                            AudioEmitter emmit = new AudioEmitter();
                            emmit.Position = Player.position;
                            RotateCue.Apply3D(listener, emmit);
                            RotateCue.Play();
                        }
                    }
                }

                float thumbRY = gamePadState.ThumbSticks.Right.Y;
                if (thumbRY != 0)
                {
                    Player.cannonRotationValue -= 0.05f * thumbRY;
                    Player.cannonRotationValue = MathHelper.Clamp(Player.cannonRotationValue, MathHelper.ToRadians(-45), MathHelper.ToRadians(10));

                    float value = MathHelper.ToDegrees(Player.cannonRotationValue);
                    value = (float)Math.Round(value, 0);
                    if (value % 2 == 0
                        && value != -45
                        && value != 10)
                    {
                        if (!ElevateCue.IsPlaying)
                        {
                            ElevateCue = parentGame.soundBank.GetCue("elevate");
                            AudioEmitter emmit = new AudioEmitter();
                            emmit.Position = Player.position;
                            ElevateCue.Apply3D(listener, emmit);
                            ElevateCue.Play();

                        }
                    }
                }

                float thumbLY = gamePadState.ThumbSticks.Left.Y;
                if (thumbLY != 0)
                {
                    Player.Power += 0.01f * thumbLY;

                    if (Player.Power > 1)
                        Player.Power = 1f;
                    else if (Player.Power < 0.1f)
                        Player.Power = 0.1f;

                    //power = 0 - 1
                    float value = Player.Power;
                    value *= 100;
                    //value = (float)Math.Round(value, 2);
                    value = (float)Math.Floor(value);
                    if (value % 5 == 0 &&
                        value != 100 && value != 10)
                    {
                        if (!PowerCue.IsPlaying)
                        {
                            PowerCue = parentGame.soundBank.GetCue("power");
                            PowerCue.SetVariable("PowerLevel", Player.Power);
                            AudioEmitter emmit = new AudioEmitter();
                            emmit.Position = Player.position;
                            PowerCue.Apply3D(listener, emmit);
                            PowerCue.Play();
                        }
                    }
                }

                MouseState mouseState = Mouse.GetState();
                if (input.IsNewKeyPress(Keys.M, playerIndex, out pI))
                    CamIsFollow = (CamIsFollow) ? false : true;

                if (input.IsNewKeyPress(Keys.N, playerIndex, out pI))
                    sessionState = (sessionState == SessionState.Edit) ? SessionState.Started : SessionState.Edit;

                if (input.IsNewKeyPress(Keys.P, playerIndex, out pI))
                    NormalDrawing.BLEND += 1;

                if (sessionState == SessionState.Edit)
                {
                    TerrEditor.HandleInput();
                }

                prevMouseState = mouseState;
            }

            if (sessionState == SessionState.Complete)
            {
                if (input.IsMenuSelect(playerIndex, out playerIndex))
                {
                    Exit();
                }
            }

            #region OLD PLAYER
            // Otherwise move the player position.
            Vector2 movement = Vector2.Zero;

            if (keyboardState.IsKeyDown(Keys.Left))
                movement.X--;

            if (keyboardState.IsKeyDown(Keys.Right))
                movement.X++;

            if (keyboardState.IsKeyDown(Keys.Up))
                movement.Y--;

            if (keyboardState.IsKeyDown(Keys.Down))
                movement.Y++;

            Vector2 thumbstick = gamePadState.ThumbSticks.Left;

            movement.X += thumbstick.X;
            movement.Y -= thumbstick.Y;

            if (movement.Length() > 1)
                movement.Normalize();

            playerPosition += movement * 2;
            #endregion

            return true;
        }
示例#9
0
        void FireBullet()
        {
            float timeNow = (float)gameTime.TotalGameTime.TotalMilliseconds / 1000.0f;
            float timeDiff = timeNow - shotTime;

            if ((MissileRemain > 0) && (timeDiff > ReloadTimeSec))
            {
                shotTime = timeNow;
                //MissileRemain--;

                Missile missile = new Missile(parentGame, rocketModel, rocketTextures, NormalDrawing, this);
                missile.position = new Vector3(
                    Player.position.X,
                    Player.position.Y,
                    Player.position.Z);
                Vector3 forwardVec = Matrix.CreateFromYawPitchRoll(
                    Player.turretRotationValue - MathHelper.ToRadians(90f),
                    0f,
                    0f).Forward;
                forwardVec.Normalize();

                missile.position += forwardVec * 11;

                missile.scale = 1;

                float DECLINATION = -Player.cannonRotationValue; // stays in radians

                // sin in radians                       // width                    // height
                missile.position.Y = (float)(Math.Sin(DECLINATION) * 13.3) + Player.position.Y + 4;

                float ROTATION = Player.turretRotationValue - MathHelper.ToRadians(90f);
                Matrix Orientation = Matrix.CreateFromYawPitchRoll(ROTATION, DECLINATION, 0f);
                //LevelVars.Player.FacingDirection
                //DECLINATION
                missile.SetBody(Orientation);

                Vector3 force = Orientation.Forward;
                force.Normalize();
                Vector3 angle = Orientation.Left;
                angle.Normalize();

                float power = 120f * Player.Power;
                missile.Body.ApplyWorldImpulse(force * power);
                missile.Body.AngularVelocity = (angle * MathHelper.Clamp((0.8f - Player.Power), 0.20f, 0.6f));

                missile.rgob.limbs[0].PhysicsBody.ApplyWorldImpulse(force * power * 5);
                missile.rgob.limbs[0].PhysicsBody.AngularVelocity = (angle * MathHelper.Clamp((0.8f - Player.Power), 0.20f, 0.6f) * 1);

                //missile.Body.AngularVelocity += (force * 1.5f);

                missile.Skin.callbackFn += new CollisionCallbackFn(MissileColllisionFunction);

                BulletList.Add(missile);

                FollowCam.Following = true;
                FollowCam.myMissile = missile;
                FollowCam.NewUpDownRot = missile.rotation.Y;
                FollowCam.NewLeftRightRot = (Player.turretRotationValue - MathHelper.ToRadians(90));

                cue = parentGame.soundBank.GetCue("fire");
                AudioEmitter emmit = new AudioEmitter();
                emmit.Position = Player.position;
                cue.Apply3D(listener, emmit);
                cue.Play();

                Vector3 effectPos = (missile.position - forwardVec * 2);
                for (int i = 0; i < 25; ++i)
                    NormalDrawing.shotSmokeParticles.AddParticle(effectPos, new Vector3(0, 0, 0));

                for (int i = 0; i < 25; ++i)
                    NormalDrawing.shotExplosionParticles.AddParticle(effectPos, new Vector3(0, 0, 0));
            }
        }
示例#10
0
        public bool PieceColllisionFunction(CollisionSkin skin0, CollisionSkin skin1)
        {
            // here is handled what happens if your Object collides with another special Object (= OtherObject)
            if ((skin1.ExternalData) != null && (skin1.ExternalData) is TriangleMeshActor)
            {
                // since this instance is a 'bad guy' he deactivates 'Good Guys' when it collides with them
                if ((skin0.Owner.ExternalData) is BuildingPiece)
                {
                    //((BuildingPiece)skin0.Owner.ExternalData).Destroy();

                    BuildingPiece piece = (skin0.Owner.ExternalData) as BuildingPiece;

                    if (!piece.ContactGround)
                    {
                        cue = parentGame.soundBank.GetCue("piece_bounce");
                        AudioEmitter emmit = new AudioEmitter();
                        emmit.Position = piece.position;
                        cue.Apply3D(listener, emmit);
                        cue.Play();
                    }
                    piece.ContactGround = true;
                }

                return true;
            }
            //else
            //{
            //    if ((skin0.Owner.ExternalData) is BuildingPiece)
            //    {
            //        BuildingPiece piece = (skin0.Owner.ExternalData) as BuildingPiece;
            //        piece.ContactGround = false;
            //    }
            //    return true;
            //}

            return true;
        }
示例#11
0
        public void Update(GameTime gameTime)
        {
            if (currentMusic == null)
            {
                currentMusic = soundBank.GetCue(GetRandomTrack(currentPlaylist));
                //Fake 3D Sound for Surround Effect ;)
                currentMusic.Apply3D(new AudioListener(), new AudioEmitter());
                currentMusic.Play();
                popUpText.Text = currentPlaylist[currentMusic.Name];
                StartPopUp();
            }
            if (currentMusic.IsStopped)
            {
                currentMusicindex++;
                if (currentMusicindex >= playList.Keys.Count)
                    currentMusicindex = 0;
                currentMusic = soundBank.GetCue(GetRandomTrack(currentPlaylist));
                currentMusic.Apply3D(new AudioListener(), new AudioEmitter());
                currentMusic.Play();
                popUpText.Text = currentPlaylist[currentMusic.Name];
                StartPopUp();
            }
            if (transition)
            {
                oldVolume -= gameTime.GetElapsedTotalSecondsFloat();
                oldVolume = MathHelper.Clamp(oldVolume, 0, options.MusicVolumeFloat);
                currentVolume += gameTime.GetElapsedTotalSecondsFloat();
                if (currentVolume >= options.MusicVolumeFloat)
                {
                    transition = false;
                    currentVolume = MathHelper.Clamp(currentVolume, 0, options.MusicVolumeFloat);
                    oldCategory.Stop(AudioStopOptions.Immediate);
                    oldMusic.Stop( AudioStopOptions.Immediate);
                }
                oldCategory.SetVolume(oldVolume);
                currentCategory.SetVolume(currentVolume);
            }
            if (popUpActive)
            {
                if (popUpFloatIn)
                {
                    popUp.Y += (int)(popUpSpeed * gameTime.GetElapsedTotalSecondsFloat());
                    AlignPopUpText();
                    if (popUp.Y >= 0)
                    {
                        popUpFloatIn = false;
                    }
                }
                else
                {
                    popUpStillStandelpasedTime += gameTime.GetElapsedTotalSecondsFloat();
                    if (popUpStillStandelpasedTime >= popUpStillStandThreshold)
                    {
                        popUp.Y-= (int)(popUpSpeed * gameTime.GetElapsedTotalSecondsFloat());
                        if (popUp.X <= -(int)(options.Resolution.ScreenHeight * 0.1))
                            popUpActive = false;
                        AlignPopUpText();
                    }
                }

            }
        }
示例#12
0
 public static void Apply3D(Cue cue, AudioEmitter emitter)
 {
     cue.Apply3D(AudioListener.GetClosestListener(emitter.Position), emitter);
 }