Exemple #1
0
        public GameState Update(MouseState mouseState, KeyboardState keyboardState, GameState currentGS)
        {
            _play.SetPosition(new Vector2(Config.Width / 16 * 11 - _play.GetWidth / 2, (float)(Config.Height - _btnTexMid.Height * 1.5)));
            _play.Update(mouseState);

            _exit.SetPosition(new Vector2(Config.Width / 16 * 5 - _exit.GetWidth / 2, (float)(Config.Height - _btnTexMid.Height * 1.5)));
            _exit.Update(mouseState);

            _userName.SetPosition(new Vector2(Config.Width / 16 * 5 - _userName.GetWidth / 2, (float)(Config.Height - _btnTexMid.Height * 4.5)));
            _userName.Update(mouseState, keyboardState);

            _password.SetPosition(new Vector2(Config.Width / 16 * 11 - _password.GetWidth / 2, (float)(Config.Height - _btnTexMid.Height * 4.5)));
            _password.Update(mouseState, keyboardState);

            _server.SetBtnWidth((Config.Width - (Config.Width / 8 * 5 - _exit.GetWidth)) / 8 - 2);
            _server.SetPosition(new Vector2(Config.Width / 16 * 5 - _exit.GetWidth / 2, Config.Height - _btnTexMid.Height * 3));
            _server.Update(mouseState, keyboardState);

            _logo.SetPosition(new Vector2(Config.Width / 2 - _logo.GetWidth / 2, Config.Height / 16 * 4 - _logo.GetHeight / 2));

            _password.Update(mouseState, keyboardState);
            _server.Update(mouseState, keyboardState);

            if (_exit.IsClicked)
            {
                return(GameState.Exit);
            }

            if (_play.IsClicked)
            {
                string serverText = _server.GetText();
                if (serverText.Contains(':'))
                {
                    Storage.Network.Server = serverText.Split(':').First();
                    Storage.Network.Port   = Convert.ToUInt16(serverText.Split(':').Last());
                }
                else
                {
                    Storage.Network.Server = serverText;
                    Storage.Network.Port   = 25565;
                }
                Storage.Network.UserName = _userName.GetText();
                Storage.Network.Password = _password.GetText();
                return(GameState.InGame);
            }
            return(currentGS);
        }
Exemple #2
0
        public static void Update()
        {
            foreach (var b in new List <Button>(CurButtons))
            {
                b.Update();
            }
            foreach (var t in new List <Textbox>(CurTextboxes))
            {
                t.Update();
            }

            backgroundhue += GameTime.DeltaTime / 25;

            if (state == State.NewWorld)
            {
                string worldname = txtbx_NewWorld_Name.GetText();
                string seed      = txtbx_NewWorld_Seed.GetText();

                btn_NewWorld_CreateWorld.disabled = !IsValidNewWorld(worldname, seed);
            }
        }
Exemple #3
0
        public static void Init()
        {
            Vector2 buttonSize = new Vector2(0.3, 0.08);

            btn_Back_Title = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Main); });
            backgroundhue  = 180;

            #region Home Screen
            btn_Main_Play    = new Button(new Vector2(0, 0.3), buttonSize, "Play", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.WorldSelect); });
            btn_Main_Credits = new Button(new Vector2(0, -0.05), buttonSize, "Credits", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Credits); });
            btn_Main_Help    = new Button(new Vector2(0, -0.4), buttonSize, "Help", TextStyle.Chiller_SingleLine_Large, delegate() { SwitchTo(State.Help); });
            btn_Main_Exit    = new Button(new Vector2(0, -0.75), buttonSize, "Exit", TextStyle.Chiller_SingleLine_Large, delegate() { Glut.glutLeaveMainLoop(); });
            #endregion

            #region Background
            txt_Main_Title = new Text("TITLE HERE", new TextStyle(TextAlignment.Center, TextFont.Chiller, 3f, 2f, 1, 1f, new Vector3(1, 1, 1)), new Vector2(0, 1));
            backgroundpos  = Vector2.Zero;
            float s = 1f / Program.AspectRatio;
            float imageAspectRatio = (float)Textures.TitleBackgroundTex.Size.Width / Textures.TitleBackgroundTex.Size.Height;
            background = GuiModel.CreateRectangle(new Vector2(s * imageAspectRatio, s), Textures.TitleBackgroundTex);
            background.vao.UpdateUVs(new Vector2[] {
                backgroundpos + new Vector2(0, 1f),
                backgroundpos + new Vector2(0, 0),
                backgroundpos + new Vector2(1, 0),
                backgroundpos + new Vector2(1, 1f)
            });
            #endregion

            #region Credits
            TextStyle tstyle = new TextStyle(TextAlignment.Center, TextFont.Chiller, 0.8f, 1.8f, 1 << 30, 0.5f, new Vector3(1, 1, 1));
            txt_CreditsInfo = new Text("Copyright Alex Tan (2016). Apache License. https://github.com/Pilex1/2D-Game/blob/master/LICENSE" + Environment.NewLine + Environment.NewLine + "- code, bugs, game design, bugs, graphics, bugs, everything you see here, bugs. Did I mention bugs?" + Environment.NewLine + Environment.NewLine + "Help me continue making these projects:" + Environment.NewLine + Environment.NewLine + "Visit my github repositories to view and download the full source code plus my other projects" + Environment.NewLine + " - https://github.com/Pilex1" + Environment.NewLine + " - https://github.com/Pilex1/2D-Game" + Environment.NewLine + Environment.NewLine + "Subscribe to my youtube channel where I post videos of Mandelbrot renders and game development" + Environment.NewLine + " - Pilex", tstyle, new Vector2(0, 0.9));
            #endregion

            #region World Pickers
            btnWorldPickers = new List <Button>();

            txtboxWorldPickers = new List <Textbox>();
            worlds             = new HashSet <string>();
            ResetWorldPickers();
            #endregion

            #region New World
            //creating new world
            txtbx_NewWorld_Name = new Textbox(new Vector2(0, 0.5), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            txtbx_NewWorld_Seed = new Textbox(new Vector2(0, 0.2), new Vector2(0.3, 0.03), TextFont.Chiller, 0.6f);
            float offset = 0.15f;
            txt_NewWorld_Name        = new Text("World Name", tstyle, new Vector2(0, 0.5 + offset));
            txt_NewWorld_Seed        = new Text("Seed", tstyle, new Vector2(0, 0.2 + offset));
            btn_NewWorld_CreateWorld = new Button(new Vector2(0, -0.3), new Vector2(0.3, 0.08), "Create", TextStyle.Chiller_SingleLine_Large, delegate() {
                string worldname = txtbx_NewWorld_Name.GetText();
                worlds.Add(worldname);
                Program.SwitchToGame(worldname, int.Parse(txtbx_NewWorld_Seed.GetText()));
            });
            btn_NewWorld_RandSeed = new Button(new Vector2(0.5, 0.2), new Vector2(0.15, 0.03), "Random seed", TextStyle.Chiller_SingleLine_Small, delegate() {
                int irand = MathUtil.RandInt(Program.Rand, 1 << 24, 1 << 30);
                txtbx_NewWorld_Seed.SetText(irand.ToString());
            });
            btn_NewWorld_Back = new Button(new Vector2(0, -0.7), buttonSize, "Back", TextStyle.Chiller_SingleLine_Large, delegate() {
                txtbx_NewWorld_Name.ClearText();
                txtbx_NewWorld_Name.disabled = true;

                txtbx_NewWorld_Seed.ClearText();
                txtbx_NewWorld_Seed.disabled = true;

                SwitchTo(State.WorldSelect);
            });
            #endregion

            #region Help
            txt_Help = new Text("How to play:" + Environment.NewLine + "W A S D - movement" + Environment.NewLine + "Left click - destroy tile" + Environment.NewLine + "Right click - interact / place tile" + Environment.NewLine + "E - open / close inventory" + Environment.NewLine + "Mousewheel and keys 1 to 9 - hotbar selection" + Environment.NewLine + Environment.NewLine + "Debug controls: (pretend these don't exist)" + Environment.NewLine + "F1 - toggle tile data view" + Environment.NewLine + "F - toggle flying", tstyle, new Vector2(0, 0.9));
            #endregion

            SwitchTo(State.Main);
        }