コード例 #1
0
ファイル: MainMenu.cs プロジェクト: Thinny-Hendrix/MoonCow
        public MainMenu(Game1 game)
            : base(game)
        {
            this.game = game;
            tutorial = false;
            sb = new SpriteBatch(game.GraphicsDevice);
            buttons = new List<MenuButton>();

            //buttons.Add(new MenuButton("start game", new Vector2(200, 300)));
            buttons.Add(new MenuButton("Select level", new Vector2(155, 800), 0, 38));
            buttons.Add(new MenuButton("How to Play", new Vector2(190, 860), 0, 38));
            buttons.Add(new MenuButton("level creator", new Vector2(225, 920), 0, 38));
            buttons.Add(new MenuButton("exit game", new Vector2(260, 980), 0, 38));
            //buttons.Add(new MenuButton("options", new Vector2(200, 500)));

            activeButton = 0;
            currentButton = buttons.ElementAt(activeButton);
            currentButton.activate();
            scale = (float)game.GraphicsDevice.Viewport.Bounds.Width / 1920.0f;
            buttonSwitchCooldown = 0;
            holdTime = 0;
            menuCircle = new MenuCircle();
            time = 0;

            foreach (MenuButton b in buttons)
            {
                b.push(true,true,true);
            }
        }
コード例 #2
0
ファイル: LevelMenu.cs プロジェクト: Thinny-Hendrix/MoonCow
        public LevelMenu(Game1 game)
            : base(game)
        {
            this.game = game;
            sb = new SpriteBatch(game.GraphicsDevice);
            campaignButtons = new List<MenuButton>();
            customButtons = new List<MenuButton>();
            campaignMaps = Directory.GetFiles(@"Content/MapXml/Campaign/", "*.xml");
            customMaps = Directory.GetFiles(@"Content/MapXml/Custom/", "*.xml");

            campaignLabel = new MenuButton("Campaign", new Vector2(560, 490), 0);
            customLabel = new MenuButton("Custom", new Vector2(1100, 490), 0);
            campaignLabel.activate();
            loadingDrawn = false;

            int yPos = 600;

            foreach(string file in campaignMaps)
            {
                string levelName = file.Substring(24, file.Length - 28);
                campaignButtons.Add(new MenuButton(levelName, new Vector2(960, yPos), 1, true));
                yPos += 50;
            }

            yPos = 600;

            foreach (string file in customMaps)
            {
                string levelName = file.Substring(22, file.Length - 26);
                customButtons.Add(new MenuButton(levelName, new Vector2(960, yPos), 1, false));
                yPos += 50;
            }

            activeButton = 0;
            currentButton = campaignButtons.ElementAt(activeButton);
            currentButton.activate();
            scale = (float)game.GraphicsDevice.Viewport.Bounds.Width / 1920.0f;
            buttonSwitchCooldown = 0;
            holdTime = 0;
            cooldown = 40;
            campaign = true;

            lsHeader = new LsHeader();
        }
コード例 #3
0
ファイル: LevelMenu.cs プロジェクト: Thinny-Hendrix/MoonCow
        public override void Update(GameTime gameTime)
        {
            if(loading && loadingDrawn)
            {
                loadMap();
            }

            if(cooldown > 0)
            {
                cooldown--;
            }

            float stickY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y;
            float stickX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X;

            if ((Keyboard.GetState().IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) && cooldown <= 0)
            {
                if(!loading)
                    game.audioManager.addSoundEffect(AudioLibrary.select, 0.1f);
                confirm();
            }

            bool buttonPressed = false;

            if (buttonSwitchCooldown > 0)
                buttonSwitchCooldown -= Utilities.deltaTime;

            if(buttonSwitchCooldown <= 0)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left) || stickX < -0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadLeft))
                {
                    if(!campaign)
                    {
                        campaign = true;
                        activeButton = 0;
                        currentButton.disable();
                        currentButton = campaignButtons[activeButton];
                        currentButton.activate();
                        lsHeader.push(true);
                        customLabel.disable();
                        campaignLabel.activate();

                        foreach (MenuButton b in campaignButtons)
                        {
                            b.push(true, true, true);
                        }
                        foreach (MenuButton b in customButtons)
                        {
                            b.push(true, false, false);
                        }
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Right) || stickX > 0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadRight))
                {
                    if (campaign)
                    {
                        campaign = false;
                        activeButton = 0;
                        currentButton.disable();
                        currentButton = customButtons[activeButton];
                        currentButton.activate();
                        lsHeader.push(false);
                        customLabel.activate();
                        campaignLabel.disable();

                        foreach (MenuButton b in campaignButtons)
                        {
                            b.push(false, false, false);
                        }
                        foreach (MenuButton b in customButtons)
                        {
                            b.push(false, true, true);
                        }
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                }
            }

            if (buttonSwitchCooldown <= 0)
            {
                if (campaign)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Down) || stickY < -0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadDown))
                    {
                        buttonPressed = true;
                        currentButton.disable();
                        if (activeButton < campaignButtons.Count() - 1)
                        {
                            activeButton++;
                        }
                        else
                        {
                            activeButton = 0;
                        }
                        currentButton = campaignButtons.ElementAt(activeButton);
                        currentButton.activate();
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.Up) || stickY > 0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadUp))
                    {
                        buttonPressed = true;
                        currentButton.disable();
                        if (activeButton > 0)
                        {
                            activeButton--;
                        }
                        else
                        {
                            activeButton = campaignButtons.Count() - 1;
                        }
                        currentButton = campaignButtons.ElementAt(activeButton);
                        currentButton.activate();
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                }
                else
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Down) || stickY < -0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadDown))
                    {
                        buttonPressed = true;
                        currentButton.disable();
                        if (activeButton < customButtons.Count() - 1)
                        {
                            activeButton++;
                        }
                        else
                        {
                            activeButton = 0;
                        }
                        currentButton = customButtons.ElementAt(activeButton);
                        currentButton.activate();
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.Up) || stickY > 0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadUp))
                    {
                        buttonPressed = true;
                        currentButton.disable();
                        if (activeButton > 0)
                        {
                            activeButton--;
                        }
                        else
                        {
                            activeButton = customButtons.Count() - 1;
                        }
                        currentButton = customButtons.ElementAt(activeButton);
                        currentButton.activate();
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                }
            }

            if (buttonPressed)
            {
                if (holdTime < 0.2f)
                {
                    holdTime += Utilities.deltaTime;
                    buttonSwitchCooldown = 0.15f;
                }
                else
                {
                    buttonSwitchCooldown = 0.1f;
                }
            }
            else
            {
                holdTime = 0;
            }

            foreach (MenuButton b in campaignButtons)
            {
                b.Update();
            }
            foreach (MenuButton b in customButtons)
            {
                b.Update();
            }

            lsHeader.Update();
            MenuAssets.updateLinePos();
        }
コード例 #4
0
ファイル: MainMenu.cs プロジェクト: Thinny-Hendrix/MoonCow
        public override void Update(GameTime gameTime)
        {
            float stickY = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.Y;
            float stickX = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left.X;

            if (Keyboard.GetState().IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
            {
                if (!tutorial)
                {
                    confirm();
                    game.audioManager.addSoundEffect(AudioLibrary.select, 0.1f);
                }
                else
                {/*
                    if(buttonSwitchCooldown <= 0)
                    {
                        game.audioManager.addSoundEffect(AudioLibrary.select, 0.1f);
                        htpIndex++;
                        buttonSwitchCooldown = 0.5f;
                        if(htpIndex >= 3)
                        {
                            tutorial = false;
                        }
                    }*/
                }
            }

            if(tutorial)
            {
                if (buttonSwitchCooldown <= 0)
                {
                    if (Keyboard.GetState().IsKeyDown(Keys.Left) || stickX < -0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadLeft))
                    {
                        htpIndex = (htpIndex - 1 + 3) % 3;
                        buttonSwitchCooldown = 0.2f;
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }
                    if (Keyboard.GetState().IsKeyDown(Keys.Right) || stickX > 0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadRight))
                    {
                        htpIndex = (htpIndex + 1 + 3) % 3;
                        buttonSwitchCooldown = 0.2f;
                        game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                    }

                }
            }

            if(tutorial && (Keyboard.GetState().IsKeyDown(Keys.Escape) || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B)))
            {
                tutorial = false;
                htpIndex = 0;
                game.audioManager.addSoundEffect(AudioLibrary.back, 0.1f);
            }

            bool buttonPressed = false;

            if (buttonSwitchCooldown > 0)
            {
                buttonSwitchCooldown -= Utilities.deltaTime;
            }
            if (!tutorial && buttonSwitchCooldown <= 0)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Down) || stickY < -0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadDown))
                {
                    buttonPressed = true;
                    currentButton.disable();
                    if (activeButton < buttons.Count() - 1)
                    {
                        activeButton++;
                    }
                    else
                    {
                        activeButton = 0;
                    }
                    currentButton = buttons.ElementAt(activeButton);
                    currentButton.activate();
                    menuCircle.downHit();
                    game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Up) || stickY > 0.3f || GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadUp))
                {
                    buttonPressed = true;
                    currentButton.disable();
                    if (activeButton > 0)
                    {
                        activeButton--;
                    }
                    else
                    {
                        activeButton = buttons.Count()-1;
                    }
                    currentButton = buttons.ElementAt(activeButton);
                    currentButton.activate();
                    menuCircle.upHit();
                    game.audioManager.addSoundEffect(AudioLibrary.hover, 0.1f);
                }
            }

            if (buttonPressed)
            {
                if (holdTime < 0.2f)
                {
                    holdTime += Utilities.deltaTime;
                    buttonSwitchCooldown = 0.15f;
                }
                else
                {
                    buttonSwitchCooldown = 0.1f;
                }
            }
            else
            {
                holdTime = 0;
            }

            foreach(MenuButton b in buttons)
            {
                b.Update();
            }

            updateBg();
            menuCircle.Update();

            if(time != 1)
            {
                time += Utilities.deltaTime;
                if (time > 1)
                    time = 1;
            }
        }