Example #1
0
        public void TestIsLooped()
        {
            var looped = false;
            //////////////////////////////////////////////////////////////////////////////////
            // 1. Check that get and set IsLooped for an Disposed instance throw the 'ObjectDisposedException'
            var dispInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA"));

            dispInst.Dispose();
            Assert.Throws <ObjectDisposedException>(() => looped            = dispInst.IsLooped, "SoundMusic.IsLooped { get } did not throw the 'ObjectDisposedException' when called from a disposed object.");
            Assert.Throws <ObjectDisposedException>(() => dispInst.IsLooped = false, "SoundMusic.IsLooped { set } did not throw the 'ObjectDisposedException' when called from a disposed object.");

            //////////////////////////////////////////////////////////////////////////////////
            // 2. Check that set IsLooped for a playing instance throw the 'InvalidOperationException'
            var loopedWavInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectBip"));

            loopedWavInstance.Play();
            Assert.Throws <InvalidOperationException>(() => loopedWavInstance.IsLooped = true, "SoundMusic.IsLooped { set } did not throw the 'InvalidOperationException' when called from a playing sound.");
            ActiveAudioEngineUpdate(2000);

            /////////////////////////////////////////////////
            // 3. Check that IsLooped default value is false
            Assert.IsFalse(loopedWavInstance.IsLooped, "Default looping status is not false.");

            /////////////////////////////////////////////////////////////
            // 4. Check that IsLooped set/get do not crash on valid sound
            Assert.DoesNotThrow(() => looped = loopedWavInstance.IsLooped, "SoundMusic.IsLooped { get } crashed.");
            Assert.DoesNotThrow(() => loopedWavInstance.IsLooped = true, "SoundMusic.IsLooped { set } crashed.");

            //////////////////////////////////////////////////////////////
            // 5. Check that sound is looping when IsLooped is set to true
            loopedWavInstance.IsLooped = true;
            loopedWavInstance.Play();
            ActiveAudioEngineUpdate(3000);
            Assert.AreEqual(SoundPlayState.Playing, loopedWavInstance.PlayState, "Sound does not loop when Islooped is set to true.");
            loopedWavInstance.Stop();
            ActiveAudioEngineUpdate(2000);

            //////////////////////////////////////////////////////////////
            // 6. Check that sound is looping when IsLooped is set to true
            var loopedMP3Instance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBipMp3"));

            loopedMP3Instance.IsLooped = true;
            loopedMP3Instance.Play();
            ActiveAudioEngineUpdate(3000);
            Assert.AreEqual(SoundPlayState.Playing, loopedMP3Instance.PlayState, "Sound does not loop when Islooped is set to true.");
            loopedMP3Instance.Stop();
            ActiveAudioEngineUpdate(2000);

            ////////////////////////////////////////////////////////////////////////
            // 7. Check that sound has no glitches when looped a continuous sound
            contInstance.IsLooped = true;
            contInstance.Play();
            ActiveAudioEngineUpdate(3000);
            Assert.AreEqual(SoundPlayState.Playing, contInstance.PlayState, "Sound does not loop when Islooped is set to true.");
            contInstance.Stop();
        }
Example #2
0
 public static void PlayIfNotPlaying(this SoundMusic music)
 {
     if (music.PlayState != SoundPlayState.Playing)
     {
         music.Play();
     }
 }
Example #3
0
        private static void TestSoundMusicLoadingImpl(Game game)
        {
            SoundMusic sound = null;

            Assert.DoesNotThrow(() => sound = game.Asset.Load <SoundMusic>("EffectBip"), "Failed to load the SoundMusic.");
            Assert.IsNotNull(sound, "The SoundMusic loaded is null.");
            sound.Play();
            // Should hear the sound here.
        }
Example #4
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            music           = Asset.Load <SoundMusic>("MusicFishLampMp3");
            effect          = Asset.Load <SoundEffect>("EffectBip");
            music.IsLooped  = true;
            effect.IsLooped = true;
            music.Play();
            effect.Play();
        }
Example #5
0
        protected override async Task LoadContent()
        {
            await base.LoadContent();

            music = Asset.Load<SoundMusic>("MusicFishLampMp3");
            effect = Asset.Load<SoundEffect>("EffectBip");
            music.IsLooped = true;
            effect.IsLooped = true;
            music.Play();
            effect.Play();
        }
        public void TestInvalidationDuringSoundMusicPlay()
        {
            sayuriPart.Play();

            // user should unplug and plug back the the headphone here
            // and check that sound restart without throwing any exceptions.
            var count = 0;

            while (count < 1500)
            {
                ++count;

                Assert.DoesNotThrow(() => sayuriPart.Pause());
                engine.Update();

                Assert.DoesNotThrow(() => sayuriPart.Play());
                engine.Update();

                Utilities.Sleep(10);
            }

            sayuriPart.Stop();
        }
Example #7
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            foreach (var pointerEvent in Input.PointerEvents)
            {
                if (pointerEvent.State == PointerState.Up)
                {
                    music.Stop();
                    music.Play();
                    //effect.Stop();
                    //effect.Play();
                }
            }
        }
Example #8
0
        public override async Task Execute()
        {
            if (!IsLiveReloading)
            {
                // start ambient music
                SoundMusic.IsLooped = true;
                SoundMusic.Play();

                fontColor         = Color.Transparent;
                originalPositionX = RightWave.Transform.Position.X;
            }

            while (Game.IsRunning)
            {
                if (Input.PointerEvents.Any(item => item.State == PointerState.Down)) // New click
                {
                    // reset wave position
                    LeftWave.Transform.Position.X  = -originalPositionX;
                    RightWave.Transform.Position.X = originalPositionX;

                    // reset transparency
                    fontColor = Color.White;

                    // play the sound effect on each touch on the screen
                    SoundEffect.Stop();
                    SoundEffect.Play();
                }
                else
                {
                    // moving wave position
                    LeftWave.Transform.Position.X  -= 0.025f;
                    RightWave.Transform.Position.X += 0.025f;

                    // changing font transparency
                    fontColor = 0.93f * fontColor;
                    LeftWave.Get <SpriteComponent>().Color  = fontColor;
                    RightWave.Get <SpriteComponent>().Color = fontColor;
                }

                // wait for next frame
                await Script.NextFrame();
            }
        }
Example #9
0
        public void Reset()
        {
            Show();

            IsLightOn = true;

            muteButtonTimer = new HelperTimer(TimeSpan.FromSeconds(1.0), true, "MuteButtonEnabled", () => {
                showMuteButton  = true;
                muteButtonTimer = new HelperTimer(TimeSpan.FromSeconds(15.0), true, "MuteSong", () => {
                    showMuteButton = false;
                    if (Level.IsHardBoiled)
                    {
                        musicToreador.PlayIfNotPlaying();
                    }
                    else
                    {
                        musicClassicalish.PlayIfNotPlaying();
                    }
                });
            });

            showMuteButton = false;
            musicIntro.Play();
        }
Example #10
0
        public void Update(GameTime gt, InputManager input)
        {
            Bot.Update(gt, input);

            if (HasWon)
            {
                _spamFadeTime += (float)gt.Elapsed.TotalSeconds;

                if (_spamFadeTime >= SPAM_FADE_TIME)
                {
                    Main.UI.SetState(UIState.SixAM);
                }
                return;
            }

            Office.Update(gt, input);
            Laptop.Update(gt, input);

            Monsters.Update(gt, input);

            // Cheats
            if (input.IsKeyPressed(Keys.D6))
            {
                Time = VICTORY_TIME;
            }

            if (input.IsKeyPressed(Keys.F7))
            {
                CHEAT_InfiniteExposure = !CHEAT_InfiniteExposure;
            }

            if (input.IsKeyPressed(Keys.F8))
            {
                CHEAT_InfiniteBattery = !CHEAT_InfiniteBattery;
            }

            if (input.IsKeyPressed(Keys.F9))
            {
                CHEAT_MapDebug = !CHEAT_MapDebug;
            }

            if (input.IsKeyPressed(Keys.F10))
            {
                CHEAT_MonstersStayPut = !CHEAT_MonstersStayPut;
            }

            if (input.IsKeyPressed(Keys.F11))
            {
                CHEAT_OwlInvincibility = !CHEAT_OwlInvincibility;
            }

            // ESC returns to main menu
            if (input.IsKeyPressed(Keys.Escape))
            {
                UI.SetState(UIState.MainMenu);
            }

            // Bot switch
            if (input.IsKeyPressed(Keys.F1))
            {
                Bot = new PlayerMouseInput(this);
                Bot.Reset();
            }
            else if (input.IsKeyPressed(Keys.F2))
            {
                Bot = new PsychicAI(this);
                Bot.Reset();
            }
            else if (input.IsKeyPressed(Keys.F3))
            {
                Bot = new SmartAI(this);
                Bot.Reset();
            }

            if (_flipUpEnabled && Bot.MousePos.Y >= FLIPUP_THRESHOLD && !_isMouseLingering && !IsJumpscaring)
            {
                Laptop.ToggleLaptop();
                _isMouseLingering = true;
            }

            if (Bot.MousePos.Y < FLIPUP_THRESHOLD && _isMouseLingering && !IsJumpscaring)
            {
                _isMouseLingering = false;
            }

            if (!IsJumpscaring)
            {
                Time += (float)gt.Elapsed.TotalSeconds;
            }
            else
            {
                if (gt.FrameCount % 2 == 0)
                {
                    jumpscareShakeOffset = new Vector2((float)(Rand.NextDouble() * JUMPSCARE_SHAKE_RANGE + JUMPSCARE_SHAKE_MIN),
                                                       (float)(Rand.NextDouble() * JUMPSCARE_SHAKE_RANGE + JUMPSCARE_SHAKE_MIN));
                }

                if (Main.UI.State == UIState.Laptop)
                {
                    Laptop.ToggleLaptop();
                }
            }

            if (Monsters.IsExposed)
            {
                _exposureShakeOffset = (int)(Math.Sin(gt.Total.TotalSeconds * SHAKE_SPEED) * EXPOSURE_SHAKE_MAX);
            }

            if (Exposure >= 0.95f && CHEAT_InfiniteExposure)
            {
                Exposure = 0;                 // Reset exposure at 95%
            }

            if (Monsters.IsExposed && Exposure >= 1.0f && !CHEAT_InfiniteExposure)
            {
                IsJumpscaring = true;
                Monsters.StartJumpscareFromExposure();
                exposureUpSound.Stop();
            }

            if (Time >= VICTORY_TIME && !IsJumpscaring)
            {
                HasWon = true;
                spamMusic.Play();

                Main.HasWon = true;

                if (IsHardBoiled)
                {
                    Main.HasWonHardboiled = true;
                }
            }

            _flipUpEnabled = false;
            if (!Laptop.IsLaptopSwitching)
            {
                if (Main.UI.State == UIState.Laptop || Office.IsLightOn)
                {
                    _flipUpEnabled = true;
                }
            }

            if (Main.UI.State == UIState.Office && Office.IsLightOn)
            {
                const float CHARGE_SPEED = 1.0f / LAPTOP_BATTERY_TIME;
                LaptopBattery = Math.Min(LaptopBattery + CHARGE_SPEED * (float)gt.Elapsed.TotalSeconds, 1.0f);
            }
        }
Example #11
0
        public void SetState(UIState state)
        {
            UIState prev = State;

            State = state;

            if (State == UIState.MainMenu)
            {
                inputRegions.Clear();

                inputRegions.Add(new InputRegion(HARDBOILED_INPUTBOX, true, (i) => {
                    if (!Main.HasWon)
                    {
                        return;
                    }

                    if (Rand.Next(RARE_SCREEN_RARITY) == 0)
                    {
                        SetStateNextFrame(UIState.RareStartup);
                    }
                    else
                    {
                        SetStateNextFrame(UIState.Survive);
                    }

                    Main.Level.IsHardBoiled = true;
                }));

                inputRegions.Add(new InputRegion(STARTGAME_INPUTBOX, true, (i) => {
                    if (Rand.Next(RARE_SCREEN_RARITY) == 0)
                    {
                        SetStateNextFrame(UIState.RareStartup);
                    }
                    else
                    {
                        SetStateNextFrame(UIState.Survive);
                    }

                    Main.Level.IsHardBoiled = false;
                }));

                inputRegions.Add(new InputRegion(FULLSCREEN_INPUTBOX, true, (i) => {
                    Main.MainGame.ToggleFullscreen();
                }));

                InputRegion volumeInput = new InputRegion(VOLUME_INPUTBOX);
                volumeInput.MouseDown += _volume_MouseDown;
                inputRegions.Add(volumeInput);

                menuMusic.Play();
            }
            else
            {
                menuMusic.Stop();
            }

            if (State == UIState.RareStartup)
            {
                inputRegions.Clear();

                RareStartupIndex = Rand.Next(0, RARE_SCREEN_COUNT) + 1;
                timer            = new HelperTimer(TimeSpan.FromSeconds(RARE_STARTUP_TIME), "RareStartupEnd", () => { SetStateNextFrame(UIState.Survive); });
            }

            if (State == UIState.Survive)
            {
                inputRegions.Clear();

                _staticScreensLeft = STATIC_SCREEN_LENGTH;

                timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_DELAY), "SurviveDelay", () => {
                    timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_FADETIME), "SurviveFade", () => { SetStateNextFrame(UIState.Office); });
                });

                Main.Level.Laptop.soundCameraChange.Play();
            }

            if (State == UIState.YouDied)
            {
                inputRegions.Clear();
                inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (i) => { SetStateNextFrame(UIState.MainMenu); }));
            }

            if (State == UIState.Static)
            {
                inputRegions.Clear();

                timer = new HelperTimer(TimeSpan.FromSeconds(DEATH_STATIC_TIME), "DeathStaticEnd", () => { SetState(UIState.YouDied); });
                soundStatic.Play();
                Main.Level.Office.musicClassicalish.Stop();
            }
            else
            {
                soundStatic.Stop();
            }

            if (State == UIState.SixAM)
            {
                inputRegions.Clear();

                _spamOffset = SPAM_SIZE.Y;

                timer = new HelperTimer(TimeSpan.FromSeconds(SPAM_DELAY), "SpamBegin", () => {
                    _doingSpam = true;
                    timer      = new HelperTimer(TimeSpan.FromSeconds(SPAM_TIME), "SpamEnd", () => {
                        _doingSpam = false;
                        if (Main.Level.IsHardBoiled)
                        {
                            SetState(UIState.Newspaper);
                        }
                        else
                        {
                            SetState(UIState.TheEggnd);
                        }
                    });
                });

                Main.Level.Office.musicClassicalish.Stop();
            }

            if (State == UIState.TheEggnd)
            {
                inputRegions.Clear();

                timer = new HelperTimer(TimeSpan.FromSeconds(THE_EGGND_TIME), "TheEggndTime", () => { SetState(UIState.MainMenu); });

                Main.Level.spamMusic.Stop();
                theEggndMusic.Play();
            }
            else
            {
                theEggndMusic.Stop();
            }

            if (State == UIState.Newspaper)
            {
                inputRegions.Clear();

                timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEIN_TIME), "NewspaperIn", () => {
                    inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (n) => {
                        timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEOUT_TIME), "NewspaperOut", () => {
                            SetStateNextFrame(UIState.MainMenu);
                            newspaperMusic.Stop();
                        });
                    }));
                });

                newspaperMusic.Play();
            }

            if (State == UIState.Office)
            {
                inputRegions.Clear();

                if (prev != UIState.Laptop)
                {
                    Main.Level.Reset();
                }
                else
                {
                    Main.Level.Laptop.Hide();
                    Main.Level.Office.Show();
                }
            }
            else
            {
                Main.Level.Hide();
            }

            if (State == UIState.Laptop)
            {
                inputRegions.Clear();

                if (prev != UIState.Office)
                {
                    Main.Level.Reset();                     // should never happen
                }
                else
                {
                    Main.Level.Office.Hide();
                    Main.Level.Laptop.Show();
                }
            }
        }
Example #12
0
        public void TestPlay()
        {
            /////////////////////////////////////
            // 1. Check that Play does not crash
            Assert.DoesNotThrow(monoInstance.Play, "Call to SoundMusic.Play crashed throwing an exception.");

            ////////////////////////////////////////////////////////////////////
            // 2. Check that a second call to Play while playing does not crash
            Assert.DoesNotThrow(monoInstance.Play, "Second call to SoundMusic.Play while playing crashed throwing an exception.");

            ////////////////////////////////////////////
            // 3. Listen that the played sound is valid
            ActiveAudioEngineUpdate(1500);

            //////////////////////////////////////////////////////////////////
            // 4. Check that there is no crash when restarting the sound
            Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after it finishes crashed throwing an exception.");
            ActiveAudioEngineUpdate(200);

            //////////////////////////////////////////////////////////////////////////////////////////////////////
            // 5. Check  that there is no crash when playing after pausing the sound and that play flow is correct
            monoInstance.Pause();
            ActiveAudioEngineUpdate(200);
            Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after pausing it crashed throwing an exception.");
            ActiveAudioEngineUpdate(1500);

            //////////////////////////////////////////////////////////////////////////////////////////////////////
            // 6. Check that there is no crash when playing after stopping a sound and that the play flow restart
            monoInstance.Play();
            ActiveAudioEngineUpdate(200);

            monoInstance.Stop();
            ActiveAudioEngineUpdate(200);
            Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after stopping it crashed throwing an exception.");
            int timeCount = 0;

            while (monoInstance.PlayState == SoundPlayState.Playing)
            {
                ActiveAudioEngineUpdate(1000);
                timeCount += 1000;

                if (timeCount > 3000)
                {
                    Assert.Fail("SoundMusic.Play has not finished after 3 seconds.");
                }
            }

            ////////////////////////////////////////////////////////////////
            // 7. Play a stereo file a listen that the played sound is valid
            stereoInstance.Play();
            ActiveAudioEngineUpdate(3000);

            //////////////////////////////////////////////////////////////////////////////////
            // 8. Check that Playing an Disposed instance throw the 'ObjectDisposedException'
            var dispInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA"));

            dispInstance.Dispose();
            Assert.Throws <ObjectDisposedException>(dispInstance.Play, "SoundEffectInstance.Play did not throw the 'ObjectDisposedException' when called from a disposed object.");

            ////////////////////////////////////////////////////////////////
            // 9. Play a mp3 file and listen that the played sound is valid
            mp3Instance.Play();
            ActiveAudioEngineUpdate(4000);

            //////////////////////////////////////////////////////////////////////////////
            // 10. Play another music and check that the previous one is correctly stopped
            monoInstance.Play();
            Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "Mono intstance play status is not what it is supposed to be.");
            Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "MP3 intstance play status is not what it is supposed to be.");
            ActiveAudioEngineUpdate(1500);
        }
Example #13
0
        public Office(Level level)
        {
            Level = level;

            CameraOffset = new Vector2(MAX_CAMERA_OFFSET / 2.0f, 0);

            lightswitchInput = new InputRegion(LIGHTSWITCH_INPUTBOX, false, (i) => {
                IsLightOn = !IsLightOn;

                if (IsLightOn)
                {
                    soundLightOn.Play();

                    if (!Level.IsHardBoiled)
                    {
                        musicClassicalish.Play();
                    }
                }
                else
                {
                    soundLightOff.Play();
                    Level.Monsters.GoldenFlumpty.Shoo();

                    if (!Level.IsHardBoiled)                     // Don't pause music in hard boiled mode
                    {
                        musicClassicalish.Pause();
                    }
                }
            });

            buttonLeftInput = new InputRegion(BUTTON_LEFT_OFFSET + CameraOffset, BUTTON_SIZE, true, (i) => {
                if (Vent != VentState.Left)
                {
                    Vent        = VentState.Left;
                    _ventMoving = true;
                    soundVent.Stop();
                    soundVent.Play();
                }
            });

            buttonRightInput = new InputRegion(BUTTON_RIGHT_OFFSET + CameraOffset, BUTTON_SIZE, false, (i) => {
                if (Vent != VentState.Right)
                {
                    Vent        = VentState.Right;
                    _ventMoving = true;
                    soundVent.Stop();
                    soundVent.Play();
                }
            });

            rawrInput = new InputRegion(RAWR_HITBOX_OFFSET + CameraOffset, RAWR_HITBOX_SIZE, true, (i) => {
                soundRawr.Stop();
                soundRawr.Play();                 // spammable
            });

            muteIntroInput = new InputRegion(MUTE_INTRO_INPUTBOX, false, (i) => {
                musicIntro.Stop();
                showMuteButton = false;
                muteButtonTimer.Stop();

                if (Level.IsHardBoiled)
                {
                    musicToreador.Play();
                }
                else
                {
                    musicClassicalish.Play();
                }
            });

            Vent = VentState.Left;
        }