示例#1
0
        public MainWindowViewModel()
        {
            Configuration.LoadConfiguration();
            Logger.Initialize();
            engine = new AudioEngine(5, false);
            int result = engine.initialize();
            if (AudioEngine.Failed(result))
                Logger.Log("Error initializing AudioEngine: " + AudioEngine.getErrorCode(result));
            renderDevices = engine.getRenderDevices().ToList();
            renderDevices.Add("Default Render Device");
            captureDevices = engine.getCaptureDevices().ToList();
            captureDevices.Add("Default Capture Device");

            captureDevice = captureDevices.Last();
            renderDevice = renderDevices.Last();

            effectWindow = new EffectCollection();

            this.volume = 100;

            StartCommand = new RelayCommand(
                        () => this.Start(),
                        () => true);
            MuteCommand = new RelayCommand(
                        () => this.Mute(),
                        () => true);
            AddEffectCommand = new RelayCommand(
                        () => this.AddEffect(),
                        () => true);
        }
    void Start()
    {
        TennisStateRenderer renderer = new TennisStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, "tennis", Settings.menu_sounds, Settings.game_sounds);

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Camera_Default", new Vector3(0, 10, 0), false));
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Light_Default", new Vector3(0, 10, 0), false));
        environment.Add(new CanvasObject("Prefabs/Tennis/OutroLogo", true, new Vector3(0, 0, 0), false));

        TennisRuleset rules = new TennisRuleset();
        rules.Add(new TennisRule("initialization", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForMenu("outro"), Vector3.zero);
            state.environment.Add(tso);
            state.stoppableSounds.Add(tso);
            return false;
        }));

        rules.Add(new TennisRule("soundOver", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            Application.Quit();
            return false;
        }));

        gameObject.AddComponent<TennisMenuEngine>();
        gameObject.AddComponent<TennisMenuUserInterface>();
        gameObject.GetComponent<TennisMenuEngine>().initialize(rules, environment, renderer);
        gameObject.GetComponent<TennisMenuUserInterface>().initialize(gameObject.GetComponent<TennisMenuEngine>());
        gameObject.GetComponent<TennisMenuEngine>().postEvent(new GameEvent("", "initialization", "unity"));
    }
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = new AudioEngine();

            using (var monoStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                monoSoundEffect = SoundEffect.Load(defaultEngine, monoStream);
            }
            using (var stereoStream = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                stereoSoundEffect = SoundEffect.Load(defaultEngine, stereoStream);
            }
            using (var contStream = AssetManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousMonoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var contStream = AssetManager.FileProvider.OpenStream("EffectToneAE", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousStereoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var monoStream = AssetManager.FileProvider.OpenStream("Effect44100Hz", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                laugherMono = SoundEffect.Load(defaultEngine, monoStream);
            }

            monoInstance = monoSoundEffect.CreateInstance();
            stereoInstance = stereoSoundEffect.CreateInstance();
        }
示例#4
0
 internal static void ActiveAudioEngineUpdate(AudioEngine engine, int miliSeconds)
 {
     for (int i = 0; i < miliSeconds / 10 + 1; i++)
     {
         engine.Update();
         Utilities.Sleep(10);
     }
 }
示例#5
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();

            validWavStream = ContentManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read);
        }
示例#6
0
        public void TestDispose()
        {
            var crossDisposedEngine = new AudioEngine(); 
            var engine = new AudioEngine();
            crossDisposedEngine.Dispose(); // Check there no Dispose problems with sereval cross-disposed instances. 

            // Create some SoundEffects
            SoundEffect soundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                soundEffect = SoundEffect.Load(engine, wavStream);
            }
            SoundEffect dispSoundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                dispSoundEffect = SoundEffect.Load(engine, wavStream);
            }
            dispSoundEffect.Dispose();

            var soundEffectInstance = soundEffect.CreateInstance();
            var dispInstance = soundEffect.CreateInstance();
            dispInstance.Dispose();

            // Create some SoundMusics.
            var soundMusic1 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicBip", VirtualFileMode.Open, VirtualFileAccess.Read));
            var soundMusic2 = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicToneA", VirtualFileMode.Open, VirtualFileAccess.Read));
            soundMusic2.Dispose();

            // Create some dynamicSounds.
            var generator = new SoundGenerator();
            var dynSound1 = new DynamicSoundEffectInstance(engine, 44100, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits);
            var dynSound2 = new DynamicSoundEffectInstance(engine, 20000, AudioChannels.Mono, AudioDataEncoding.PCM_8Bits);
            dynSound1.Play();
            dynSound1.SubmitBuffer(generator.Generate(44100, new[]{ 1000f }, 1, 120000));
            dynSound2.Dispose();

            // Start playing some
            soundEffectInstance.Play();
            soundMusic1.Play();

            for (int i = 0; i < 10; i++)
            {
                engine.Update();
                Utilities.Sleep(5);
            }

            Assert.DoesNotThrow(engine.Dispose, "AudioEngine crashed during disposal.");
            Assert.IsTrue(soundEffect.IsDisposed, "SoundEffect is not disposed.");
            Assert.Throws<InvalidOperationException>(engine.Dispose, "AudioEngine did not threw invalid operation exception.");
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectInstance.PlayState, "SoundEffectInstance has not been stopped properly.");
            Assert.IsTrue(soundEffectInstance.IsDisposed, "SoundEffectInstance has not been disposed properly.");
            Assert.AreEqual(SoundPlayState.Stopped, soundMusic1.PlayState, "soundMusic1 has not been stopped properly.");
            Assert.IsTrue(soundMusic1.IsDisposed, "soundMusic1 has not been disposed properly.");
            //Assert.AreEqual(SoundPlayState.Stopped, dynSound1.PlayState, "The dynamic sound 1 has not been stopped correctly.");
            //Assert.IsTrue(dynSound1.IsDisposed, "The dynamic sound 1 has not been disposed correctly.");
        }
        public AudioFileTrack(AudioEngine audioengine, String filename, AudioTimeMarker markers, object reference=null)
            : base(audioengine)
        {
            this.reference = null;
            this.isFree = false;
            this.filename = filename;
            this.markers = markers;
            Init();

        }
        /// <summary>
        /// Based on compilation setting, returns the proper instance of sounds.
        /// </summary>
        /// <returns>A platform specific instance of <see cref="AudioEngine"/></returns>
        public static AudioEngine NewAudioEngine(AudioDevice device = null)
        {
            AudioEngine engine = null;
#if SILICONSTUDIO_PLATFORM_IOS
            engine = new AudioEngineIos();
#else
            engine = new AudioEngine(device);
#endif
            engine.InitializeAudioEngine();
            return engine;
        }
示例#9
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = new AudioEngine();

            monoInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip"));
            stereoInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicStereo"));
            contInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicToneA"));
            mp3Instance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3"));
            wavInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip"));
        }
示例#10
0
 public void ContextInitialization()
 {
     try
     {
         var engine = new AudioEngine();
         engine.Dispose();
     }
     catch (Exception e)
     {
         Assert.IsTrue(e is AudioInitializationException, "Audio engine failed to initialize but did not throw AudioInitializationException");
     }
 }
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            engine = new AudioEngine();

            using (var stream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                oneSound = SoundEffect.Load(engine, stream);
            }
            oneSound.IsLooped = true;

            sayuriPart = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));
            sayuriPart.IsLooped = true;
        }
示例#12
0
        public void TestLoad()
        {
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 1. Check that SoundEffect.Load throws "ArgumentNullException" when either 'engine' or 'stream' param is null
            // 1.1 Null engine
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.Throws<ArgumentNullException>(() => SoundEffect.Load(null, validWavStream), "SoundEffect.Load did not throw 'ArgumentNullException' when called with a null engine.");
            // 1.2 Null stream
            Assert.Throws<ArgumentNullException>(() => SoundEffect.Load(defaultEngine, null), "SoundEffect.Load did not throw 'ArgumentNullException' when called with a null stream.");

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // 2. Check that the load function throws "ObjectDisposedException" when the audio engine is disposed.
            var disposedEngine = new AudioEngine();
            disposedEngine.Dispose();
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.Throws<ObjectDisposedException>(() => SoundEffect.Load(disposedEngine, validWavStream), "SoundEffect.Load did not throw 'ObjectDisposedException' when called with a displosed audio engine.");

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 3. Check that the load function throws "InvalidOperationException" when the audio file stream is not valid
            // 3.1 Invalid audio file format.
            var otherFileFormatStream = AssetManager.FileProvider.OpenStream("EffectStereoOgg", VirtualFileMode.Open, VirtualFileAccess.Read);
            Assert.Throws<InvalidOperationException>(() => SoundEffect.Load(defaultEngine, otherFileFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with an invalid file extension.");
            otherFileFormatStream.Dispose();
            // 3.2 Corrupted Header wav file
            var corruptedWavFormatStream = AssetManager.FileProvider.OpenStream("EffectHeaderCorrupted", VirtualFileMode.Open, VirtualFileAccess.Read);
            Assert.Throws<InvalidOperationException>(() => SoundEffect.Load(defaultEngine, corruptedWavFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with a corrupted wav stream.");
            corruptedWavFormatStream.Dispose();
            // 3.3 Invalid wav file format (4-channels)
            var invalidChannelWavFormatStream = AssetManager.FileProvider.OpenStream("Effect4Channels", VirtualFileMode.Open, VirtualFileAccess.Read);
            Assert.Throws<InvalidOperationException>(() => SoundEffect.Load(defaultEngine, invalidChannelWavFormatStream), "SoundEffect.Load did not throw 'InvalidOperationException' when called with an invalid 4-channels wav format.");
            invalidChannelWavFormatStream.Dispose();

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 4. Check that the load function throws "NotSupportedException" when the audio file stream is not supported
            // 4.1 extented wav file format (5-channels)
            var extendedChannelWavFormatStream = AssetManager.FileProvider.OpenStream("EffectSurround5Dot1", VirtualFileMode.Open, VirtualFileAccess.Read);
            Assert.Throws<NotSupportedException>(() => SoundEffect.Load(defaultEngine, extendedChannelWavFormatStream), "SoundEffect.Load did not throw 'NotSupportedException' when called with an extended 5-channels wav format.");
            extendedChannelWavFormatStream.Dispose();
            // 4.2 Invalid wav file format (24bits encoding)
            var invalidEncodingWavFormatStream = AssetManager.FileProvider.OpenStream("Effect24bits", VirtualFileMode.Open, VirtualFileAccess.Read);
            Assert.Throws<NotSupportedException>(() => SoundEffect.Load(defaultEngine, invalidEncodingWavFormatStream), "SoundEffect.Load did not throw 'NotSupportedException' when called with an invalid ieeefloat encoding wav format.");
            invalidEncodingWavFormatStream.Dispose();

            ///////////////////////////////////////////////////////
            // 5. Load a valid wav file stream and try to play it
            validWavStream.Seek(0, SeekOrigin.Begin);
            Assert.DoesNotThrow(() => SoundEffect.Load(defaultEngine, validWavStream), "SoundEffect.Load have thrown an exception when called with an valid wav stream.");
        }
示例#13
0
    //private MissionType mType;
    // Use this for initialization
    void Start()
    {
        audioengine = (AudioEngine)FindObjectOfType(typeof(AudioEngine));
        galaxy = (Galaxy)FindObjectOfType(typeof(Galaxy));
        godMission = (PersistentMission)FindObjectOfType(typeof(PersistentMission));
        DontDestroyOnLoad(gameObject);
        firstUpdate = true;
        whatControllerAmIUsing = WhatControllerAmIUsing.MOUSE_KEYBOARD;
        GameObject newGalaxy = Instantiate(GalaxyPrefab, new Vector3(0, 0 ,0), Quaternion.identity) as GameObject;
        newGalaxy.name = "Galaxy";

        if (!GOD.goToRandomPointInGalaxy)
        {
            Invoke("waitForaBit", 0.5f);
        }
    }
示例#14
0
 public ValueSequence(float[] times, float[] values, double length, bool isBang, AudioEngine engine)
 {
     FTimes = times;
     FCount = FTimes.Length;
     FEngine = engine;
     FValues = new float[FCount];
     FIsBang = isBang;
     
     for(int i=0; i<FCount; i++)
     {
         FValues[i] = values[i%values.Length];
     }
     
     Array.Sort(FTimes, FValues);
     FLength = Math.Max(Math.Abs(length), 0.00000520833f);
     
     //set state
     Next(FEngine.Timer.Beat % FLength);
 }
        /// <summary>
        ///     Handles performing actions w/ the mouse
        /// </summary>
        private void HandleHitObjectMouseInput()
        {
            // Prevent clicking if in range of the nav/control bars.
            if (View.ControlBar.ScreenRectangle.Contains(MouseManager.CurrentState.Position))
            {
                return;
            }

            // Left click/place object
            if (MouseManager.IsUniqueClick(MouseButton.Left) && !View.MenuBar.IsActive)
            {
                var lane = ScrollContainer.GetLaneFromX(MouseManager.CurrentState.X);

                if (lane == -1)
                {
                    return;
                }

                var time    = (int)ScrollContainer.GetTimeFromY(MouseManager.CurrentState.Y) / ScrollContainer.TrackSpeed;
                var timeFwd = (int)AudioEngine.GetNearestSnapTimeFromTime(WorkingMap, Direction.Forward, Screen.BeatSnap.Value, time);
                var timeBwd = (int)AudioEngine.GetNearestSnapTimeFromTime(WorkingMap, Direction.Backward, Screen.BeatSnap.Value, time);

                var fwdDiff = Math.Abs(time - timeFwd);
                var bwdDiff = Math.Abs(time - timeBwd);

                if (fwdDiff < bwdDiff)
                {
                    time = timeFwd;
                }
                else if (bwdDiff < fwdDiff)
                {
                    time = timeBwd;
                }

                if (WorkingMap.TimingPoints.Count == 0)
                {
                    return;
                }

                PlaceObject(CompositionInputDevice.Mouse, lane, time);
            }
        }
示例#16
0
        /*******************************************************************************************
        * Main Load
        * *****************************************************************************************/
        protected override void LoadContent()
        {
            // load font
            spriteBatch      = new SpriteBatch(GraphicsDevice);
            statsFont        = Content.Load <SpriteFont>("Fonts/StatsFont");
            instructionsFont = Content.Load <SpriteFont>("Fonts/InstructionsFont");

            // load sounds and play initial sound
            audioEngine = new AudioEngine("Content/Audio/GameAudio.xgs");
            waveBank    = new WaveBank(audioEngine, "Content/Audio/Wave Bank.xwb");
            soundBank   = new SoundBank(audioEngine, "Content/Audio/Sound Bank.xsb");
            trackCue    = soundBank.GetCue("Tracks");
            trackCue.Play();

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // load spaceship
            spaceship.LoadContent(Content, "Models/spaceship");


            CreateObstacles1();
            CreateObstacles2();
            CreateObstacles3();
            CreateObstacles4();
            CreateObstacles5();
            CreateObstacles6();
            CreateAstronauts();
            CreateStars();

            // load ground
            ground.LoadContent(Content, "Models/ground");

            // load lifebar
            lifebar = Content.Load <Texture2D>("Textures/lifebar5");

            // load uhd
            uhd = Content.Load <Texture2D>("Textures/uhd");

            // load logo
            logo = Content.Load <Texture2D>("Textures/logo");
        }
示例#17
0
        internal static void TakeScreenshot()
        {
            GraphicsDevice device = GameBase.graphics.GraphicsDevice;
            bool           pause  = AudioEngine.AudioState == AudioEngine.AudioStates.Playing;

            if (pause)
            {
                AudioEngine.Pause();
            }

            string filename = "";

            using (Texture2D dstTexture = new Texture2D(
                       device,
                       device.Viewport.Width,
                       device.Viewport.Height,
                       1,
                       ResourceUsage.ResolveTarget,
                       SurfaceFormat.Bgr32, ResourceManagementMode.Manual))
            {
                device.ResolveBackBuffer(dstTexture);
                if (!Directory.Exists("Screenshots"))
                {
                    Directory.CreateDirectory("Screenshots");
                }

                int num = ConfigManager.sScreenshot;
                do
                {
                    num++;
                    filename = String.Format("Screenshots\\screenshot{0:000}.png", num);
                } while (File.Exists(filename));

                dstTexture.Save(filename, ImageFileFormat.Png);
            }
            if (pause)
            {
                AudioEngine.Pause();
            }

            GameBase.ShowMessage("Saved screenshot to " + filename, Color.BlueViolet, 6000);
        }
示例#18
0
        public ShipGameGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            audioEngine = new AudioEngine("content/sounds/sounds.xgs");
            waveBank    = new WaveBank(audioEngine, "content/sounds/Wave Bank.xwb");
            soundBank   = new SoundBank(audioEngine, "content/sounds/Sound Bank.xsb");

            game = new GameManager(soundBank);

            graphics.PreferredBackBufferWidth  = GameOptions.ScreenWidth;
            graphics.PreferredBackBufferHeight = GameOptions.ScreenHeight;

            //graphics.MinimumPixelShaderProfile = ShaderProfile.PS_2_0;
            //graphics.MinimumVertexShaderProfile = ShaderProfile.VS_1_1;

            IsFixedTimeStep = renderVsync;
            graphics.SynchronizeWithVerticalRetrace = renderVsync;
        }
示例#19
0
        private void Exit()
        {
            AudioEngine.PlaySample(AudioEngine.s_MenuBack);

            GameBase.ChangeMode(Modes.MatchSetup);

            if (LoadingReplay)
            {
                score.GotReplayData -= score_GotReplayData;
            }


            /*if (!ReplayMode && rankingDialog != null && (rankingDialog.saveReplay == null || !rankingDialog.saveReplay.Checked))
             * {
             *  score.replay = null;
             *  score.rawReplayCompressed = null;
             *  score.rawReplayOld = null;
             * }*/
            //rankingdialog
        }
示例#20
0
        protected void score_GotReplayData(object sender)
        {
            score.GotReplayData -= score_GotReplayData;

            LoadingReplay = false;

            if (score.replay != null)
            {
                StreamingManager.StopSpectating(false);

                AudioEngine.PlaySample(AudioEngine.s_MenuHit);
                InputManager.ReplayMode  = true;
                InputManager.ReplayScore = score;
                GameBase.ChangeMode(Modes.Play);
            }
            else
            {
                Console.WriteLine("error");
            }
        }
示例#21
0
        private BGMDataViewModel()
        {
            this.audio              = AudioEngine.Instance;
            this.audio.OggPlayback += this.OggPlayback;
            this.audio.SetVolume(0.5f);

            this.isLooping = true;

            this.seekPlayDelay = new Timer {
                Interval = 400, AutoReset = false, Enabled = false
            };
            this.seekPlayDelay.Elapsed += (sender, args) =>
            {
                if (!this.IsPlaying && this.playingWhenSeek)
                {
                    this.PlayPause();
                }
                this.playingWhenSeek = false;
            };
        }
示例#22
0
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 0 || isReporting || !hasDrawn)
            {
                selectedReport = null;
                return;
            }

            selectedReport = dataGridView1.SelectedRows[0].Tag as AiReport;

            if (selectedReport.RelatedHitObjects.Count > 0)
            {
                editor.Compose.Select(selectedReport.RelatedHitObjects.ToArray());
            }

            if (selectedReport.Time != -1)
            {
                AudioEngine.SeekTo(selectedReport.Time);
            }
        }
示例#23
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here
#if WINDOWS
            m_audioEngine = new AudioEngine("Content/Audio/Praedonum.xgs");
            m_waveBank    = new WaveBank(m_audioEngine, "Content/Audio/Wave Bank.xwb");
            m_soundBank   = new SoundBank(m_audioEngine, "Content/Audio/Sound Bank.xsb");
#endif

#if XBOX
            // TODO CHANGE THESE
            m_audioEngine = new AudioEngine("Content/Xact Tower.xgs");
            m_waveBank    = new WaveBank(m_audioEngine, "Content/WaveBank.xwb");
            m_soundBank   = new SoundBank(m_audioEngine, "Content/SoundBank.xsb");
#endif

            m_sounds = new List <Cue>();

            base.Initialize();
        }
示例#24
0
        public SoundSink(AudioEngine audioEngine, Submixer submixer = null, ISoundSinkReceiver receiver = null)
        {
            _format = new AudioFormat {
                SampleRate = 44_100, Channels = 2, BitsPerSample = 16
            };

            var silenceDataCount = (int)(_format.Channels * _format.SampleRate * sizeof(ushort) * SampleQuantum.TotalSeconds);

            _silenceData = new byte[silenceDataCount];

            Engine           = audioEngine;
            _receiver        = receiver;
            _chain           = new BufferChain(Engine);
            _circBuffer      = new CircularBuffer(_silenceData.Length);
            _tempBuf         = new byte[_silenceData.Length];
            _submixer        = submixer;
            _sinkThread      = new Thread(MainLoop);
            _sinkThread.Name = "SoundSink";
            _sinkThread.Start();
        }
示例#25
0
        protected override void Dispose(bool disposing)
        {
            KeyboardHandler.OnKeyPressed -= Game1_OnKeyPressed;
            KeyboardHandler.OnKeyRepeat  -= GameBase_OnKeyRepeat;

            AudioEngine.SetVolumeMusic(initialAudioVolume);

            GameBase.spriteManagerOverlay.RemoveTagged("b");
            GameBase.spriteManagerOverlay.RemoveTagged("np");


            if (spriteManager != null)
            {
                spriteManager.Dispose();
            }

            content.Unload();

            base.Dispose(disposing);
        }
示例#26
0
        public void Initialize(int ledCount)
        {
            audio = new AudioEngine();
            audio.Start();
            audio.NewData += OnNewAudioData;
            this.ledCount  = ledCount;
            FFT_SPACING_HZ = FFT_MAXFREQ / ledCount;

            this.lastIndex = (int)(2500 / FFT_SPACING_HZ);
            this.freqArray = new int[this.lastIndex];
            for (int i = 0; i < freqArray.Length; i++)
            {
                this.freqArray[i] = (int)Math.Floor(Utils.Scale(FFTUtil.GetFreqForIndex(i, FFT_SPACING_HZ), 0, 2500, 0, this.ledCount / 2 + 1));
            }
            leds = new Led[ledCount];
            for (int i = 0; i < ledCount; i++)
            {
                leds[i] = new Led();
            }
        }
示例#27
0
 static BackendDiscoverer()
 {
     AvailableBackends = new HashSet <AudioBackend>();
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         var engine = AudioEngine.CreateXAudio();
         if (engine != null)
         {
             AvailableBackends.Add(AudioBackend.XAudio2);
         }
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         var engine = AudioEngine.CreateOpenAL();
         if (engine != null)
         {
             AvailableBackends.Add(AudioBackend.OpenAL);
         }
     }
 }
示例#28
0
        /// <summary>
        /// Initializes the specified game.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="title">The title.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="flags">The flags.</param>
        public static void Initialize(SchwiftyGame game, string title = "", int x = 0, int y = 0, int width = 1280, int height = 720, SDL.SDL_WindowFlags flags = SDL_WindowFlags.SDL_WINDOW_SHOWN)
        {
            Resource.StartupCheck();
            SDL_Init(SDL_INIT_VIDEO);

            if (title == "")
            {
                title = Assembly.GetExecutingAssembly().GetName().FullName;
            }

            window = new Window(title, x, y, width, height, flags);
            window.Create();
            IsFullScreen = false;

            //initialize audio engine.
            AudioEngine.Init();

            SDL_ttf.TTF_Init();
            _game = game;
        }
示例#29
0
        void HoverGainedEffect(object sender, EventArgs e)
        {
            pText senderText = sender as pText;

            if (senderText != null)
            {
                if (senderText.Tag is Color)
                {
                    senderText.BackgroundColour = ColourHelper.Lighten(senderText.BackgroundColour, 0.1f);
                }
                else
                {
                    senderText.BackgroundColour = HighlightColour;
                }

                AudioEngine.Click(null, @"click-short");

                senderText.TextChanged = true;
            }
        }
示例#30
0
        public override List <Bullet> Fire(Vector gunPosition, CustomCursor cursor)
        {
            var spray     = new List <Bullet>();
            var direction = (cursor.Position - gunPosition).Normalize();
            var position  = gunPosition + direction * 48;

            spray.Add(new Bullet(
                          position,
                          direction * 30,
                          bulletWeight,
                          new Edge(position, position + direction * 32),
                          20));

            ammo--;
            ticksFromLastFire = 0;
            AudioEngine.PlayNewInstance(fireSoundPath);
            cursor.MoveBy(new Vector(r.Next(-10, 10), r.Next(-10, 10)));

            return(spray);
        }
示例#31
0
文件: Game1.cs 项目: CalmBit/Robotica
 /// <summary>
 /// LoadContent will be called once per game and is the place to load
 /// all of your content.
 /// </summary>
 protected override void LoadContent()
 {
     // Create a new SpriteBatch, which can be used to draw textures.
     spriteBatch      = new SpriteBatch(GraphicsDevice);
     font             = Content.Load <SpriteFont>("Main");
     GUISprites       = Content.Load <Texture2D>("robotica_sprites_new");
     PlayerSprites    = Content.Load <Texture2D>("robotica_player_new_bright");
     Shadow           = Content.Load <Texture2D>("robotica_shadow");
     RoomBack         = Content.Load <Texture2D>("robotica_green");
     Lock             = Content.Load <Texture2D>("lock");
     Missing          = Content.Load <Texture2D>("missing");
     Weapon           = Content.Load <Texture2D>("robotica_weapon");
     Audio            = new AudioEngine("Content\\Robotica.xgs");
     SoundEffectsBank = new SoundBank(Audio, "Content\\Sound Bank.xsb");
     WaveEffectsBank  = new WaveBank(Audio, "Content\\Wave Bank.xwb");
     for (var i = 0; i < 16; i++)
     {
         Entities.Add(new EntityWeapon(new Vector2(128 + i % 4 * 64, 128 + (i / 4) * 64)));
     }
     try
     {
         var reader = new FileStream("./Config/splash.txt", FileMode.Open);
         var sb     = new StringBuilder();
         var c      = '\0';
         while (reader.Position < reader.Length)
         {
             while ((c = (char)reader.ReadByte()) != '\n' && reader.Position != reader.Length)
             {
                 sb.Append(c);
             }
             SplashStrings.Add(sb.ToString().Trim());
             sb.Clear();
         }
         splash = rand.Next(SplashStrings.Count);
     }
     catch (Exception)
     {
         SplashStrings.Add("YOU REALLY SHOULD HAVE THAT FILE!");
     }
     // TODO: use this.Content to load your game content here
 }
        private void BeginAudioTransition(Beatmap beatmap, bool continuePlaying)
        {
            if (continuePlaying)
            {
                if (audioThread != null && audioThreadLoadingMap == BeatmapManager.Current && audioState != FadeStates.Idle)
                {
                    return;
                }

                AudioEngine.LoadAudioForPreview(BeatmapManager.Current, continuePlaying, true);
            }
            else
            {
                audioState = FadeStates.FadeOut;

                //if (audioThread != null)
                //    audioThread.Abort();

                //audioThreadLoadingMap = beatmap;

                //audioThread = GameBase.RunBackgroundThread(delegate
                //{
                //    try
                //    {
                //        while (AudioEngine.volumeMusicFade > 10)
                //        {
                //            audioState = FadeStates.FadeOut;
                //            Thread.Sleep(10);
                //        }
                //        audioState = FadeStates.Idle;
                //        AudioEngine.LoadAudioForPreview(BeatmapManager.Current, continuePlaying, true);
                //    }
                //    catch (Exception) {
                //        NotificationManager.ShowMessage("Error loading audio for this beatmap...");
                //        audioError = true;
                //    }

                //    audioThread = null;
                //});
            }
        }
示例#33
0
        private void p_play(object sender, EventArgs e)
        {
            if (!ShowControls)
            {
                return;
            }

            AudioEngine.Click(null, @"click-short-confirm");

            NotificationManager.ShowMessageMassive("Play", 1000);
            if (AudioEngine.Paused)
            {
                AudioEngine.TogglePause();
            }
            else
            {
                AudioEngine.Play();
                //ChooseRandomSong(false);
            }
            manualPause = false;
        }
示例#34
0
        public void LoadSounds()
        {
            _engine    = new AudioEngine("Content\\Sounds\\BackSounds.xgs");
            _soundBank = new SoundBank(_engine, "Content\\Sounds\\Sound Bank.xsb");
            _waveBank  = new WaveBank(_engine, "Content\\Sounds\\Wave Bank.xwb");
            _engine.GetCategory("Music");

            Sounds.Add(SoundEnum.Click, _soundBank.GetCue("RICOCHET"));
            Sounds.Add(SoundEnum.Desert, _soundBank.GetCue("wind03"));
            Sounds.Add(SoundEnum.DeadSpider, _soundBank.GetCue("guts04a"));
            Sounds.Add(SoundEnum.Grass, _soundBank.GetCue("cricket00"));
            Sounds.Add(SoundEnum.Gunshot, _soundBank.GetCue("GUNSHOT"));
            Sounds.Add(SoundEnum.Heartbeat, _soundBank.GetCue("heartbeat"));
            Sounds.Add(SoundEnum.Laser, _soundBank.GetCue("LASER"));
            Sounds.Add(SoundEnum.Lava, _soundBank.GetCue("lava_burn1"));
            Sounds.Add(SoundEnum.Lava2, _soundBank.GetCue("lava"));
            Sounds.Add(SoundEnum.MainTheme, _soundBank.GetCue("STARWARS"));
            Sounds.Add(SoundEnum.Sand, _soundBank.GetCue("wind03"));
            Sounds.Add(SoundEnum.Snow, _soundBank.GetCue("wind01b"));
            Sounds.Add(SoundEnum.Spider, _soundBank.GetCue("angry"));
        }
示例#35
0
        private void s_Hover(object sender, EventArgs e)
        {
            pSprite p = sender as pSprite;

            if (currentTier != (Tiers)p.TagNumeric)
            {
                return;
            }

            if (p.Tag != null)
            {
                pSprite p2 = ((pSprite)p.Tag);
                p2.Transformations.Clear();
                p2.Transformations.AddRange(p.Transformations);
                p2.FadeIn(150);
            }
            if (Game.IsActive)
            {
                AudioEngine.PlaySample(AudioEngine.s_MenuClick);
            }
        }
示例#36
0
            internal override void PlaySound(HitObjectSoundType type, SampleSetInfo ssi)
            {
                float volume = ssi.Volume * (0.5f + 0.5f * circularProgress.Progress);

                if ((type & HitObjectSoundType.Finish) > 0)
                {
                    AudioEngine.PlaySample(OsuSamples.HitFinish, ssi.AdditionSampleSet, volume);
                }

                if ((type & HitObjectSoundType.Whistle) > 0)
                {
                    AudioEngine.PlaySample(OsuSamples.HitWhistle, ssi.AdditionSampleSet, volume);
                }

                if ((type & HitObjectSoundType.Clap) > 0)
                {
                    AudioEngine.PlaySample(OsuSamples.HitClap, ssi.AdditionSampleSet, volume);
                }

                AudioEngine.PlaySample(OsuSamples.HitNormal, ssi.SampleSet, volume);
            }
示例#37
0
        /// <inheritdoc />
        ///  <summary>
        ///  </summary>
        ///  <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            if (!Exiting)
            {
                PlayHitsounds();

                if (ConfigManager.EditorPlayMetronome.Value)
                {
                    Metronome.Update(gameTime);
                }

                if (AudioEngine.Track.IsDisposed)
                {
                    AudioEngine.LoadCurrentTrack();
                }

                HandleInput(gameTime);
            }

            base.Update(gameTime);
        }
示例#38
0
        /// <summary>
        ///     Plays the audio track at the preview time if it has stopped
        /// </summary>
        private void KeepPlayingAudioTrackAtPreview()
        {
            if (Exiting)
            {
                return;
            }

            if (AudioEngine.Track == null)
            {
                AudioEngine.PlaySelectedTrackAtPreview();
                return;
            }

            lock (AudioEngine.Track)
            {
                if (AudioEngine.Track.HasPlayed && AudioEngine.Track.IsStopped)
                {
                    AudioEngine.PlaySelectedTrackAtPreview();
                }
            }
        }
示例#39
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            Sonya.Initialize(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            SubZero.Initialize(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            SonyaGreenBar.health(new Vector2(graphics.PreferredBackBufferWidth / 45,
                                             graphics.PreferredBackBufferHeight / 30), SonyaHealth, Color.LimeGreen);
            SonyaRedBar.health(new Vector2(graphics.PreferredBackBufferWidth / 45,
                                           graphics.PreferredBackBufferHeight / 30), SonyaHealth, Color.Red);

            SubZGreenBar.health(new Vector2(graphics.PreferredBackBufferWidth - 580,
                                            graphics.PreferredBackBufferHeight / 30), SonyaHealth, Color.LimeGreen);
            SubZRedBar.health(new Vector2(graphics.PreferredBackBufferWidth - 580,
                                          graphics.PreferredBackBufferHeight / 30), SonyaHealth, Color.Red);
            audioEngine = new AudioEngine("Content\\game music.xgs");
            waveBank    = new WaveBank(audioEngine, "Content\\Wave Bank.xwb");
            soundBank   = new SoundBank(audioEngine, "Content\\Sound Bank.xsb");
            musicCue    = soundBank.GetCue("fighting backgorund music");
            musicCue.Play();
            base.Initialize();
            this.IsMouseVisible = false;
        }
示例#40
0
        internal static void ChooseRandomSong(bool force, bool forcePreview = false)
        {
            if (BeatmapManager.Beatmaps.Count <= 0)
            {
                return;
            }

            if (BeatmapManager.Current == null || force)
            {
                List <Beatmap> maps  = playPool.Count == 0 ? BeatmapManager.Beatmaps : playPool;
                int            count = playPool.Count == 0 ? maps.Count - 1 : maps.Count;
                Beatmap        next  = maps[RNG.Next(0, count)];

                int chance = 0;
                while (chance++ < 100 && (
                           (BeatmapManager.Current != null && next.SortTitle == BeatmapManager.Current.SortTitle) || !next.AudioPresent || next.GetAudioStream() == null))
                {
                    next = maps[RNG.Next(0, count)];
                }

                if (BeatmapManager.Current != null)
                {
                    playHistory.Push(BeatmapManager.Current.BeatmapChecksum);
                }

                BeatmapManager.Current = next;
            }

            try
            {
                AudioEngine.LoadAudioForPreview(BeatmapManager.Current, true,
                                                forcePreview ||
                                                (!ConfigManager.sMenuMusic && (AudioEngine.AudioTrack == null || AudioEngine.LoadedBeatmap == null || string.IsNullOrEmpty(AudioEngine.LoadedBeatmap.ContainingFolder))));
            }
            catch (AudioNotLoadedException)
            {
            }

            SongInfo(false);
        }
示例#41
0
        internal override void Close()
        {
            if (!IsDisplayed)
            {
                return;
            }

            GameBase.User.AchievementImages = null;

            AudioEngine.PlaySample(AudioEngine.s_MenuBack);

            if (OnlineRetrival)
            {
                if (GameBase.User.Sprites != null)
                {
                    GameBase.User.Sprites[0].IsClickable = true;
                    if (SpriteCollection != null)
                    {
                        foreach (pSprite p in GameBase.User.Sprites)
                        {
                            SpriteCollection.Remove(p);
                        }
                    }

                    if (spriteManager != null)
                    {
                        spriteManager.RemoveRange(GameBase.User.Sprites);
                    }
                }
            }

            if (saveReplay != null)
            {
                ConfigManager.sSaveReplay = saveReplay.Checked;
            }

            WriteScore();

            base.Close();
        }
        /// <summary>
        ///     If necessary, it will load and play the selected map's audio.
        /// </summary>
        /// <param name="previousMap"></param>
        public static void LoadNewAudioTrackIfNecessary(Map previousMap = null)
        {
            if (previousMap != null && MapManager.GetAudioPath(previousMap) == MapManager.GetAudioPath(MapManager.Selected.Value))
            {
                return;
            }

            if (AudioEngine.Track != null && AudioEngine.Track.IsPlaying)
            {
                AudioEngine.Track.Fade(0, 200);
            }

            ThreadScheduler.Run(() =>
            {
                if (AudioEngine.Track != null)
                {
                    lock (AudioEngine.Track)
                    {
                        try
                        {
                            AudioEngine.LoadCurrentTrack(true);

                            if (AudioEngine.Track == null)
                            {
                                return;
                            }

                            AudioEngine.Track.Seek(MapManager.Selected.Value.AudioPreviewTime);
                            AudioEngine.Track.Volume = 0;
                            AudioEngine.Track.Play();
                            AudioEngine.Track.Fade(100, 800);
                        }
                        catch (Exception)
                        {
                            // ignored.
                        }
                    }
                }
            });
        }
示例#43
0
        private FingerprintSignature MakeSubFingerID(string key, string filename)
        {
            FingerprintSignature fingerprint = null;

            AudioEngine audioEngine = new AudioEngine();

            try
            {
                SpectrogramConfig spectrogramConfig = new DefaultSpectrogramConfig();

                AudioSamples samples = null;
                try
                {
                    // First read audio file and downsample it to mono 5512hz
                    samples = audioEngine.ReadMonoFromFile(filename, spectrogramConfig.SampleRate, 0, -1);
                }
                catch
                {
                    return(null);
                }

                // No slice the audio is chunks seperated by 11,6 ms (5512hz 11,6ms = 64 samples!)
                // An with length of 371ms (5512kHz 371ms = 2048 samples [rounded])
                fingerprint = audioEngine.CreateFingerprint(samples, spectrogramConfig);
                if (fingerprint != null)
                {
                    fingerprint.Reference = key;
                }
            }
            finally
            {
                if (audioEngine != null)
                {
                    audioEngine.Close();
                    audioEngine = null;
                }
            }

            return(fingerprint);
        }
示例#44
0
        internal pTab(string name, object tag, Vector2 position, float depth, bool flip, bool skinnable, Transformation hoverEffect, float textSize = 1)
        {
            tabBackground = new pSprite(skinnable ? TextureManager.Load(@"selection-tab") : TextureManager.Load(@"selection-tab", SkinSource.Osu), Fields.TopLeft,
                                        Origins.TopLeft,
                                        Clocks.Game,
                                        position, depth, true, hoverEffect.StartColour);
            if (flip)
            {
                tabBackground.FlipVertical = true;
            }
            tabBackground.HoverEffect    = hoverEffect;
            tabBackground.OnHover       += delegate { AudioEngine.Click(null, @"click-short"); };
            tabBackground.OriginPosition = new Vector2(70, 12);
            tabBackground.Tag            = this;
            Tag = tag ?? this;

            int lengthLimit = (int)(13 / textSize);

            if (!string.IsNullOrEmpty(name))
            {
                name = name.Length > lengthLimit?name.Remove(lengthLimit) + ".." : name;

                tabBackground.HandleInput = true;
                tabBackground.OnClick    += tab_OnClick;
            }
            else //Dud
            {
                tabBackground.InitialColour = new Color(160, 8, 42);
            }

            tabText =
                new pText(name, 12 * textSize, position, new Vector2(82, 12) * textSize, depth + 0.0001F, true, Color.White, false);
            tabText.TextBold      = true;
            tabText.TextShadow    = true;
            tabText.Origin        = Origins.Centre;
            tabText.TextAlignment = TextAlignment.Centre;

            SpriteCollection.Add(tabBackground);
            SpriteCollection.Add(tabText);
        }
示例#45
0
        public void TestLoad()
        {
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 1. Check that SoundMusic.Load throws "ArgumentNullException" when either 'engine' or 'filename' param is null
            // 1.1 Null engine
            Assert.Throws<ArgumentNullException>(() => SoundMusic.Load(null, new MemoryStream()), "SoundMusic.Load did not throw 'ArgumentNullException' when called with a null engine.");
            // 1.2 Null stream
            Assert.Throws<ArgumentNullException>(() => SoundMusic.Load(defaultEngine, null), "SoundMusic.Load did not throw 'ArgumentNullException' when called with a null stream.");

            ///////////////////////////////////////////////////////////////////////////////////////////////////////
            // 2. Check that the load function throws "ObjectDisposedException" when the audio engine is disposed.
            var disposedEngine = new AudioEngine();
            disposedEngine.Dispose();
            Assert.Throws<ObjectDisposedException>(() => SoundMusic.Load(disposedEngine, OpenDataBaseStream("EffectToneA")), "SoundMusic.Load did not throw 'ObjectDisposedException' when called with a displosed audio engine.");
            
            ///////////////////////////
            // 4. Load a valid wav file
            Assert.DoesNotThrow(() => SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")), "SoundMusic.Load have thrown an exception when called with an valid wav file.");

            ///////////////////////////
            // 5. Load a valid mp3 file
            Assert.DoesNotThrow(() => SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")), "SoundMusic.Load have thrown an exception when called with an valid wav file.");
        }
    void Start()
    {
        TennisStateRenderer renderer = new TennisStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, "tennis", Settings.menu_sounds, Settings.game_sounds);

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(movingCamera);
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Light_Default", new Vector3(0, 10, 0), false));
        environment.Add(new CanvasObject("Prefabs/Tennis/Logos", true, new Vector3(10000, 0, 0), false));
        int i = 0;
        environment.Add(new TennisMenuItem("Prefabs/Tennis/ButtonSelected", Settings.default_soundset, "default", "default_", null, new Vector3(0, 0, -offset_y), false, true));
        foreach (string s in auEngine.getSettingsAudioForMenu()) {
            if (s == "default") {
                continue;
            }
            environment.Add(new TennisMenuItem("Prefabs/Tennis/ButtonDefault", s, s, s + "_", null, new Vector3(0, 0, i++ * offset_y), false, false));
        }

        TennisRuleset rules = new TennisRuleset();
        rules.Add(new TennisRule("initialization", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            AudioClip audioClip;
            audioClip = auEngine.getSoundForMenu("voice_selection");
            state.timestamp = 0;
            TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
            state.environment.Add(tso);
            state.stoppableSounds.Add(tso);
            Settings.previousMenu = "mainMenu";
            return false;
        }));

        rules.Add(new TennisRule("action", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            if (eve.payload.Equals("enter")) {
                foreach (WorldObject obj in state.environment) {
                    if (obj is TennisMenuItem) {
                        TennisMenuItem temp = obj as TennisMenuItem;
                        if (temp.selected) {
                            Settings.menu_sounds = temp.target;
                            Settings.game_sounds = temp.target;
                        }
                    }
                }
                Application.LoadLevel("mainMenu");
            }
            return true;
        }));

        rules.Add(new TennisRule("move", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            state.timestamp++;
            foreach (TennisSoundObject tennisSo in state.stoppableSounds) {
                state.environment.Remove(tennisSo);
            }
            state.stoppableSounds.Clear();
            TennisMenuItem previous = null;
            bool change = false;
            AudioClip audioClip;
            TennisSoundObject tso;
            foreach (WorldObject obj in state.environment) {
                if (obj is TennisMenuItem) {
                    TennisMenuItem temp = obj as TennisMenuItem;
                    if (temp.selected) {
                        if (eve.payload == "_up" || eve.payload == "left") {
                            if (previous == null) {
                                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.up);
                                tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
                                state.environment.Add(tso);
                                state.stoppableSounds.Add(tso);
                                break;
                            }
                            temp.selected = false;
                            temp.prefab = temp.prefab.Replace("Selected", "Default");
                            previous.selected = true;
                            previous.prefab = previous.prefab.Replace("Default", "Selected");
                            tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForPlayer(previous.audioMessageCode + Random.Range(1, 5)), Vector3.zero);
                            state.environment.Add(tso);
                            state.stoppableSounds.Add(tso);
                            break;
                        } else {
                            change = true;
                        }
                    } else if (change) {
                        temp.selected = true;
                        temp.prefab = temp.prefab.Replace("Default", "Selected");
                        previous.prefab = previous.prefab.Replace("Selected", "Default");
                        previous.selected = false;
                        change = false;
                        tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForPlayer(temp.audioMessageCode + Random.Range(1, 5)), Vector3.zero);
                        state.environment.Add(tso);
                        state.stoppableSounds.Add(tso);
                        break;
                    }
                    previous = temp;
                }
            }
            if (change) {
                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.down);
                tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
                state.environment.Add(tso);
                state.stoppableSounds.Add(tso);
            }
            foreach (WorldObject obj in state.environment) {
                if (obj is TennisMenuItem) {
                    TennisMenuItem temp = obj as TennisMenuItem;
                    if (temp.selected) {
                        movingCamera.position = new Vector3(0, 10, Mathf.Clamp(temp.position.z, 6 * offset_y, 0));
                        break;
                    }
                }
            }
            return true;
        }));

        gameObject.AddComponent<TennisMenuEngine>();
        gameObject.AddComponent<TennisMenuUserInterface>();
        gameObject.GetComponent<TennisMenuEngine>().initialize(rules, environment, renderer);
        gameObject.GetComponent<TennisMenuUserInterface>().initialize(gameObject.GetComponent<TennisMenuEngine>());
        gameObject.GetComponent<TennisMenuEngine>().postEvent(new GameEvent("", "initialization", "unity"));
    }
示例#47
0
        public void TestResumeAudio()
        {
            var engine = new AudioEngine();

            // create a sound effect instance
            SoundEffect soundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));
            
            // check that resume do not play stopped instances
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that user paused music does not resume
            wave1Instance.Play();
            wave1Instance.Pause();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that sounds paused by PauseAudio are correctly restarted
            wave1Instance.Play();
            music.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Playing, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 3000);// listen that the sound comes out
            music.Stop();
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 100);// stop the music

            // check that a sound stopped during the pause does not play during the resume
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Stop();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a sound played during the pause do not play during the resume
            engine.PauseAudio();
            wave1Instance.Play();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (1)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // wait that the sound is finished
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (2)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            wave1Instance.Pause();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a several calls to pause/play do not have side effects
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // listen that the sound comes out

            // check that the sound is not played if disposed
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Dispose();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out
            
            music.Dispose();
            soundEffect.Dispose();
        }
示例#48
0
        public void TestPauseAudio()
        {
            var engine = new AudioEngine();
            
            // create a sound effect instance
            SoundEffect soundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));

            // check state
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Paused, engine.State);

            // check that existing instance can not be played
            wave1Instance.Play();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            music.Play();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // create a new sound effect
            SoundEffect soundEffectStereo;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffectStereo = SoundEffect.Load(engine, wavStream);

            // check that a new instance can not be played
            soundEffectStereo.Play();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a stopped sound stay stopped
            engine.ResumeAudio();
            soundEffectStereo.Stop();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that a paused sound stay paused
            engine.ResumeAudio();
            soundEffectStereo.Play();
            soundEffectStereo.Pause();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);

            // check that a playing sound is paused
            engine.ResumeAudio();
            wave1Instance.Play();
            soundEffectStereo.Play();
            music.Play();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // check that stopping a sound while paused is possible
            engine.PauseAudio();
            soundEffectStereo.Stop();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that disposing a sound while paused is possible
            engine.PauseAudio();
            music.Dispose();
            Assert.IsTrue(music.IsDisposed);

            soundEffect.Dispose();
            soundEffectStereo.Dispose();
        }
示例#49
0
        public void TestState()
        {
            // test initial state
            var engine = new AudioEngine();
            Assert.AreEqual(AudioEngineState.Running, engine.State);

            // test state after pause
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Paused, engine.State);

            // test state after resume
            engine.ResumeAudio();
            Assert.AreEqual(AudioEngineState.Running, engine.State);

            // test state after dispose
            engine.Dispose();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);

            // test that state remains dispose
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);
            engine.ResumeAudio();
            Assert.AreEqual(AudioEngineState.Disposed, engine.State);
        }
 public SoundBank(AudioEngine audioEngine, string filename)
 {
 }
示例#51
0
 public WaveBank(AudioEngine audioEngine, string streamingWaveBankFilename, int offset, short packetsize) { }
	void Start () {
		CurveStateRenderer renderer = new CurveStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, Settings.game_name, Settings.menu_sounds, Settings.game_sounds);

        List<Actor> actors = new List<Actor>();
        actors.Add(new CurveActor("pointer", "Prefabs/Curve/Ball", new Vector3(initial_x, initial_y, 90f), false, null));

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(new CurveStaticObject("Prefabs/Curve/Ball", Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/MainCamera", Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/Light", Vector3.zero, false));
        environment.Add(new CanvasObject("Prefabs/Curve/LeapLogo", true, Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/Divider", new Vector3(0, 0, 100f), false));
		
		List<Player> players = new List<Player>();
		players.Add(new Player("player0", "player0"));

        CurveRuleset rules = new CurveRuleset();
		rules.Add(new CurveRule("initialization", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
			AudioClip auClip = auEngine.getSoundForMenu("tutorial_1");
			CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", auClip);
			state.environment.Add(tso);
			state.blockingSound = tso;
            state.timestamp = 11;
            for (int j = 0; j < 14; j++) {
                state.expectedValues[j] = 6;
            }
			return false;
		}));

        rules.Add(new CurveRule("frame", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.replaying || state.repeating) {
                if (state.delay <= 0) {
                    state.delay = 0.6f;
                    if (state.replaying) {
                        float x = initial_rx + state.index * offset_x;
                        float y = initial_y + state.expectedValues[state.index] * offset_y;
                        engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("note", new Vector3(state.index, state.expectedValues[state.index], 0)), new Vector3(x, y, 90)));
                    } else {
                        if (state.values[state.index] != -1) {
                            float x = initial_x + state.index * offset_x;
                            float y = initial_y + state.values[state.index] * offset_y;
                            engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("note", new Vector3(state.index, state.values[state.index], 0)), new Vector3(x, y, 90)));
                        } else {
                            engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("air")));
                        }
                    }
                    state.index++;
                    if (state.index == max) {
                        if ((state.timestamp == 17 && state.replaying)
                            || (state.timestamp == 19 && state.replaying)
                            || (state.timestamp == 20 && state.repeating)
                            || (state.timestamp == 22 && state.replaying)
                            || (state.timestamp == 23 && state.replaying)) {
                            state.timestamp += 41;
                            if (state.timestamp == 60) {
                                state.values[0] = 12;
                            }
                        }
                        state.index = 0;
                        state.repeating = false;
                        state.replaying = false;
                        state.delay = 0;
                    }
                } else {
                    state.delay -= Time.deltaTime;
                }
            }
            return false;
        }));

        rules.Add(new CurveRule("action", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (eve.payload.Equals("escape")) {
                Application.LoadLevel(Settings.previousMenu);
                return false;
            }
            return true;
        }));

        rules.Add(new CurveRule("soundOver", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            int id = int.Parse(eve.payload);
            if (state.blockingSound != null && id == state.blockingSound.clip.GetInstanceID()) {
                state.environment.Remove(state.blockingSound);
                state.blockingSound = null;
                CurveSoundObject tso;
                switch (state.timestamp) {
                    case 11:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(7, 0, 0)));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 52;
                        return false;
                    case 12:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(7, 1, 0)));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 53;
                        return false;
                    case 13:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(7, 13, 0)));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 54;
                        return false;
                    case 14:
                        state.replaying = true;
                        state.timestamp = 55;
                        return false;
                    case 115:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForMenu("tutorial_5b"));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 15;
                        return false;
                    case 116:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForMenu("tutorial_6"));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 57;
                        max = 3;
                        return false;
                    case 118:
                        tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForMenu("tutorial_8b"));
                        state.blockingSound = tso;
                        state.environment.Add(tso);
                        state.timestamp = 18;
                        return false;
                    case 22:
                        max = 14;
                        for (int i = 0; i < 14; i++) {
                            state.expectedValues[i] = i / 3;
                        }
                        state.replaying = true;
                        return false;
                    case 23:
                        state.replaying = true;
                        for (int i = 0; i < 14; i++) {
                            state.expectedValues[i] = 13 - i;
                        }
                        return false;
                    case 24:
                        state.timestamp = 10;
                        return false;
                    default:
                        if (state.timestamp > 50) {
                            state.timestamp = state.timestamp - 50;
                            tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForMenu("tutorial_" + state.timestamp));
                            state.blockingSound = tso;
                            state.environment.Add(tso);
                            state.timestamp += 10;
                        }
                        return false;
                }
            } else {
                WorldObject toRemove = null;
                foreach (WorldObject go in state.environment) {
                    if (go is CurveSoundObject && (go as CurveSoundObject).clip.GetInstanceID() == id) {
                        toRemove = go;
                        break;
                    }
                }
                if (toRemove != null) {
                    state.environment.Remove(toRemove);
                }
                if (state.timestamp == 55
                    || state.timestamp == 58
                    || state.timestamp == 60
                    || state.timestamp == 61
                    || state.timestamp == 63
                    || state.timestamp == 64
                    || state.timestamp == 65) {
                    state.timestamp -= 50;
                    CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForMenu("tutorial_" + state.timestamp));
                    state.blockingSound = tso;
                    state.environment.Add(tso);
                    state.timestamp += 10;
                }
            }
            return false;
        }));

        rules.Add(new CurveRule("ALL", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            return !eve.initiator.StartsWith("player") || (eve.initiator.Equals("player" + state.curPlayer) && state.blockingSound == null);
        }));

        rules.Add(new CurveRule("action", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.repeating || state.replaying || state.blockingSound != null) {
                return true;
            }
            switch (eve.payload) {
                case "any":
                    if (state.timestamp == 10) {
                        (state.result as CurveGameResult).status = CurveGameResult.GameStatus.Over;
                        return false;
                    }
                    return true;
                case "replay":
                    state.replaying = true;
                    state.index = 0;
                    return false;
                case "repeat":
                    state.repeating = true;
                    state.index = 0;
                    return false;
                case "enter":
                    foreach (Actor actor in state.actors) {
                        Vector3 position = actor.position - new Vector3(initial_x, initial_y, 0f);
                        int x = (int)(position.x / offset_x);
                        int y = (int)(position.y / offset_y);
                        if (state.values[x] == state.expectedValues[x]) {
                            if (state.timestamp == 18) {
                                CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("boundary", new Vector3(0, 1, 0)));
                                state.environment.Add(tso);
                                state.blockingSound = tso;
                                state.timestamp = 118;
                            } else {
                                engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("boundary", new Vector3(0, 1, 0)), Vector3.zero));
                            }
                        } else {
                            if (state.timestamp == 15) {
                                CurveSoundObject tso;
                                state.values[x] = y;
                                if (state.values[x] == state.expectedValues[x]) {
                                    tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("correct"));
                                    state.environment.Add(tso);
                                    state.blockingSound = tso;
                                    state.timestamp = 116;
                                } else {
                                    tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(x, y, 0)));
                                    state.environment.Add(tso);
                                    state.blockingSound = tso;
                                    state.timestamp = 115;
                                }
                            } else {
                                state.values[x] = y;
                                if (state.values[x] == state.expectedValues[x]) {
                                    if (state.timestamp == 18 && state.values[1] == state.expectedValues[1] && state.values[2] == state.expectedValues[2]) {
                                        CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("correct"));
                                        state.environment.Add(tso);
                                        state.blockingSound = tso;
                                        state.timestamp = 59;
                                    } else if (state.timestamp == 21 && state.values[0] == state.expectedValues[0]) {
                                        CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("correct"));
                                        state.environment.Add(tso);
                                        state.blockingSound = tso;
                                        state.timestamp = 62;
                                    } else {
                                        engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("correct")));
                                    }
                                } else {
                                    engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(x, y, 0)), Vector3.zero));
                                }
                            }
                        }
                    }
                    return false;
            }
            return true;
        }));

        rules.Add(new CurveRule("move", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.repeating || state.replaying) {
                return false;
            }
            int dx = 0;
            int dy = 0;
            switch (eve.payload) {
                case "left":
                    dx = -1;
                    break;
                case "right":
                    dx = 1;
                    break;
                case "up":
                    dy = 1;
                    break;
                case "down":
                    dy = -1;
                    break;
                default:
                    return false;
            }
            foreach (Actor actor in state.actors) {
                Vector3 position = actor.position - new Vector3(initial_x, initial_y, 0f);
                int x = (int)(position.x / offset_x) + dx;
                int y = (int)(position.y / offset_y) + dy;
                if (x <= -1 || x >= max || y <= -1 || y >= 14) {
                    return false;
                }
                actor.position = new Vector3(offset_x * x + initial_x, offset_y * y + initial_y, actor.position.z);
                engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(x, y, 0))));
            }
            return false;
        }));
		
		gameObject.AddComponent<CurveGameEngine>();
		gameObject.AddComponent<CurveUserInterface>();
		gameObject.GetComponent<CurveGameEngine>().initialize(rules, actors, environment, players, renderer);
		gameObject.GetComponent<CurveUserInterface>().initialize(gameObject.GetComponent<CurveGameEngine>());
		gameObject.GetComponent<CurveGameEngine>().postEvent(new GameEvent("", "initialization", "unity"));
	}
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = AudioEngineFactory.NewAudioEngine();
        }
    void Start() {
        CurveStateRenderer renderer = new CurveStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, Settings.game_name, Settings.menu_sounds, Settings.game_sounds);

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(movingCamera);
        environment.Add(new CurveStaticObject("Prefabs/Curve/Light_Default", new Vector3(0, 10, 0), false));
        environment.Add(new CanvasObject("Prefabs/Curve/Logos", true, new Vector3(10000, 0, 0), false));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonSelected", "5 λεπτά", "newGame", "5", auEngine.getSoundForMenu("new_game_remaining_time_5"), new Vector3(0, 0, -offset_y), false, true));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonDefault", "4 λεπτά", "newGame", "4", auEngine.getSoundForMenu("new_game_remaining_time_4"), new Vector3(0, 0, 0), false, false));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonDefault", "3 λεπτά", "newGame", "3", auEngine.getSoundForMenu("new_game_remaining_time_3"), new Vector3(0, 0, offset_y), false));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonDefault", "2 λεπτά", "newGame", "2", auEngine.getSoundForMenu("new_game_remaining_time_2"), new Vector3(0, 0, 2 * offset_y), false));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonDefault", "1 λεπτό", "newGame", "1", auEngine.getSoundForMenu("new_game_remaining_time_1"), new Vector3(0, 0, 3 * offset_y), false));
        environment.Add(new CurveMenuItem("Prefabs/Curve/ButtonDefault", "Πίσω", "curveSelectionMenu", "back", auEngine.getSoundForMenu("back"), new Vector3(0, 0, 4 * offset_y), false));

        CurveRuleset rules = new CurveRuleset();
        rules.Add(new CurveRule("initialization", (CurveMenuState state, GameEvent eve, CurveMenuEngine engine) => {
            AudioClip audioClip;
            state.timestamp = 0;
            audioClip = auEngine.getSoundForMenu("new_game_select");
            CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", audioClip, Vector3.zero);
            state.environment.Add(tso);
            state.stoppableSounds.Add(tso);
            Settings.previousMenu = "curveSelectionMenu";
            return false;
        }));

        rules.Add(new CurveRule("soundOver", (CurveMenuState state, GameEvent eve, CurveMenuEngine engine) => {
            if (state.timestamp == 0) {
                AudioClip audioClip = auEngine.getSoundForMenu("new_game_remaining_time_5");
                CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", audioClip, Vector3.zero);
                state.environment.Add(tso);
                state.stoppableSounds.Add(tso);
                state.timestamp = 1;
            }
            return false;
        }));

        rules.Add(new CurveRule("action", (CurveMenuState state, GameEvent eve, CurveMenuEngine engine) => {
            if (eve.payload.Equals("escape")) {
                Application.LoadLevel("curveSelectionMenu");
                return false;
            }
            return true;
        }));

        rules.Add(new CurveRule("action", (CurveMenuState state, GameEvent eve, CurveMenuEngine engine) => {
            if (eve.payload.Equals("enter")) {
                foreach (WorldObject obj in state.environment) {
                    if (obj is CurveMenuItem) {
                        if ((obj as CurveMenuItem).selected) {
                            int mins;
                            if (Int32.TryParse((obj as CurveMenuItem).audioMessageCode, out mins)) {
                                Settings.time = mins;
                            }
                            Application.LoadLevel((obj as CurveMenuItem).target);
                            return false;
                        }
                    }
                }
            }
            return true;
        }));

        rules.Add(new CurveRule("move", (CurveMenuState state, GameEvent eve, CurveMenuEngine engine) => {
            state.timestamp++;
            foreach (CurveSoundObject Curveso in state.stoppableSounds) {
                state.environment.Remove(Curveso);
            }
            state.stoppableSounds.Clear();
            CurveMenuItem previous = null;
            bool change = false;
            AudioClip audioClip;
            CurveSoundObject tso;
            foreach (WorldObject obj in state.environment) {
                if (obj is CurveMenuItem) {
                    CurveMenuItem temp = obj as CurveMenuItem;
                    if (temp.selected) {
                        if (eve.payload == "_up" || eve.payload == "left") {
                            if (previous == null) {
                                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.up);
                                tso = new CurveSoundObject("Prefabs/Curve/AudioSource", audioClip, Vector3.zero);
                                state.environment.Add(tso);
                                state.stoppableSounds.Add(tso);
                                break;
                            }
                            temp.selected = false;
                            temp.prefab = temp.prefab.Replace("Selected", "Default");
                            previous.selected = true;
                            previous.prefab = previous.prefab.Replace("Default", "Selected");
                            tso = new CurveSoundObject("Prefabs/Curve/AudioSource", previous.audioMessage, Vector3.zero);
                            state.environment.Add(tso);
                            state.stoppableSounds.Add(tso);
                            break;
                        } else {
                            change = true;
                        }
                    } else if (change) {
                        temp.selected = true;
                        temp.prefab = temp.prefab.Replace("Default", "Selected");
                        previous.prefab = previous.prefab.Replace("Selected", "Default");
                        previous.selected = false;
                        change = false;
                        tso = new CurveSoundObject("Prefabs/Curve/AudioSource", temp.audioMessage, Vector3.zero);
                        state.environment.Add(tso);
                        state.stoppableSounds.Add(tso);
                        break;
                    }
                    previous = temp;
                }
            }
            if (change) {
                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.down);
                tso = new CurveSoundObject("Prefabs/Curve/AudioSource", audioClip, Vector3.zero);
                state.environment.Add(tso);
                state.stoppableSounds.Add(tso);
            }
            foreach (WorldObject obj in state.environment) {
                if (obj is CurveMenuItem) {
                    CurveMenuItem temp = obj as CurveMenuItem;
                    if (temp.selected) {
                        movingCamera.position = new Vector3(0, 10, Mathf.Clamp(temp.position.z, 6 * offset_y, 0));
                        break;
                    }
                }
            }
            return true;
        }));

        gameObject.AddComponent<CurveMenuEngine>();
        gameObject.AddComponent<CurveMenuUserInterface>();
        gameObject.GetComponent<CurveMenuEngine>().initialize(rules, environment, renderer);
        gameObject.GetComponent<CurveMenuUserInterface>().initialize(gameObject.GetComponent<CurveMenuEngine>());
        gameObject.GetComponent<CurveMenuEngine>().postEvent(new GameEvent("", "initialization", "unity"));
    }
示例#55
0
 public WaveBank(AudioEngine audioEngine, string nonStreamingWaveBankFilename) { }
    void Start()
    {
        TennisStateRenderer renderer = new TennisStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, "tennis", Settings.menu_sounds, Settings.game_sounds);

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Camera_Default", new Vector3(0, 10, 0), false));
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Light_Default", new Vector3(0, 10, 0), false));
        environment.Add(new CanvasObject("Prefabs/Tennis/Logos", true, new Vector3(10000, 0, 0), false));
        environment.Add(new TennisMenuItem("Prefabs/Tennis/ButtonSelected", "Οδηγίες", "tutorial", "tutorials", auEngine.getSoundForMenu("tutorials"), new Vector3(0, 0, -offset_y), false, true));
        environment.Add(new TennisMenuItem("Prefabs/Tennis/ButtonDefault", "Νέο Παιχνίδι", "newGame", "new_game", auEngine.getSoundForMenu("new_game"), new Vector3(0, 0, 0), false));
        environment.Add(new TennisMenuItem("Prefabs/Tennis/ButtonDefault", "Έξοδος", "exitScene", "exit", auEngine.getSoundForMenu("exit"), new Vector3(0, 0, offset_y), false));

        TennisRuleset rules = new TennisRuleset();
        rules.Add(new TennisRule("initialization", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            AudioClip audioClip;
            if (Settings.just_started) {
                Settings.just_started = false;
                audioClip = auEngine.getSoundForMenu("game_intro");
                state.timestamp = 0;
            } else {
                audioClip = auEngine.getSoundForMenu("tutorials");
                state.timestamp = 1;
            }
            TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
            state.environment.Add(tso);
            state.stoppableSounds.Add(tso);
            Settings.previousMenu = "mainMenu";
            return false;
        }));

        rules.Add(new TennisRule("soundSettings", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            Settings.menu_sounds = eve.payload;
            auEngine = new AudioEngine(0, "Tic-Tac-Toe", Settings.menu_sounds, Settings.game_sounds);
            foreach (WorldObject wo in state.environment) {
                if (wo is TennisMenuItem) {
                    (wo as TennisMenuItem).audioMessage = auEngine.getSoundForMenu((wo as TennisMenuItem).audioMessageCode);
                }
            }
            return false;
        }));

        rules.Add(new TennisRule("soundOver", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            if (state.timestamp == 0) {
                AudioClip audioClip = auEngine.getSoundForMenu("tutorials");
                TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
                state.environment.Add(tso);
                state.stoppableSounds.Add(tso);
                state.timestamp = 1;
            }
            return false;
        }));

        rules.Add(new TennisRule("action", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            if (eve.payload.Equals("escape")) {
                Application.LoadLevel("mainMenu");
                return false;
            }
            return true;
        }));

        rules.Add(new TennisRule("action", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            if (eve.payload.Equals("enter")) {
                foreach (WorldObject obj in state.environment) {
                    if (obj is TennisMenuItem) {
                        if ((obj as TennisMenuItem).selected) {
                            Application.LoadLevel((obj as TennisMenuItem).target);
                            return false;
                        }
                    }
                }
            }
            return true;
        }));

        rules.Add(new TennisRule("move", (TennisMenuState state, GameEvent eve, TennisMenuEngine engine) => {
            state.timestamp++;
            foreach (TennisSoundObject Tennisso in state.stoppableSounds) {
                state.environment.Remove(Tennisso);
            }
            state.stoppableSounds.Clear();
            TennisMenuItem previous = null;
            bool change = false;
            AudioClip audioClip;
            TennisSoundObject tso;
            foreach (WorldObject obj in state.environment) {
                if (obj is TennisMenuItem) {
                    TennisMenuItem temp = obj as TennisMenuItem;
                    if (temp.selected) {
                        if (eve.payload == "_up" || eve.payload == "left") {
                            if (previous == null) {
                                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.up);
                                tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
                                state.environment.Add(tso);
                                state.stoppableSounds.Add(tso);
                                break;
                            }
                            temp.selected = false;
                            temp.prefab = temp.prefab.Replace("Selected", "Default");
                            previous.selected = true;
                            previous.prefab = previous.prefab.Replace("Default", "Selected");
                            tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", previous.audioMessage, Vector3.zero);
                            state.environment.Add(tso);
                            state.stoppableSounds.Add(tso);
                            break;
                        } else {
                            change = true;
                        }
                    } else if (change) {
                        temp.selected = true;
                        temp.prefab = temp.prefab.Replace("Default", "Selected");
                        previous.prefab = previous.prefab.Replace("Selected", "Default");
                        previous.selected = false;
                        change = false;
                        tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", temp.audioMessage, Vector3.zero);
                        state.environment.Add(tso);
                        state.stoppableSounds.Add(tso);
                        break;
                    }
                    previous = temp;
                }
            }
            if (change) {
                audioClip = auEngine.getSoundForPlayer("boundary", Vector3.down);
                tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", audioClip, Vector3.zero);
                state.environment.Add(tso);
                state.stoppableSounds.Add(tso);
            }
            return true;
        }));

        gameObject.AddComponent<TennisMenuEngine>();
        gameObject.AddComponent<TennisMenuUserInterface>();
        gameObject.GetComponent<TennisMenuEngine>().initialize(rules, environment, renderer);
        gameObject.GetComponent<TennisMenuUserInterface>().initialize(gameObject.GetComponent<TennisMenuEngine>());
        gameObject.GetComponent<TennisMenuEngine>().postEvent(new GameEvent("", "initialization", "unity"));
    }
示例#57
0
    /// <summary>
    /// Allows the game component to perform any initialization it needs to before starting
    /// to run.  This is where it can query for any required services and load content.
    /// </summary>
    public override void Initialize()
    {
        m_audioEngine = new AudioEngine("Content/" + m_filename + ".xgs");

        base.Initialize();
    }
示例#58
0
        public void TestGetLeastSignificativeSoundEffect()
        {
            var engine = new AudioEngine();

            //////////////////////////////////////////
            // 1. Test that it returns null by default
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            // create a sound effect
            SoundEffect soundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);

            /////////////////////////////////////////////////////////////////////
            // 2. Test that is returns null when there is no playing sound effect
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            /////////////////////////////////////////////////////////////////////////////////
            // 3. Test that is returns null when there is no not looped sound effect playing
            soundEffect.IsLooped = true;
            soundEffect.Play();
            Assert.AreEqual(null, engine.GetLeastSignificativeSoundEffect());

            ////////////////////////////////////////////////////////////////////////////
            // 4. Test that the sound effect is returned if not playing and not looped
            soundEffect.Stop();
            soundEffect.IsLooped = false;
            soundEffect.Play();
            Assert.AreEqual(soundEffect, engine.GetLeastSignificativeSoundEffect());

            // create another longer sound effect
            SoundEffect longerSoundEffect;
            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                longerSoundEffect = SoundEffect.Load(engine, wavStream);

            ///////////////////////////////////////////////////////////////////////
            // 5. Test that the longest sound is returned if it is the only playing
            soundEffect.Stop();
            longerSoundEffect.Play();
            Assert.AreEqual(longerSoundEffect, engine.GetLeastSignificativeSoundEffect());

            //////////////////////////////////////////////////////////////
            // 6. Test that the shortest sound is returned if both playing
            longerSoundEffect.Play();
            soundEffect.Play();
            Assert.AreEqual(soundEffect, engine.GetLeastSignificativeSoundEffect());

            //////////////////////////////////////////////////////////////////////
            // 7. Test that the longest sound is returned if the other is looped
            soundEffect.Stop();
            soundEffect.IsLooped = true;
            soundEffect.Play();
            longerSoundEffect.Play();
            Assert.AreEqual(longerSoundEffect, engine.GetLeastSignificativeSoundEffect());

            engine.Dispose();
        }
    void Start()
    {
        TennisStateRenderer renderer = new TennisStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, "tennis", Settings.menu_sounds, Settings.game_sounds);

        List<Actor> actors = new List<Actor>();

        List<WorldObject> environment = new List<WorldObject>();
        ball = new TennisMovingObject("Prefabs/Tennis/Ball", new Vector3(0, -1, Settings.size_mod_z * 5.9f), true);
        environment.Add(ball);
        environment.Add(new TennisStaticObject("Prefabs/Tennis/MainCamera", new Vector3(0, 1, (Settings.size_mod_z * -6f) - 5.5f), false));
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Light", new Vector3(0, 0, 0), false));
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Field", new Vector3(0, -7, 0), false));
        environment.Add(new TennisStaticObject("Prefabs/Tennis/Wall", new Vector3(0, -5, Settings.size_mod_z * 6), false));
        environment.Add(new CanvasObject("Prefabs/Tennis/LeapLogo", true, new Vector3(0, 0, 0), false));

        List<Player> players = new List<Player>();
        players.Add(new Player("player0", "player0"));

        TennisRuleset rules = new TennisRuleset();
        rules.Add(new TennisRule("initialization", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            AudioClip auClip = auEngine.getSoundForMenu("tutorial_intro");
            TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auClip);
            state.environment.Add(tso);
            state.blockingSound = tso;
            state.speed = 0;
            state.timestamp = -1;
            state.target = 0;
            return false;
        }));

        rules.Add(new TennisRule("action", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            if (eve.payload.Equals("any")) {
                switch(state.timestamp) {
                case 0:
                    AudioClip auClip = auEngine.getSoundForMenu("tutorial_01");
                    TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auClip);
                    state.environment.Add(tso);
                    state.blockingSound = tso;
                    state.timestamp++;
                    return false;
                case 10:
                    (state.result as TennisGameResult).status = TennisGameResult.GameStatus.Over;
                    return false;
                default:
                    return false;
                }
            }
            return true;
        }));

        rules.Add(new TennisRule("action", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            if (eve.payload.Equals("escape")) {
                Application.LoadLevel("mainMenu");
                return false;
            }
            return true;
        }));

        rules.Add(new TennisRule("soundOver", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            int id = int.Parse(eve.payload);
            if (state.blockingSound != null && id == state.blockingSound.clip.GetInstanceID()) {
                state.environment.Remove(state.blockingSound);
                state.blockingSound = null;
                switch(state.timestamp) {
                case -1:
                    state.timestamp++;
                    break;
                case 44:
                    break;
                case 55:
                    break;
                case 66:
                    break;
                case 77:
                    break;
                case 78:
                    break;
                case 88:
                    break;
                case 89:
                    break;
                case 76:
                    state.timestamp++;
                    break;
                case 6:
                    state.blockingSound = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForMenu("tutorial_0" + state.timestamp));
                    state.environment.Add(state.blockingSound);
                    state.timestamp = 76;
                    break;
                case 7:
                    TennisSoundObject stso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForMenu("tutorial_outro"));
                    state.environment.Add(stso);
                    state.blockingSound = stso;
                    state.timestamp = 9;
                    break;
                case 9:
                    state.timestamp = 10;
                    break;
                default:
                    state.timestamp++;
                    state.speed = 1f;
                    break;
                }
            } else {
                WorldObject toRemove = null;
                foreach (WorldObject go in state.environment) {
                    if (go is TennisSoundObject && (go as TennisSoundObject).clip.GetInstanceID() == id) {
                        toRemove = go;
                        break;
                    }
                }
                if (toRemove != null) {
                    state.environment.Remove(toRemove);
                }
            }
            return false;
        }));

        rules.Add(new TennisRule("action", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            if (eve.payload.Equals("pause") && state.blockingSound != null) {
                state.blockingSound.hidden = true;
                return false;
            }
            return true;
        }));

        rules.Add(new TennisRule("action", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            if (eve.payload.Equals("enter") && state.timestamp > 10 && state.blockingSound == null && state.timestamp < 66) {
                state.timestamp /= 11;
                TennisSoundObject ltso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForMenu("tutorial_0" + state.timestamp));
                state.environment.Add(ltso);
                state.blockingSound = ltso;
                state.target = state.timestamp == 4 ? -1 : 0;
                state.timestamp = (state.timestamp + 1) * 11;
                return false;
            }
            return true;
        }));

        rules.Add(new TennisRule("ALL", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            return !eve.initiator.StartsWith("player") || (eve.initiator.Equals("player" + state.curPlayer) && state.blockingSound == null);
        }));

        rules.Add(new TennisRule("position", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            if (state.timestamp < 67) {
                return false;
            }
            if (state.speed == 0f || !positionalMovement) {
                return false;
            }
            switch (state.timestamp) {
                case 67:
                    if (!eve.payload.Equals("right")) {
                        state.timestamp = 66;
                        actors.Clear();
                        AudioClip auClip = auEngine.getSoundForMenu("tutorial_55");
                        state.blockingSound = new TennisSoundObject("Prefabs/Tennis/AudioSource", auClip);
                        state.environment.Add(state.blockingSound);
                        state.speed = 0;
                    }
                    break;
                case 78:
                    if (!eve.payload.Equals("left")) {
                        state.timestamp = 77;
                        actors.Clear();
                        AudioClip auClip = auEngine.getSoundForMenu("tutorial_66");
                        state.blockingSound = new TennisSoundObject("Prefabs/Tennis/AudioSource", auClip);
                        state.environment.Add(state.blockingSound);
                        state.speed = 0;
                    }
                    break;
                case 68:
                    break;
                case 79:
                    break;
                default:
                    return false;
            }
            int dx = 0;
            switch (eve.payload) {
                case "left":
                    dx = -1;
                    break;
                case "right":
                    dx = 1;
                    break;
            }
            foreach (Actor actor in state.actors) {
                Vector3 newPos = new Vector3(offset_x * dx, actor.position.y, actor.position.z);
                if (actor.position == newPos) {
                    return false;
                }
                actor.position = newPos;
                engine.state.environment.Add(new TennisSoundObject("Prefabs/Tennis/GameAudio", auEngine.getSoundForPlayer("just moved", new Vector3(dx, 0, 0)), actor.position));
            }
            return false;
        }));

        rules.Add(new TennisRule("move", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            switch (state.timestamp) {
            case 44:
                if (eve.payload.Equals("right")) {
                    state.speed = 1f;
                }
                break;
            case 55:
                if (eve.payload.Equals("left")) {
                    state.speed = 1f;
                }
                break;
            case 66:
                actors.Add(new TennisActor("racket", "Prefabs/Tennis/Racket", new Vector3(0, -5, Settings.size_mod_z * - 6), false, null));
                if (eve.payload.Equals("right")) {
                    state.target = 1;
                    state.speed = 1f;
                    state.timestamp = 67;
                }
                break;
            case 77:
                actors.Add(new TennisActor("racket", "Prefabs/Tennis/Racket", new Vector3(0, -5, Settings.size_mod_z * -6), false, null));
                if (eve.payload.Equals("left")) {
                    state.target = -1;
                    state.speed = 1f;
                    state.timestamp = 78;
                }
                break;
            default:
                break;
            }
            return false;
        }));

        rules.Add(new TennisRule("hit", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            switch (eve.payload) {
            case "-1":
                ballTarget = -1;
                break;
            case "0":
                ballTarget = 0;
                break;
            case "1":
                ballTarget = 1;
                break;
            }
            return false;
        }));

        rules.Add(new TennisRule("bounce", (TennisGameState state, GameEvent eve, TennisGameEngine engine) => {
            AudioClip auClip;
            Vector3 position = new Vector3(ballTarget * offset_x, ball.position.y, ball.position.z);
            switch (eve.payload) {
            case "racket":
                auClip = auEngine.getSoundForPlayer("player_racket_hit");
                state.timestamp++;
                break;
            case "wall":
                if (state.timestamp == 68 || state.timestamp == 79) {
                    environment.Remove(ball);
                    ball = new TennisMovingObject("Prefabs/Tennis/Ball", new Vector3(0, -1, Settings.size_mod_z * 5.9f), true);
                    environment.Add(ball);
                    state.speed = 0f;
                    if (state.timestamp == 68) {
                        state.blockingSound = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForPlayer("opponent_racket_hit"));
                    } else {
                        state.blockingSound = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForPlayer("win_" + Random.Range(1, 13)));
                    }
                    environment.Add(state.blockingSound);
                    state.timestamp = (state.timestamp - 2) / 11;
                    return false;
                }
                auClip = auEngine.getSoundForPlayer("opponent_racket_hit");
                break;
            case "floor":
                auClip = auEngine.getSoundForPlayer("floor_hit");
                break;
            case "net":
                auClip = auEngine.getSoundForPlayer("net_pass");
                position.Scale(new Vector3(1f, 1f, 1f));
                break;
            case "boundary":
                environment.Remove(ball);
                ball = new TennisMovingObject("Prefabs/Tennis/Ball", new Vector3(0, -1, Settings.size_mod_z * 5.9f), true);
                environment.Add(ball);
                state.speed = 0f;
                if (state.timestamp < 10) {
                    TennisSoundObject rtso = new TennisSoundObject("Prefabs/Tennis/AudioSource", auEngine.getSoundForMenu("tutorial_0" + state.timestamp));
                    state.environment.Add(rtso);
                    state.blockingSound = rtso;
                    switch(state.timestamp) {
                    case 2:
                        state.target = 0;
                        break;
                    case 3:
                        state.target = 1;
                        state.timestamp = 44;
                        break;
                    case 44:
                        break;
                    case 55:
                        break;
                    case 66:
                        break;
                    default:
                        state.target = -2;
                        break;
                    }
                }
                return false;
            default:
                return false;
            }
            TennisSoundObject tso = new TennisSoundObject("Prefabs/Tennis/GameAudio", auClip, position);
            engine.state.environment.Add(tso);
            return true;
        }));

        gameObject.AddComponent<TennisGameEngine>();
        gameObject.AddComponent<TennisUserInterface>();
        gameObject.GetComponent<TennisGameEngine>().initialize(rules, actors, environment, players, renderer);
        gameObject.GetComponent<TennisUserInterface>().initialize(gameObject.GetComponent<TennisGameEngine>());
        gameObject.GetComponent<TennisGameEngine>().postEvent(new GameEvent("", "initialization", "unity"));
    }
	void Start () {
        CurveStateRenderer renderer = new CurveStateRenderer();
        AudioEngine auEngine = new AudioEngine(0, Settings.game_name, Settings.menu_sounds, Settings.game_sounds);

        List<Actor> actors = new List<Actor>();
        actors.Add(new CurveActor("pointer", "Prefabs/Curve/Ball", new Vector3(initial_x, initial_y, 90f), false, null));

        List<WorldObject> environment = new List<WorldObject>();
        environment.Add(new CurveStaticObject("Prefabs/Curve/Ball", Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/MainCamera",    Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/Light", Vector3.zero, false));
        environment.Add(new CanvasObject("Prefabs/Curve/LeapLogo", true, Vector3.zero, false));
        environment.Add(new CurveStaticObject("Prefabs/Curve/Divider", new Vector3(0, 0, 100f), false));
        TextCanvasObject gui = new TextCanvasObject("Prefabs/Curve/GUI_Element", true, "Time Left: " + Settings.time * 60, new Vector3(0, 0, 0), false);
        environment.Add(gui);

        List<Player> players = new List<Player>();
        players.Add(new Player("player0", "player0"));

        CurveRuleset rules = new CurveRuleset();
        rules.Add(new CurveRule("initialization", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            AudioClip auClip = auEngine.getSoundForMenu("new_game_intro");
            CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", auClip);
            state.environment.Add(tso);
            state.blockingSound = tso;
            state.timestamp = 0;
            state.level = Settings.level;
            state.time_left = Settings.time * 60;
            for (int j = 0; j < 14; j++) {
                switch (state.level) {
                    case 0:
                        state.expectedValues[j] = 6;
                        break;
                    case 1:
                        state.expectedValues[j] = j;
                        break;
                    case 2:
                        state.expectedValues[j] = (int)(13f - j);
                        break;
                    case 3:
                        state.expectedValues[j] = (int)(j * j / 13f);
                        break;
                    case 4:
                        state.expectedValues[j] = (int)(Mathf.Sqrt(14.5f * j));
                        break;
                    case 5:
                        state.expectedValues[j] = (int) Mathf.Round((Mathf.Sin(j * 3.14159f / 4f) + 1f) * 6f);
                        break;
                    case 6:
                        state.expectedValues[j] = (int)(13f / (j + 1));
                        break;
                }
                state.values[j] = -1;
            }
            return false;
        }));

        rules.Add(new CurveRule("frame", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.timestamp == 2 && !state.repeating && !state.replaying) {
                state.time_left -= Time.deltaTime;
                gui.text = "Time Left: " + (int)state.time_left;
                if (state.time_left <= 0) {
                    state.timestamp = 9;
                    AudioClip auClip = auEngine.getSoundForMenu("new_game_loss");
                    CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", auClip);
                    state.environment.Add(tso);
                    state.blockingSound = tso;
                }
            } else if (state.timestamp == 2) {
                if (state.delay <= 0) {
                    state.delay = 0.6f;
                    if (state.replaying) {
                        float x = initial_rx + state.index * offset_x;
                        float y = initial_y + state.expectedValues[state.index] * offset_y;
                        engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("note", new Vector3(state.index, state.expectedValues[state.index], 0)), new Vector3(x, y, 90)));
                    } else {
                        if (state.values[state.index] != -1) {
                            float x = initial_x + state.index * offset_x;
                            float y = initial_y + state.values[state.index] * offset_y;
                            engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("note", new Vector3(state.index, state.values[state.index], 0)), new Vector3(x, y, 90)));
                        } else {
                            engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/VisibleGameAudio", auEngine.getSoundForPlayer("air")));
                        }
                    }
                    state.index++;
                    if (state.index == 14) {
                        state.index = 0;
                        state.repeating = false;
                        state.replaying = false;
                        state.delay = 0;
                    }
                } else {
                    state.delay -= Time.deltaTime;
                }
            }
            return false;
        }));

        rules.Add(new CurveRule("action", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (eve.payload.Equals("escape")) {
                Application.LoadLevel(Settings.previousMenu);
                return false;
            }
            return true;
        }));

        rules.Add(new CurveRule("soundOver", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            int id = int.Parse(eve.payload);
            if (state.blockingSound != null && id == state.blockingSound.clip.GetInstanceID()) {
                state.environment.Remove(state.blockingSound);
                state.blockingSound = null;
                if (state.timestamp == 0) {
                    state.timestamp = 2;
                    state.replaying = true;
                }
                if (state.timestamp == 9) {
                    state.timestamp = 10;
                }
            } else {
                WorldObject toRemove = null;
                foreach (WorldObject go in state.environment) {
                    if (go is CurveSoundObject && (go as CurveSoundObject).clip.GetInstanceID() == id) {
                        toRemove = go;
                        break;
                    }
                }
                if (toRemove != null) {
                    state.environment.Remove(toRemove);
                }
            }
            return false;
        }));

        rules.Add(new CurveRule("ALL", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            return !eve.initiator.StartsWith("player") || (eve.initiator.Equals("player" + state.curPlayer) && state.blockingSound == null);
        }));

        rules.Add(new CurveRule("action", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.repeating || state.replaying || state.blockingSound != null) {
                return true;
            }
            switch (eve.payload) {
                case "any":
                    if (state.timestamp == 10) {
                        (state.result as CurveGameResult).status = CurveGameResult.GameStatus.Over;
                        return false;
                    }
                    return true;
                case "replay":
                    state.replaying = true;
                    state.index = 0;
                    return false;
                case "repeat":
                    state.repeating = true;
                    state.index = 0;
                    return false;
                case "enter":
                    if (state.timestamp == 1 || state.timestamp >= 9) {
                        return false;
                    }
                    foreach (Actor actor in state.actors) {
                        Vector3 position = actor.position - new Vector3(initial_x, initial_y, 0f);
                        int x = (int)(position.x / offset_x);
                        int y = (int)(position.y / offset_y);
                        if (state.values[x] == state.expectedValues[x]) {
                            engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("boundary", new Vector3(0, 1, 0)), Vector3.zero));
                        } else {
                            state.values[x] = y;
                            if (state.values[x] == state.expectedValues[x]) {
                                engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("correct"), Vector3.zero));
                            } else {
                                engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(x, y, 0)), Vector3.zero));
                            }
                        }
                    }
                    int i;
                    for (i = 0; i < 14; i++) {
                        if (state.values[i] != state.expectedValues[i]) {
                            break;
                        }
                    }
                    if (i == 14) {
                        state.timestamp = 9;
                        engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("claps_1"), Vector3.zero));
                        AudioClip auClip = auEngine.getSoundForMenu("new_game_win");
                        CurveSoundObject tso = new CurveSoundObject("Prefabs/Curve/AudioSource", auClip);
                        state.environment.Add(tso);
                        state.blockingSound = tso;
                    }
                    return false;
            }
            return true;
        }));

        rules.Add(new CurveRule("move", (CurveGameState state, GameEvent eve, CurveGameEngine engine) => {
            if (state.repeating || state.replaying) {
                return false;
            }
            int dx = 0;
            int dy = 0;
            switch (eve.payload) {
                case "left":
                    dx = -1;
                    break;
                case "right":
                    dx = 1;
                    break;
                case "up":
                    dy = 1;
                    break;
                case "down":
                    dy = -1;
                    break;
                default:
                    return false;
            }
            foreach (Actor actor in state.actors) {
                Vector3 position = actor.position - new Vector3(initial_x, initial_y, 0f);
                int x = (int)(position.x / offset_x) + dx;
                int y = (int)(position.y / offset_y) + dy;
                if (x <= -1 || x >= 14 || y <= -1 || y >= 14) {
                    return false;
                }
                actor.position = new Vector3(offset_x * x + initial_x, offset_y * y + initial_y, actor.position.z);
                engine.state.environment.Add(new CurveSoundObject("Prefabs/Curve/GameAudio", auEngine.getSoundForPlayer("note", new Vector3(x, y, 0))));
            }
            return false;
        }));

        gameObject.AddComponent<CurveGameEngine>();
        gameObject.AddComponent<CurveUserInterface>();
        gameObject.GetComponent<CurveGameEngine>().initialize(rules, actors, environment, players, renderer);
        gameObject.GetComponent<CurveUserInterface>().initialize(gameObject.GetComponent<CurveGameEngine>());
        gameObject.GetComponent<CurveGameEngine>().postEvent(new GameEvent("", "initialization", "unity"));
	}