Rotating menu in C#(for xna game)

C++, C#, Java, PHP, ect...
Post Reply
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Rotating menu in C#(for xna game)

Post by crzyone9584 »

On my old computer i use to have a tutorial for this saved via internet. To my dismay I don't have access to my old computer.

http://www.youtube.com/watch?v=EQ2Jmm4j ... re=related

the video shows what I want to do. Here is my xna code.

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using XRpgLibrary;
using XRpgLibrary.InputHandlers;
using XRpgLibrary.Controls;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Content;

namespace Client.GameScreens
{
    public class CircleMenuScreen : BaseGameState
    {
        #region Field region

        PictureBox backgroundImage;
        PictureBox startGame;
        PictureBox loadGame;
        PictureBox exitGame;
        Rectangle _startGame;
        Rectangle _loadGame;
        Rectangle _exitGame;
 
        float maxItemWidth = 0f;

        #endregion

        #region Property Region
        #endregion

        #region Constructor Region

        public CircleMenuScreen(Game game, GameStateManager manager)
            : base(game, manager)
        {
            _startGame = new Rectangle(200, 200, 100, 100);
            _loadGame = new Rectangle(150, 150, 100, 100);
            _exitGame = new Rectangle(100, 100, 100, 100);
        }

        #endregion

        #region XNA Method Region

        public override void Initialize()
        {
            base.Initialize();
        }

        protected override void LoadContent()
        {
            base.LoadContent();

            ContentManager Content = Game.Content;

            backgroundImage = new PictureBox(
                Content.Load<Texture2D>(@"Graphics\Backgrounds\titlescreen"),
                GameRef.ScreenRectangle);
            ControlManager.Add(backgroundImage);

            startGame = new PictureBox(
                Content.Load<Texture2D>(@"Graphics\GUI\start"),
                _startGame);
            startGame.Selected += new EventHandler(menuItem_Selected);

            ControlManager.Add(startGame);

            loadGame = new PictureBox(
                Content.Load<Texture2D>(@"Graphics\GUI\load"),
                _loadGame);
            loadGame.Selected += menuItem_Selected;

            ControlManager.Add(loadGame);

            exitGame = new PictureBox(
                Content.Load<Texture2D>(@"Graphics\GUI\exit"),
                _exitGame);
            exitGame.Selected += menuItem_Selected;

            ControlManager.Add(exitGame);

            ControlManager.NextControl();

            ControlManager.FocusChanged += new EventHandler(ControlManager_FocusChanged);

            ControlManager_FocusChanged(startGame, null);
        }

        void ControlManager_FocusChanged(object sender, EventArgs e)
        {
            Control control = sender as Control;
            Vector2 position = new Vector2(control.Position.X + maxItemWidth + 10f, control.Position.Y);
        }

        private void menuItem_Selected(object sender, EventArgs e)
        {
            if (sender == startGame)
            {
                //StateManager.PushState(GameRef.CharacterGeneratorScreen);
            }

            if (sender == loadGame)
            {
                StateManager.PushState(GameRef.GamePlayScreen);
            }

            if (sender == exitGame)
            {
                GameRef.Exit();
            }
        }

        public override void Update(GameTime gameTime)
        {
            if (InputHandler.ButtonPressed(Buttons.LeftThumbstickUp, PlayerIndex.One) ||
                InputHandler.ButtonPressed(Buttons.DPadUp, PlayerIndex.One) ||
                InputHandler.KeyPressed(Keys.Up))
                
                if (InputHandler.ButtonPressed(Buttons.LeftThumbstickDown, PlayerIndex.One) ||
                InputHandler.ButtonPressed(Buttons.DPadDown, PlayerIndex.One) ||
                InputHandler.KeyPressed(Keys.Down))
                    if (_startGame.X == 200)
                    {
                        _startGame.X = 100;
                        _startGame.Y = 100;
                        _loadGame.X = 200;
                        _loadGame.Y = 200;
                        _exitGame.X = 150;
                        _exitGame.Y = 150;
                    }
                    else if (_startGame.X == 100)
                    {
                        _startGame.X = 150;
                        _startGame.Y = 150;
                        _loadGame.X = 100;
                        _loadGame.Y = 100;
                        _exitGame.X = 200;
                        _exitGame.Y = 200;
                    }
                    else if (_startGame.X == 150)
                    {
                        _startGame.X = 200;
                        _startGame.Y = 200;
                        _loadGame.X = 150;
                        _loadGame.Y = 150;
                        _exitGame.X = 100;
                        _exitGame.Y = 100;
                    }
            
                    

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            GameRef.SpriteBatch.Begin();

            base.Draw(gameTime);

            ControlManager.Draw(GameRef.SpriteBatch);

            GameRef.SpriteBatch.End();
        }

        #endregion

        #region Game State Method Region
        #endregion
the pictures show up no problem. the issue is getting them to actually move. I know I don't have them set up in a circle right now but this is just for testing purposes. So if any know a good tutorial on how to make this work thanks.. Also if you know a way to make the rotating smooth by all means please let me know.
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Re: Rotating menu in C#(for xna game)

Post by crzyone9584 »

Sorry for the double post. I figured I'd let everyone know that I got it working.. well kinda. now i just need to add in the animation of it going into a circle. but that part can wait for now. I got the basic system done for now.

[youtube]http://www.youtube.com/watch?v=Gd9Fi2U0kOs[/youtube]

Final code:

Code: Select all

if (InputHandler.ButtonPressed(Buttons.LeftThumbstickDown, PlayerIndex.One) ||
            InputHandler.ButtonPressed(Buttons.DPadDown, PlayerIndex.One) ||
            InputHandler.KeyPressed(Keys.Down))
            {
                if (startGame.DestinationRectangle.X == 200)
                {
                    startGame.SetPosition(new Vector2(100, 100));
                    loadGame.SetPosition(new Vector2(200, 200));
                    exitGame.SetPosition(new Vector2(150, 150));
                }

                else if (startGame.DestinationRectangle.X == 100)
                {
                    startGame.SetPosition(new Vector2(150, 150));
                    loadGame.SetPosition(new Vector2(100, 100));
                    exitGame.SetPosition(new Vector2(200, 200)); ;
                }

                else if (startGame.DestinationRectangle.X == 150)
                {
                    startGame.SetPosition(new Vector2(200, 200));
                    loadGame.SetPosition(new Vector2(150, 150));
                    exitGame.SetPosition(new Vector2(100, 100));
                }
            }
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
User avatar
62896dude
Posts: 516
Joined: Thu Jan 20, 2011 2:39 am

Re: Rotating menu in C#(for xna game)

Post by 62896dude »

Nice job! Very smooth movement through the three options!
Languages: C++, C#, Javascript + Angular, PHP
Programs: Webstorm 2017, Notepad++, Photoshop
Current Project: HP Destiny
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Rotating menu in C#(for xna game)

Post by Xaleph »

Hehe good job. I noticed a double ; at the end of a line:

exitGame.SetPosition(new Vector2(200, 200)); ;

Also, are you going to make it dynamic? Otherwise, you`ll have to write a heck of a lot of lines of code to swap between them.
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Re: Rotating menu in C#(for xna game)

Post by crzyone9584 »

This is just the first version. Eventually I'll have it actually show the rotation while its in like a circle. Thanks for pointing out the extra ;. Once i figure out how to actually show it moving from point a to point b and hit every xth point so it looks like it is actually rotating then I'll start optimizing the code. I think i work a little backwards. But this is on hold till I'm able to get my camera working again. I followed some tutorials found on a site that is going through and building a single player xna rpg game but i changed out the map system and broke my camera lol. Now i have to figure out whats wrong with that before i continue on my ring menu.
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Rotating menu in C#(for xna game)

Post by Jackolantern »

I have to say, moving back to PHP for a bit after being in .NET land for so long, I miss Visual Studio so bad. It really is your best buddy in development. Period.

I think this makes me want to pick up learning XNA for WP7 again :)
The indelible lord of tl;dr
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Re: Rotating menu in C#(for xna game)

Post by crzyone9584 »

if i ever get a wp7.. which i wont cause i hate microsoft yet i love visual studio... i know the irony... anywho if i ever get a wp7 id start making this game for wp7 also! then people can play my game on the go!!! well that is if i get the damn camera working again... I fails at this camera stuff. Everything else i can do... but camera is fails lol
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Rotating menu in C#(for xna game)

Post by hallsofvallhalla »

wow nice work! Makes me want to start learning XNA ;)
crzyone9584
Posts: 116
Joined: Mon Aug 01, 2011 4:46 am

Re: Rotating menu in C#(for xna game)

Post by crzyone9584 »

Its not that hard. Although getting the camera/map to work together is killing me thats for sure.
Imagecrzy
Male Ninja
Str: 5 Agi: 17 Fort: 5 IQ: 5
HP: 10/10 MP: 5/5
See Full Character:
Post Reply

Return to “Coding”