Ejemplo n.º 1
0
 /// <summary>
 /// Allows the game to run logic such as updating the world,
 /// checking for collisions, gathering input, and playing audio.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 protected override void Update(GameTime gameTime)
 {
     GameState nextState = currentView.UpdateState(gameTime);
     if (currentState != nextState)
     {
         switch (nextState)
         {
             case GameState.None:
                 break;
             case GameState.MainMenu:
                 currentView = new MenuView(this, GameState.MainMenu);
                 break;
             case GameState.OptionsMenu:
                 currentView = new OptionsMenu(this);
                 break;
             case GameState.Gameplay:
                 if (!(currentView is GamePlayView))
                     currentView = Components.First(component => component is GamePlayView) as GamePlayView;
                 break;
             case GameState.PausedGameplay:
                 break;
             case GameState.MultiplayerMenu:
                 this.GetService<ServerClient>().Connect(System.Net.IPAddress.Loopback);
                 currentView = new GamePlayView(this, 0, GameModeChoice.SimpleRace);//MultiplayerMenu(this);
                 break;
             case GameState.SingleplayerMenu:
                 break;
             case GameState.Exiting:
                 this.Exit();
                 break;
             default:
                 break;
         }
         currentState = nextState;
     }
     base.Update(gameTime);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Components
            BaseComponents.Add(new ServerClient(this));
            BaseComponents.Add(new InputComponent(this));
            BaseComponents.Add(new HUDConsoleComponent(this));
            BaseComponents.Add(new CameraComponent(this));

            foreach (IGameComponent component in BaseComponents)
            {
                Components.Add(component);
                SetService(component.GetType(), component);
            }

            currentState = GameState.MainMenu;
            currentView = new MenuView(this, currentState);

            // Camera component

            //var cameraComponent =
            //Components.Add(cameraComponent);
            //Services.AddService(typeof(CameraComponent), cameraComponent);

            base.Initialize();
        }