コード例 #1
0
        public void Update()
        {
            //mouse positioning
            MouseState m      = Mouse.GetState();
            int        mouseX = (int)m.X / 16;
            int        mouseY = (int)m.Y / 16;

            MouseLocation = new Point(m.X, m.Y);
            MouseBox      = new Rectangle(mouseX * 16, mouseY * 16, MouseTexture.Width, MouseTexture.Height);

            BackButton.Update(m);

            if (BackButton.Pressed)
            {
                BackButton.Press();
                this.Game.Menu.ShowHomePage();
            }

            SaveButton.Update(m);
            if (SaveButton.Pressed)
            {
                if (MarioPlaced && CastlePlaced && FlagPlaced)
                {
                    LevelEncoder.Encode(this.LevelName, this.LevelMap, this.Game);
                    SaveButton.Press();
                    this.Game.Menu.ShowHomePage();
                }
            }

            foreach (Button b in Buttons)
            {
                b.Update(m);
                if (b.Pressed)
                {
                    ModifySubmenuVisibility(b.Text, true);
                }
                else
                {
                    ModifySubmenuVisibility(b.Text, false);
                }
            }

            UpdateButtonSet(MarioButtons, m);
            UpdateButtonSet(ItemButtons, m);
            UpdateButtonSet(BlockButtons, m);
            UpdateButtonSet(PipeButtons, m);
            UpdateButtonSet(MiscButtons, m);
            UpdateButtonSet(EnemyButtons, m);


            if (CheckIfPlaceable(MouseLocation) && holdingCreatable)
            {
                cursorIsVisible = true;
            }
            else
            {
                cursorIsVisible = false;
            }

            if (m.LeftButton == ButtonState.Pressed && cursorIsVisible)
            {
                if (m.X <= WindowWidth && m.Y <= WindowHeight && m.X >= 0 && m.Y >= 0)
                {
                    if (!MarioPlaced && MarioButtons.Values.Contains(heldCreatable))
                    {
                        LevelMap[mouseX, mouseY] = heldCreatable;
                        MarioPlaced = true;
                    }
                    else if (!FlagPlaced && heldCreatable.EncodingString == "FXX")
                    {
                        LevelMap[mouseX, mouseY] = heldCreatable;
                        FlagPlaced = true;
                    }
                    else if (!CastlePlaced && heldCreatable.EncodingString == "KXX")
                    {
                        LevelMap[mouseX, mouseY] = heldCreatable;
                        CastlePlaced             = true;
                    }
                    else
                    {
                        LevelMap[mouseX, mouseY] = heldCreatable;
                    }
                }
            }
        }