protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
InputManager.Update(gameTime);
if(m_lastTime == null)
m_lastTime = gameTime.TotalGameTime;
if (InputManager.PadPressed(PlayerIndex.One, Buttons.Back) || InputManager.KeyReleased(Keys.OemTilde))
{
Exit();
}
m_elapsedTime += gameTime.ElapsedGameTime;
if (m_elapsedTime > TimeSpan.FromSeconds(1))
{
m_elapsedTime -= TimeSpan.FromSeconds(1);
m_frameRate = m_frameCounter;
m_frameCounter = 0;
}
switch(m_stateManager.State)
{
case GameStates.Intro:
ShowMiniMap(false);
ShowCreateWorld(false);
ShowSettings(false);
ShowMenu(false);
if (InputManager.AnyKeyPressed() || InputManager.PadPressed(PlayerIndex.One, Buttons.Start) || InputManager.PadPressed(PlayerIndex.One, Buttons.A))
{
m_stateManager.SetState(GameStates.MainMenu);
}
if (World == null || gameTime.TotalGameTime.Subtract(m_lastTime).Seconds >= 5)
{
World = new World(new VectorID(1, 1), new Random().Next(500, 9999));
m_terrainManager.UpdateChunks(new Vector2(0, 0));
m_lastTime = gameTime.TotalGameTime;
}
break;
case GameStates.MainMenu:
ShowMiniMap(false);
ShowCreateWorld(false);
ShowSettings(false);
ShowMenu(true);
if (InputManager.PadPressed(PlayerIndex.One, Buttons.B))
{
m_stateManager.PrevState();
}
if (InputManager.KeyPressed(Keys.Escape) || InputManager.PadPressed(PlayerIndex.One, Buttons.Start))
{
if(m_stateManager.LastState == GameStates.Playing)
m_stateManager.SetState(GameStates.Playing);
}
break;
case GameStates.Settings:
ShowMiniMap(false);
ShowCreateWorld(false);
ShowMenu(false);
ShowSettings(true);
if(InputManager.PadPressed(PlayerIndex.One, Buttons.B))
{
m_stateManager.PrevState();
}
break;
case GameStates.CreateWorld:
ShowSettings(false);
ShowMenu(false);
ShowCreateWorld(true);
if (InputManager.PadPressed(PlayerIndex.One, Buttons.B))
{
m_stateManager.PrevState();
}
break;
case GameStates.CreatePlayer:
ShowSettings(false);
ShowMenu(false);
ShowCreateWorld(false);
if (InputManager.PadPressed(PlayerIndex.One, Buttons.B))
{
m_stateManager.PrevState();
}
break;
case GameStates.Playing:
ShowCreateWorld(false);
ShowSettings(false);
ShowMenu(false);
ShowMiniMap(true);
XnaGUIManager.Activate(false);
if (InputManager.KeyPressed(Keys.Escape) || InputManager.PadPressed(PlayerIndex.One, Buttons.Start))
{
m_stateManager.SetState(GameStates.MainMenu);
}
if (InputManager.KeyPressed(Keys.W) || InputManager.ThumbUpPressed(PlayerIndex.One, ThumbSticks.Left))
{
m_playerManager.Move(Directions.North);
}
if (InputManager.KeyPressed(Keys.S) || InputManager.ThumbDownPressed(PlayerIndex.One, ThumbSticks.Left))
{
m_playerManager.Move(Directions.South);
}
if (InputManager.KeyPressed(Keys.A) || InputManager.ThumbLeftPressed(PlayerIndex.One, ThumbSticks.Left))
{
m_playerManager.Move(Directions.West);
}
if (InputManager.KeyPressed(Keys.D) || InputManager.ThumbRightPressed(PlayerIndex.One, ThumbSticks.Left))
{
m_playerManager.Move(Directions.East);
}
m_playerManager.Update(gameTime);
m_terrainManager.Update(gameTime);
m_miniMap.CenterTile((int)m_playerManager.Position.X, (int)m_playerManager.Position.Y);
break;
}
XnaGUIManager.Update(gameTime);
}