コード例 #1
0
        public void GivenThatTheActiveSoundListPlaysASoundWithAGameObjectWillAddingTheSoundAgainWithoutAGameObjectResetThePanAndVolume()
        {
            var ass        = new ActiveSoundService();
            var sei        = new DummySoundEffectInstance();
            var gameObject = new Mock <IGameObject>();

            gameObject.Setup(aliveGameObject => aliveGameObject.IsExtant).Returns(true);
            gameObject.Setup(objectToTheSide => objectToTheSide.Position).Returns(new Vector2(10, 10));
            var centrePointProvider = new Mock <ICentrePointProvider>();

            centrePointProvider.Setup(cp => cp.CentrePoint).Returns(Vector2.Zero);
            var activeSoundWithObject    = new ActiveSoundForObject(sei, gameObject.Object, centrePointProvider.Object);
            var activeSoundWithoutObject = new ActiveSound(sei);

            ass.Add(activeSoundWithObject);
            ass.Add(activeSoundWithoutObject);

            Assert.AreEqual(1, ass.Count);
            activeSoundWithoutObject = (ActiveSound)ass[0];
            Assert.IsTrue(sei.RestartPlayWhenStopped);
            ass.Update();
            Assert.IsFalse(sei.RestartPlayWhenStopped);
            Assert.AreEqual(1, activeSoundWithoutObject.SoundEffectInstance.Volume);
            Assert.AreEqual(0, activeSoundWithoutObject.SoundEffectInstance.Pan);
        }
コード例 #2
0
        public void GivenThatTheActiveSoundListIsEmptyCanANewSoundWithGameObjectBeAddedAndNotHaveTheDefaultVolumeAndPanning()
        {
            var ass        = new ActiveSoundService();
            var sei        = new DummySoundEffectInstance();
            var gameObject = new Mock <IGameObject>();

            gameObject.Setup(deadGameObject => deadGameObject.IsExtant).Returns(true);
            gameObject.Setup(objectToTheSide => objectToTheSide.Position).Returns(new Vector2(10, 10));
            var centrePointProvider = new Mock <ICentrePointProvider>();

            centrePointProvider.Setup(cp => cp.CentrePoint).Returns(Vector2.Zero);
            var activeSound = new ActiveSoundForObject(sei, gameObject.Object, centrePointProvider.Object);

            ass.Add(activeSound);

            Assert.AreEqual(1, ass.Count);
            var item = ass[0];

            Assert.AreEqual(SoundState.Playing, item.SoundEffectInstance.State);
            Assert.AreNotEqual(1, item.SoundEffectInstance.Volume);
            Assert.AreNotEqual(0, item.SoundEffectInstance.Pan);
        }
コード例 #3
0
        public void DoesAPlayingSoundStopIfTheAssociatedObjectIsNoLongerExtant()
        {
            var ass = new ActiveSoundService();
            var sei = new DummySoundEffectInstance();

            var gameObject = new Mock <IGameObject>();

            gameObject.Setup(deadGameObject => deadGameObject.IsExtant).Returns(true);
            var centrePointProvider = new Mock <ICentrePointProvider>();

            centrePointProvider.Setup(cp => cp.CentrePoint).Returns(Vector2.Zero);
            var activeSound = new ActiveSoundForObject(sei, gameObject.Object, centrePointProvider.Object);

            ass.Add(activeSound);
            gameObject.Setup(deadGameObject => deadGameObject.IsExtant).Returns(false);
            ass.Update();

            Assert.AreEqual(1, ass.Count);
            var item = ass[0];

            Assert.AreEqual(SoundState.Stopped, item.SoundEffectInstance.State);
        }
コード例 #4
0
        public void DoesAPlayingSoundChangeItsVolumeWhenItsAssociatedObjectMoves()
        {
            var ass        = new ActiveSoundService();
            var sei        = new DummySoundEffectInstance();
            var gameObject = new Mock <IGameObject>();

            gameObject.Setup(movingObject => movingObject.IsExtant).Returns(true);
            gameObject.SetupSequence(movingObject => movingObject.Position)
            .Returns(Vector2.Zero)
            .Returns(new Vector2(100, 0));
            var centrePointProvider = new Mock <ICentrePointProvider>();

            centrePointProvider.Setup(cp => cp.CentrePoint).Returns(Vector2.Zero);
            var activeSound = new ActiveSoundForObject(sei, gameObject.Object, centrePointProvider.Object);

            ass.Add(activeSound);
            var initialVolume = sei.Volume;

            ass.Update();
            var updatedVolume = sei.Volume;

            Assert.AreNotEqual(initialVolume, updatedVolume);
        }