コード例 #1
0
ファイル: MenuState.cs プロジェクト: demonixis/SpaceGame-XNA
        protected override void item_MouseJustClicked(object sender, MouseClickEntityEventArgs e)
        {
            MenuItem item = (sender as MenuItem);

            if (item != null)
            {
                switch (item.ItemPosition)
                {
                case 0: YnG.SwitchState(new SelectShipState()); break;

                case 1:
                    Registry.AudioManager.SpeakAsync("This section is disabled at this time");
                    //YnG.SwitchState(new MultiPlayerState(2));
                    break;

                case 2: YnG.SwitchState(new ScoreState()); break;

                case 3: YnG.SwitchState(new OptionsState()); break;

                case 4: YnG.SwitchState(new CreditsState()); break;

                case 5: YnG.Exit(); break;
                }
            }
        }
コード例 #2
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (YnG.Keys.JustPressed(Keys.Up) || YnG.Keys.JustPressed(Keys.Down) || YnG.Keys.JustPressed(Keys.Left) || YnG.Keys.JustPressed(Keys.Right) || _checkForHover)
            {
                if (YnG.Keys.JustPressed(Keys.Up) || YnG.Keys.JustPressed(Keys.Left))
                {
                    menuItemIndex--;
                }

                else if (YnG.Keys.JustPressed(Keys.Down) || YnG.Keys.JustPressed(Keys.Right))
                {
                    menuItemIndex++;
                }

                menuItemIndex = menuItemIndex < 0 ? (menuItems.Length - 1) : menuItemIndex;
                menuItemIndex = menuItemIndex > (menuItems.Length - 1) ? 0 : menuItemIndex;

                ResetColor();

                menuItems[menuItemIndex].Color = Color.DodgerBlue;

                if (menuItemIndex < 3)
                {
                    menuItemSelector.Position = new Vector2(0, menuItems[menuItemIndex].Y + menuItems[menuItemIndex].ScaledHeight / 2 - menuItemSelector.ScaledHeight / 2);
                    menuItemSelector.Visible  = true;
                }
                else
                {
                    menuItemSelector.Visible = false;
                }

                _checkForHover = false;
            }
            else if (YnG.Keys.JustPressed(Keys.Enter) || YnG.Keys.JustPressed(Keys.Space) || _checkForNext)
            {
                string nextState = String.Empty;

                switch (menuItemIndex)
                {
                case 0: (YnG.Game as MazeGame).PrepareNewLevel(1, true); break;

                case 1: nextState = "selection"; break;

                case 2: nextState = "options"; break;

                case 3: nextState = "about"; break;

                case 4: YnG.Exit(); break;
                }

                if (nextState != String.Empty)
                {
                    stateManager.SetActive(nextState, true);
                }

                _checkForNext = false;
            }
        }
コード例 #3
0
ファイル: MainMenuState.cs プロジェクト: demonixis/amlost
        public void BuildGui()
        {
            YnLabel title = new YnLabel();

            title.Text       = "I'm lost";
            title.CustomFont = YnG.Content.Load <SpriteFont>("Fonts/TitleFont");
            //title.Layout(); // Forçage du layout pour avoir la taille du texte
            title.Position = new Vector2(YnG.Width / 2 - title.Width / 2, title.Height);
            _gui.Add(title);

            YnPanel menu = new YnPanel();

            menu.HasBackground = false;
            menu.Position      = new Vector2(YnG.Width / 2 - 170 / 2, title.Position.Y + title.Height * 1.5F);
            menu.Padding       = 10;
            _gui.Add(menu);

            const int buttonWidth  = 150;
            const int buttonHeight = 50;

            SpriteFont   menuFont   = YnG.Content.Load <SpriteFont>("Fonts/MainMenuFont");
            YnTextButton playButton = menu.Add(new YnTextButton());

            playButton.Text        = "Jouer";
            playButton.Width       = buttonHeight;
            playButton.Width       = buttonWidth;
            playButton.CustomFont  = menuFont;
            playButton.MouseClick += delegate(object o, MouseClickEntityEventArgs e)
            {
                // TODO
            };

            YnTextButton settingsButton = menu.Add(new YnTextButton());

            settingsButton.Text        = "Options";
            settingsButton.Width       = buttonHeight;
            settingsButton.Width       = buttonWidth;
            settingsButton.CustomFont  = menuFont;
            settingsButton.MouseClick += delegate(object o, MouseClickEntityEventArgs e)
            {
                // TODO
            };

            YnTextButton exitButton = menu.Add(new YnTextButton());

            exitButton.Text        = "Quitter";
            exitButton.Width       = buttonHeight;
            exitButton.Width       = buttonWidth;
            exitButton.CustomFont  = menuFont;
            exitButton.MouseClick += delegate(object o, MouseClickEntityEventArgs e)
            {
                YnG.Exit();
            };


            _gui.Initialize();
            //_gui.PrepareWidgets();
        }
コード例 #4
0
ファイル: MenuState.cs プロジェクト: demonixis/amlost
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (YnG.Keys.JustPressed(Keys.Enter) || MouseInRectangle(playRectangle) || TouchInRectangle(playRectangle))
            {
                YnG.StateManager.SetActive("scene", true);
            }

            else if (YnG.Keys.JustPressed(Keys.Escape) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Back) || MouseInRectangle(quitRectangle) || TouchInRectangle(quitRectangle))
            {
                YnG.Exit();
            }
        }
コード例 #5
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            _ambianceManager.Update(gameTime);

            _narationTimer.Update(gameTime);

            if (_deadlySceenOfDeath)
            {
                // Le joueur est là où il ne devrait pas!
                // Fondu qui va bien
                _deathAlpha += 0.01F;

                if (_deathAlpha >= 1.0F && _ambianceManager.TransitionDone())
                {
                    // Le joueur est mort : TP sur le banc
                    _deathAlpha = 0.0F;
                    SetData(ImlostGame.Scenes ["scene_1"]);
                }
            }
            else
            {
                if (_showSplash)
                {
                    // Splash affiché, on le masque si on clique n'importe où
                    if (YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        _showSplash = false;
                    }
                }
                else
                {
                    _menuIcon.Update(gameTime);
                    _notesIcon.Update(gameTime);

                    //Gestion du curseur par manette xbox360
                    if (GamePad.GetState(PlayerIndex.One).IsConnected)
                    {
#if !LINUX
                        Mouse.SetPosition(YnG.Mouse.X + (int)YnG.Gamepad.RightStickValue(PlayerIndex.One).X * 20, YnG.Mouse.Y - (int)YnG.Gamepad.RightStickValue(PlayerIndex.One).Y * 20);
#endif
                    }

                    if (MouseInRectangle(_menuIcon.Rectangle) && YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        // Click sur le menu
                        // TODO
                    }

                    // Images sur la scène
                    List <YnEntity> safeList = new List <YnEntity>(_itemsOnScreen);
                    foreach (YnEntity img in safeList)
                    {
                        img.Update(gameTime);
                    }

                    if (YnG.Mouse.MouseState.LeftButton == ButtonState.Pressed && !_dragging)
                    {
                        foreach (YnEntity img in _itemImages.Values)
                        {
                            if (MouseInRectangle(img.Rectangle))
                            {
                                _dragging = true;

                                _draggedImage = new YnEntity(img.AssetName);
                                _draggedImage.LoadContent();
                            }
                        }
                    }

                    if (YnG.Mouse.Released(MouseButton.Left) && _dragging)
                    {
                        _draggedImage.Position = new Vector2(YnG.Mouse.X - _draggedImage.Width / 2, YnG.Mouse.Y - _draggedImage.Height / 2);

                        if (YnG.Mouse.Released(MouseButton.Left))
                        {
                            // Drop
                            List <YnEntity> safeList2 = new List <YnEntity>(_itemsOnScreen);
                            foreach (YnEntity img in safeList2)
                            {
                                if (img.Rectangle.Intersects(_draggedImage.Rectangle))
                                {
                                    // Intersection
                                    DoDrop(_draggedImage, img);
                                }
                            }
                        }
                    }

                    if (_dragging)
                    {
                        _draggedImage.Position = new Vector2(YnG.Mouse.X - _draggedImage.Width / 2, YnG.Mouse.Y - _draggedImage.Height / 2);
                    }

                    if (YnG.Mouse.Released(MouseButton.Left))
                    {
                        _dragging = false;
                    }

                    // Déplacement au clavier, et manette Xbox360
                    if ((YnG.Keys.JustPressed(Keys.Z) || YnG.Keys.JustPressed(Keys.Up) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickUp)) &&
                        _sceneData.TopScene != String.Empty)
                    {
                        GoUp();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.S) || YnG.Keys.JustPressed(Keys.Down) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickDown)) &&
                             _sceneData.BottomScene != String.Empty)
                    {
                        GoDown();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.Q) || YnG.Keys.JustPressed(Keys.Left) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickLeft)) &&
                             _sceneData.LeftScene != String.Empty)
                    {
                        GoLeft();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.D) || YnG.Keys.JustPressed(Keys.Right) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickRight)) &&
                             _sceneData.RightScene != String.Empty)
                    {
                        GoRight();
                    }
                    else if (YnG.Keys.JustPressed(Keys.Escape) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Back))
                    {
                        YnG.Exit();
                    }

                    if (YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        // Click sur le bouton de menu
                        int mx = YnG.Mouse.X;
                        int my = YnG.Mouse.Y;
                        if (MouseInRectangle(_menuHitbox) || TouchInRectangle(_menuHitbox) ||
                            YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                        {
                            // Afficher ou masquer le menu
                            // 97 => hauteur du menu
                            // 25 => hauteur de la poignée
                            int delta = 97 - 25;
                            if (_menuIsShown)
                            {
                                // Déplacement de la hitbox vers le haut
                                _menuHitbox.Y += delta;

                                // Déplacement du background vers le haut
                                _menuBackground.Y += delta;
                            }
                            else
                            {
                                // Déplacement de la hitbox vers le bas
                                _menuHitbox.Y -= delta;

                                // Déplacement du background vers le bas
                                _menuBackground.Y -= delta;
                            }
                            _menuIsShown = !_menuIsShown;

                            _menuIcon.Visible  = _menuIsShown;
                            _notesIcon.Visible = _menuIsShown;

                            // Un peu brutasse comme méthode...
                            // On cache tout
                            foreach (KeyValuePair <string, YnEntity> pair in _itemImages)
                            {
                                pair.Value.Visible = false;
                            }

                            // Et on ne raffiche que ce qui est dans l'inventaire du joueur
                            int itemPadding = 20;
                            int nbItems     = _inventory.Count;
                            int x           = YnG.Width / 2 - (56 * nbItems) / 2;
                            if (nbItems > 1)
                            {
                                x -= ((nbItems - 1) * itemPadding) / 2;
                            }

                            foreach (InventoryItem item in _inventory)
                            {
                                if (_menuIsShown)
                                {
                                    _itemImages [item.Code].Visible = true;

                                    // Replacement de l'élément, centré en bas, de gauche à droite
                                    Vector2 pos = new Vector2(x, YnG.Height - 63);
                                    _itemImages [item.Code].Position = pos;

                                    x += 56 + itemPadding;
                                }
                            }
                        }
                    }
                }
            }
        }