Пример #1
0
        protected override void LoadContent()
        {
            spritebatch = new SpriteBatch(GraphicsDevice);

            menuSoundEffect = GameContent.Load<SoundEffect>("Music and Sounds/Menus");
            creditsSoundEffect = GameContent.Load<SoundEffect>("Music and Sounds/Credits");
            menuSound = menuSoundEffect.Create();
            creditsSound = creditsSoundEffect.Create();
            creditsSound.IsLooped = true;
            creditsSound.Volume = vol;
            menuSound.IsLooped = true;
            menuSound.Volume = vol;
            currentSound = creditsSound;
            currentSound.Play();
            GameState = GameStates.MainMenu;

            base.LoadContent();
        }
Пример #2
0
 /// <summary>
 /// Handles the disposal event of a child <see cref="SoundEffectInstance"/>.
 /// </summary>
 /// <param name="child">The child instance that is being disposed.</param>
 internal void ChildDisposed(SoundEffectInstance child)
 {
     lock (children)
     {
         for (var i = 0; i < children.Count; i++)
         {
             var weakReference = children[i];
             var soundEffectInstance = weakReference.Target as SoundEffectInstance;
             if (!weakReference.IsAlive || soundEffectInstance == null || soundEffectInstance == child)
             {
                 children.RemoveAt(i);
                 i--;
             }
         }
     }
 }
Пример #3
0
 /// <summary>
 /// Adds the specified instance to the children list.
 /// </summary>
 /// <param name="instance">The instance to add to children list.</param>
 private void AddChild(SoundEffectInstance instance)
 {
     lock (children)
     {
         children.Add(new WeakReference(instance));
     }
 }
Пример #4
0
 /// <summary>
 /// Returns the speicfied SoundEffectInstance to the instance pool
 /// </summary>
 /// <param name="item">SFXInstance to return to instance pool</param>
 internal void Return(SoundEffectInstance item)
 {
     instancePool.Return(item);
 }
Пример #5
0
        public void LoadContent()
        {
            #region Load Rescources
            background = Main.GameContent.Load<Texture2D>("Menus/Background 2");
            font = Main.GameContent.Load<SpriteFont>("Font/Font1");
            title = Main.GameContent.Load<Texture2D>("Menus/Logo");
            highScoresUnPressed = Main.GameContent.Load<Texture2D>("Menus/High Scores");
            highScoresPressed = Main.GameContent.Load<Texture2D>("Menus/High Scores Pressed");
            optionsUnPressed = Main.GameContent.Load<Texture2D>("Menus/Options");
            optionsPressed = Main.GameContent.Load<Texture2D>("Menus/Options Pressed");
            menuUnPressed = Main.GameContent.Load<Texture2D>("Menus/Menu");
            menuPressed = Main.GameContent.Load<Texture2D>("Menus/Menu Pressed");
            creditsUnPressed = Main.GameContent.Load<Texture2D>("Menus/CreditsUnPressed");
            creditsPressed = Main.GameContent.Load<Texture2D>("Menus/CreditsPressed");
            soundUnPressed = Main.GameContent.Load<Texture2D>("Menus/Sound");
            soundPressed = Main.GameContent.Load<Texture2D>("Menus/SoundPressed");
            fullscreenUnPressed = Main.GameContent.Load<Texture2D>("Menus/FullScreen");
            fullscreenPressed = Main.GameContent.Load<Texture2D>("Menus/FullScreenPressed");
            inGameMenu = Main.GameContent.Load<Texture2D>("Menus/InGameMenu");
            exitUnHighLighted = Main.GameContent.Load<Texture2D>("Menus/Exit");
            exitHighLighted = Main.GameContent.Load<Texture2D>("Menus/ExitHighlight");
            resumeHighlighted = Main.GameContent.Load<Texture2D>("Menus/ResumeHighlight");
            resumeUnHighlighted = Main.GameContent.Load<Texture2D>("Menus/Resume");
            startUnPressed = Main.GameContent.Load<Texture2D>("Menus/Start");
            startPressed = Main.GameContent.Load<Texture2D>("Menus/Start Pressed");
            testKartUnPressed = Main.GameContent.Load<Texture2D>("Menus/TestKartUnPressed");
            testKartPressed = Main.GameContent.Load<Texture2D>("Menus/TestKartPressed");
            tifighterUnPressed = Main.GameContent.Load<Texture2D>("Menus/TiFighter");
            tifighterPressed = Main.GameContent.Load<Texture2D>("Menus/TiFighterPressed");
            shoppingCartUnPressed = Main.GameContent.Load<Texture2D>("Menus/ShoppingCart");
            shoppingCartPressed = Main.GameContent.Load<Texture2D>("Menus/ShoppingCartPressed");
            guminKartUnPressed = Main.GameContent.Load<Texture2D>("Menus/GuminKart");
            guminKartPressed = Main.GameContent.Load<Texture2D>("Menus/GuminKartPressed");
            Untitled = Main.GameContent.Load<Texture2D>("Menus/Untitled");
            pressed = Main.GameContent.Load<SoundEffect>("Music and Sounds/Button Press");
            pressedSound = pressed.Create();
            pressedSound.Volume = .25f;
            pressedSound.IsLooped = false;

            scores = new ScoreBoard("Scores", "Scores", 10);
            scores.retrieveScores();
            #endregion

            switch (type)
            {
                case MenuType.MainMenu:
                    kartSelect = new Button(new Vector2(310, 380), 173, 53, 1, Main.CurrentMouse, startUnPressed, startPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    highScores = new Button(new Vector2(9, 536), 324, 55, 2, Main.CurrentMouse, highScoresUnPressed, highScoresPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    options = new Button(new Vector2(280, 469), 233, 42, 3, Main.CurrentMouse, optionsUnPressed, optionsPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    credits = new Button(new Vector2(600, 545), 191, 47, 7, Main.CurrentMouse, creditsUnPressed, creditsPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    exit = new Button(new Vector2(720, 9), 71, 29, 9, Main.CurrentMouse, exitUnHighLighted, exitHighLighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    credits.ButtonPressed += ButtonPressed;
                    kartSelect.ButtonPressed += ButtonPressed;
                    options.ButtonPressed += ButtonPressed;
                    highScores.ButtonPressed += ButtonPressed;
                    exit.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Options:
                    highScores = new Button(new Vector2(467, 536), 324, 55, 2, Main.CurrentMouse, highScoresUnPressed, highScoresPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    sound = new Button(new Vector2(100, 100), 164, 53, 5, Main.CurrentMouse, soundUnPressed, soundPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    fullscreen = new Button(new Vector2(100, 200), 248, 45, 6, Main.CurrentMouse, fullscreenUnPressed, fullscreenPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    highScores.ButtonPressed += ButtonPressed;
                    sound.ButtonPressed += ButtonPressed;
                    fullscreen.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.HighScores:
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Pause:
                    start = new Button(new Vector2(325, 200), 123, 38, 8, Main.CurrentMouse, resumeUnHighlighted, resumeHighlighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(350, 300), 79, 29, 4, Main.CurrentMouse, exitUnHighLighted, exitHighLighted, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    start.ButtonPressed += ButtonPressed;
                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.KartSelect:
                    start = new Button(new Vector2(500, 500), 173, 53, 8, Main.CurrentMouse, startUnPressed, startPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    testKart = new Button(new Vector2(100, 100), 165, 23, 10, Main.CurrentMouse, testKartUnPressed, testKartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    tieFighter = new Button(new Vector2(100, 200), 173, 26, 11, Main.CurrentMouse, tifighterUnPressed, tifighterPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    shoppingCart = new Button(new Vector2(100, 300), 255, 32, 12, Main.CurrentMouse, shoppingCartUnPressed, shoppingCartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    guminKart = new Button(new Vector2(100, 400), 205, 25, 13, Main.CurrentMouse, guminKartUnPressed, guminKartPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);
                    menu = new Button(new Vector2(100, 500), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    start.ButtonPressed += ButtonPressed;
                    testKart.ButtonPressed += ButtonPressed;
                    tieFighter.ButtonPressed += ButtonPressed;
                    shoppingCart.ButtonPressed += ButtonPressed;
                    guminKart.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Credits:
                    menu = new Button(new Vector2(9, 537), 168, 54, 4, Main.CurrentMouse, menuUnPressed, menuPressed, Main.Graphics.PreferredBackBufferWidth, Main.Graphics.PreferredBackBufferHeight);

                    menu.ButtonPressed += ButtonPressed;
                    break;

                case MenuType.Publisher:
                    timer = new Timer(4000);
                    timer.Elapsed += TimeElapsed;
                    timer.Start();
                    break;

                default:
                    break;
            }
        }
Пример #6
0
        protected override void LoadContent()
        {
            ergonWave = Content.Load<SoundEffect>("ergon.adpcm");
            ergonWaveInstance = ergonWave.Create();
            ergonWaveInstance.IsLooped = true;
            waveBank = Content.Load<WaveBank>("TestBank");
            //waveBankXbox = Content.Load<WaveBank>("TestBankXbox.xwb"); //does not play correctly

            // SpriteFont supports the following font file format:
            // - DirectX Toolkit MakeSpriteFont or SharpDX Toolkit tkfont
            // - BMFont from Angelcode http://www.angelcode.com/products/bmfont/
            arial16BMFont = Content.Load<SpriteFont>("Arial16");

            // Instantiate a SpriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);

            primitiveBatch = new PrimitiveBatch<VertexPositionColor>(GraphicsDevice);
            primitiveBatchEffect = new BasicEffect(GraphicsDevice);
            primitiveBatchEffect.VertexColorEnabled = true;


            // setup tests
            tiles = new List<SoundTile>();
            Rectangle border = new Rectangle();
            border.X = SoundTile.Padding.X;
            border.Y = SoundTile.Padding.Y;

            AddTile(ref border, "Click to play looped SoundEffectInstance of " + ergonWave.Name, PlayMusic, PauseMusic);
            AddTile(ref border, "Click to play 'PewPew' wave bank entry", () => waveBank.Play("PewPew"));
            AddTile(ref border, "Click to play 'PewPew' wave bank entry with random pitch and pan", () => waveBank.Play("PewPew", 1, random.NextFloat(-1, 1), random.NextFloat(-1, 1)));
            AddTile(ref border, "Click to play 'PewPew' with 3D audio", PlayAudio3D, StopAudio3D);

            // setup 3D
            geometryEffect = ToDisposeContent(new BasicEffect(GraphicsDevice)
            {
                View = Matrix.LookAtRH(new Vector3(0, 10, 20), new Vector3(0, 0, 0), Vector3.UnitY),
                Projection = Matrix.PerspectiveFovRH((float)Math.PI / 4.0f, (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height, 0.1f, 100.0f),
                World = Matrix.Identity
            });

            cube = ToDisposeContent(GeometricPrimitive.Cube.New(GraphicsDevice));

            // Load the texture
            listenerTexture = Content.Load<Texture2D>("listen");
            emitterTexture = Content.Load<Texture2D>("speaker");
            geometryEffect.TextureEnabled = true;

            base.LoadContent();

        }
Пример #7
0
        private void StopAudio3D()
        {
            if (!play3D) return;

            audio3DEffectInstance.Stop(true);
            audio3DEffectInstance.Dispose();
            audio3DEffectInstance = null;

            play3D = false;
        }
Пример #8
0
        private void PlayAudio3D()
        {
            if (play3D)
                return;

            EnableSpatialAudioWithReverb();

            listener = Matrix.LookAtRH(Vector3.Zero, new Vector3(0, 0, 8), Vector3.Up);
            listenerVelocity = Vector3.Zero;

            emitter = Matrix.LookAtRH(new Vector3(0, 0, 8), Vector3.Zero, Vector3.Up);
            emitterVelocity = Vector3.Zero;

            audio3DEffectInstance = waveBank.Create("PewPew");
            audio3DEffectInstance.IsLooped = true;
            audio3DEffectInstance.Apply3D(listener, listenerVelocity, emitter, emitterVelocity);
            audio3DEffectInstance.Play();
            play3D = true;
        }