public GameStateManager(GraphicsDeviceManager man,ContentManager cman,MineWorldClient gam)
        {
            Audiomanager = new AudioManager();
            Config = new ConfigFile("data/settings.ini");
            _inputhelper = new InputHelper();
            Game = gam;
            Conmanager = cman;
            Graphics = man;
            Device = Graphics.GraphicsDevice;
            SpriteBatch = new SpriteBatch(Device);
            _screens = new BaseState[]
                           {
                               new TitleState(this, GameState.TitleState),
                               new MainMenuState(this, GameState.MainMenuState),
                               new LoadingState(this, GameState.LoadingState),
                               new MainGameState(this, GameState.MainGameState),
                               new SettingsState(this, GameState.SettingsState),
                               _serverbrowsingstate = new ServerBrowsingState(this, GameState.ServerBrowsingState),
                               _errorstate = new ErrorState(this, GameState.ErrorState)
                           };
            //curScreen = titlestate;
            Pbag = new PropertyBag(gam,this);

            //Set initial state in the manager itself
            SwitchState(GameState.TitleState);
        }
Beispiel #2
0
 public void Update(GameTime gameTime,InputHelper input)
 {
     if (_game.Game.IsActive)
     {
         if (input.IsNewPress((Keys)ClientKey.Debug))
         {
             Enabled = !Enabled;
         }
     }
 }
Beispiel #3
0
        public override void Update(GameTime gameTime, InputHelper input)
        {
            _loadingangle += 0.01f;
            if (input.IsNewPress((Keys)ClientKey.Exit))
            {
                _gamemanager.SwitchState(GameState.MainMenuState);
            }

            //If everything is loaded then lets play
            if (_gamemanager.Pbag.WorldManager.Everythingloaded())
            {
                _gamemanager.SwitchState(GameState.MainGameState);
                //gamemanager.Pbag.ClientSender.SendPlayerInWorld();
            }
        }
Beispiel #4
0
        public override void Update(GameTime gameTime,InputHelper input)
        {
            if (Gamemanager.Game.IsActive)
            {
                //Lets see if we need to end this game
                if (input.IsNewPress((Keys)ClientKey.Exit))
                {
                    Gamemanager.Pbag.Client.Disconnect("exit");
                    Gamemanager.SwitchState(GameState.MainMenuState);
                }

                if (input.IsNewPress((Keys)ClientKey.FullScreen))
                {
                    Gamemanager.Graphics.ToggleFullScreen();
                }
            }

            //Update chunks to load close ones, unload far ones
            Gamemanager.Pbag.WorldManager.Update(gameTime,input);
            Gamemanager.Pbag.Player.Update(gameTime, input);
            Gamemanager.Pbag.Debugger.Update(gameTime, input);
        }
Beispiel #5
0
 public override void Update(GameTime gameTime, InputHelper input)
 {
     if (_gamemanager.Game.IsActive)
     {
         if (input.AnyKeyPressed(true))
         {
             _gamemanager.SwitchState(GameState.MainMenuState);
         }
     }
 }
Beispiel #6
0
 public override void Update(GameTime gameTime, InputHelper input)
 {
     _guiman.Update(gameTime);
     if (_gamemanager.Game.IsActive)
     {
         if (_play.Pushed)
         {
             _play.Pushed = false;
             //gamemanager.Pbag.ClientSender.SendJoinGame("127.0.0.1");
             //gamemanager.SwitchState(GameStates.LoadingState);
             _gamemanager.SwitchState(GameState.ServerBrowsingState);
         }
         if (_settings.Pushed)
         {
             _settings.Pushed = false;
             _gamemanager.SwitchState(GameState.SettingsState);
         }
         if (_exit.Pushed)
         {
             _exit.Pushed = false;
             _gamemanager.ExitGame();
         }
     }
 }
Beispiel #7
0
        public override void Update(GameTime gameTime, InputHelper input)
        {
            _guiman.Update(gameTime);
            if (_back.Pushed)
            {
                _back.Pushed = false;

                //Save all settings when back is pushed
                _gamemanager.Pbag.Player.Name = _playername.Text;
                _gamemanager.Audiomanager.SetVolume(_volume.Value);

                //Also save it to the file
                _gamemanager.SaveSettings();

                _gamemanager.SwitchState(GameState.MainMenuState);
            }
        }
Beispiel #8
0
        public void Update(GameTime gamefTime,InputHelper input)
        {
            //fTime increases at rate of 1 ingame day/night cycle per 20 minutes (actual value is 0 at dawn, 0.5pi at noon, pi at dusk, 1.5pi at midnight, and 0 or 2pi at dawn again)
            FTime += (float)(Math.PI / 36000);
            FTime %= MathHelper.TwoPi;

            foreach (Chunk c in Chunks)
            {
                c.Update(Player.Position,FTime);
            }

            //Update our moon and sun for the correct offset
            _sun.Update(FTime, _gamemanager.Pbag.Player.Position);
            _moon.Update(FTime, _gamemanager.Pbag.Player.Position);

            if (_gamemanager.Game.IsActive)
            {
                if (input.IsNewPress((Keys)ClientKey.WireFrame))
                {
                    _gamemanager.Pbag.WireMode = !_gamemanager.Pbag.WireMode;
                }
            }
        }
Beispiel #9
0
        public void Update(GameTime gtime, InputHelper input)
        {
            if (_game.GameManager.Game.IsActive)
            {
                if (NoClip) //If noclipped
                {
                    if (input.IsCurPress(Keys.LeftShift))
                    {
                        Speed = 1.0f;
                    }
                    else
                    {
                        Speed = 0.5f;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveForward))
                    {
                        Position -= Cam.Forward * Speed;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveLeft))
                    {
                        Position -= Cam.Right * Speed;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveBack))
                    {
                        Position += Cam.Forward * Speed;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveRight))
                    {
                        Position += Cam.Right * Speed;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveUp))
                    {
                        Position += Vector3.Up * Speed;
                    }
                    if (input.IsCurPress((Keys)ClientKey.MoveDown))
                    {
                        Position += Vector3.Down * Speed;
                    }
                }
                else
                {
                    //if (input.IsCurPress(Keys.W))
                    //{
                    //    Position -= Cam.Forward * Speed;
                    //}
                    //if (input.IsCurPress(Keys.A))
                    //{
                    //    Position -= Cam.Right * Speed;
                    //}
                    //if (input.IsCurPress(Keys.S))
                    //{
                    //    Position += Cam.Forward * Speed;
                    //}
                    //if (input.IsCurPress(Keys.D))
                    //{
                    //    Position += Cam.Right * Speed;
                    //}

                    ////Execute standard movement
                    //Vector3 footPosition = Position + new Vector3(0f, -1.5f, 0f);
                    //Vector3 headPosition = Position + new Vector3(0f, 0.1f, 0f);
                    //Vector3 midPosition = Position + new Vector3(0f, -0.7f, 0f);

                    //if (game.WorldManager.BlockAtPoint(headPosition) == BlockTypes.Water)
                    //{
                    //    bUnderwater = true;
                    //}
                    //else
                    //{
                    //    bUnderwater = false;
                    //}

                    //vPlayerVel.Y += Gravity * (float)gtime.ElapsedGameTime.TotalSeconds;

                    //if (game.WorldManager.SolidAtPointForPlayer(footPosition) || game.WorldManager.SolidAtPointForPlayer(headPosition))
                    //{
                    //    BlockTypes standingOnBlock = game.WorldManager.BlockAtPoint(footPosition);
                    //    BlockTypes hittingHeadOnBlock = game.WorldManager.BlockAtPoint(headPosition);

                    //    // If the player has their head stuck in a block, push them down.
                    //    if (game.WorldManager.SolidAtPointForPlayer(headPosition))
                    //    {
                    //        int blockIn = (int)(headPosition.Y);
                    //        Position.Y = (blockIn - 0.15f);
                    //    }

                    //    // If the player is stuck in the ground, bring them out.
                    //    // This happens because we're standing on a block at -1.5, but stuck in it at -1.4, so -1.45 is the sweet spot.
                    //    if (game.WorldManager.SolidAtPointForPlayer(footPosition))
                    //    {
                    //        int blockOn = (int)(footPosition.Y);
                    //        Position.Y = (float)(blockOn + 1 + 1.45);
                    //    }

                    //    vPlayerVel.Y = 0;
                    //}
                }
            }

            //Re-initialize aim and aimblock vectors
            VAim = new Vector3();
            VAimBlock = new Vector3();

            //Check along a path stemming from the camera's forward if there is a collision
            for (float i = 0; i <= 6; i += 0.01f)
            {
                if (i < 5.5f)
                {
                    VAim = Cam.Position - Cam.Forward * i;
                    try
                    {
                        BaseBlock select = _game.WorldManager.BlockAtPoint(VAim);
                        if (select.AimSolid)
                        {
                            break; //If there is, break the loop with the current aim vector
                        }
                    }
                    catch
                    {
                        VAim = new Vector3(-10, -10, -10);
                        break;
                    }
                }
                else
                {
                    VAim = new Vector3(-10, -10, -10);
                }
            } //Otherwise set it to be an empty vector

            if (VAim != new Vector3(-10, -10, -10))
            {
                VAimBlock = new Vector3((int)Math.Floor(VAim.X), (int)Math.Floor(VAim.Y), (int)Math.Floor(VAim.Z)); //Get the aim block based off of that aim vector
            }

            Cam.Position = Position;

            if (_game.GameManager.Game.IsActive)
            {
                if (Mousehasfocus)
                {
                    if (!input.IsCurPress(Keys.LeftAlt))
                    {
                        Cam.Rotate( //Rotate the camera based off of mouse position, set mouse position to be screen center
                            MathHelper.ToRadians((input.MousePosition.Y - _game.GameManager.Device.DisplayMode.Height / 2) * Sensitivity * 0.1f),
                            MathHelper.ToRadians((input.MousePosition.X - _game.GameManager.Device.DisplayMode.Width / 2) * Sensitivity * 0.1f),
                            0.0f
                            );
                        Mouse.SetPosition(_game.GameManager.Device.DisplayMode.Width / 2, _game.GameManager.Device.DisplayMode.Height / 2);
                    }
                    else
                    {
                        Mousehasfocus = false;
                    }
                }
                else
                {
                    Mousehasfocus = true;
                }
            }
            else
            {
                Mousehasfocus = false;
            }

            CreateFaceMarker(); //Create the face marker's vertices - I need to redo this method

            if (input.IsNewPress((MouseButtons)ClientKey.ActionOne))
            {
                //We cant do a thing with empty hand
                if (LeftHand != null)
                {
                    LeftHand.Use();
                }
            }

            if (input.IsNewPress((MouseButtons)ClientKey.ActionTwo))
            {
                //We cant do a thing with empty hand
                if (RightHand != null)
                {
                    RightHand.Use();
                }
            }

            if (input.MouseScrollWheelVelocity < 0f)
            {
                Selectedblock -= 1;
                if (Selectedblock < 0)
                {
                    Selectedblock = 0;
                }
                Selectedblocktype = (BlockTypes)Selectedblock;
            }

            if (input.MouseScrollWheelVelocity > 0f)
            {
                Selectedblock += 1;
                if (Selectedblock > 63)
                {
                    Selectedblock = 63;
                }
                Selectedblocktype = (BlockTypes)Selectedblock;
            }

            //Update our camera
            Cam.Update();
            //Send our position to the server
            _game.ClientSender.SendMovementUpdate();
        }
Beispiel #10
0
 public abstract void Update(GameTime gameTime, InputHelper input);
        public override void Update(GameTime gameTime, InputHelper input)
        {
            _guiman.Update(gameTime);
            if (_gamemanager.Game.IsActive)
            {
                if (_join.Pushed)
                {
                    _join.Pushed = false;
                    //Make sure we have a valid selection
                    if (_serversbox.ItemIndex != -1)
                    {
                        string selectedserver;
                        selectedserver = _serversbox.Items[_serversbox.ItemIndex].ToString();

                        foreach (ServerInformation server in _servers.Values)
                        {
                            if (selectedserver == server.GetTag())
                            {
                                _gamemanager.Pbag.ClientSender.SendJoinGame(server.Ipaddress);
                                _gamemanager.SwitchState(GameState.LoadingState);
                            }
                        }
                    }
                }
                if (_refresh.Pushed)
                {
                    _refresh.Pushed = false;
                    _serversbox.Items.Clear();
                    _servers.Clear();
                    _gamemanager.Pbag.ClientSender.DiscoverLocalServers();
                }
                if (_back.Pushed)
                {
                    _back.Pushed = false;
                    _gamemanager.SwitchState(GameState.MainMenuState);
                }
            }
        }