/// <summary> /// Updates the position of the dog, and plays sounds. /// </summary> public override void Update(GameTime gameTime, AudioManager audioManager) { // Set the entity to a fixed position. Position = new Vector3(0, 0, -4000); Forward = Vector3.Forward; Up = Vector3.Up; Velocity = Vector3.Zero; // If the time delay has run out, start or stop the looping sound. // This would normally go on forever, but we stop it after a six // second delay, then start it up again after four more seconds. timeDelay -= gameTime.ElapsedGameTime; if (timeDelay < TimeSpan.Zero) { if (activeSound == null) { // If no sound is currently playing, trigger one. activeSound = audioManager.Play3DSound("DogSound", true, this); timeDelay += TimeSpan.FromSeconds(6); } else { // Otherwise stop the current sound. activeSound.Stop(false); activeSound = null; timeDelay += TimeSpan.FromSeconds(4); } } }
/// <summary> /// Updates the position of the dog, and plays sounds. /// </summary> public override void Update(GameTime gameTime, AudioManager audioManager) { // Set the entity to a fixed position. Position = new Vector3(0, 0, -4000); Forward = Vector3.Forward; Up = Vector3.Up; Velocity = Vector3.Zero; // If the time delay has run out, start or stop the looping sound. // This would normally go on forever, but we stop it after a six // second delay, then start it up again after four more seconds. timeDelay -= gameTime.ElapsedGameTime; if (timeDelay < TimeSpan.Zero) { if (activeSound == null) { // If no sound is currently playing, trigger one. activeSound = audioManager.Play3DSound("DogSound", true, this); timeDelay += TimeSpan.FromSeconds(6); } else { // Otherwise stop the current sound. activeSound.Stop(false); activeSound = null; timeDelay += TimeSpan.FromSeconds(4); } } }
/// <summary> /// Updates the position of the cat, and plays sounds. /// </summary> public override void Update(GameTime gameTime, AudioManager audioManager) { // Move the cat in a big circle. double time = gameTime.TotalGameTime.TotalSeconds; float dx = (float)-Math.Cos(time); float dz = (float)-Math.Sin(time); Vector3 newPosition = new Vector3(dx, 0, dz) * 6000; // Update entity position and velocity. Velocity = newPosition - Position; Position = newPosition; if (Velocity == Vector3.Zero) Forward = Vector3.Forward; else Forward = Vector3.Normalize(Velocity); Up = Vector3.Up; // If the time delay has run out, trigger another single-shot sound. timeDelay -= gameTime.ElapsedGameTime; if (timeDelay < TimeSpan.Zero) { // For variety, randomly choose between three slightly different // variants of the sound (CatSound0, CatSound1, and CatSound2). string soundName = "CatSound" + random.Next(3); audioManager.Play3DSound(soundName, false, this); timeDelay += TimeSpan.FromSeconds(1.25f); } }
/// <summary> /// Updates the position of the cat, and plays sounds. /// </summary> public override void Update(GameTime gameTime, AudioManager audioManager) { // Move the cat in a big circle. double time = gameTime.TotalGameTime.TotalSeconds; float dx = (float)-Math.Cos(time); float dz = (float)-Math.Sin(time); Vector3 newPosition = new Vector3(dx, 0, dz) * 6000; // Update entity position and velocity. Velocity = newPosition - Position; Position = newPosition; if (Velocity == Vector3.Zero) { Forward = Vector3.Forward; } else { Forward = Vector3.Normalize(Velocity); } Up = Vector3.Up; // If the time delay has run out, trigger another single-shot sound. timeDelay -= gameTime.ElapsedGameTime; if (timeDelay < TimeSpan.Zero) { // For variety, randomly choose between three slightly different // variants of the sound (CatSound0, CatSound1, and CatSound2). string soundName = "CatSound" + random.Next(3); audioManager.Play3DSound(soundName, false, this); timeDelay += TimeSpan.FromSeconds(1.25f); } }