예제 #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)
        {
            var deltaTime = (decimal)gameTime.ElapsedGameTime.TotalSeconds;

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (GameState == GameState.RUNNING)
            {
                WorldManager.HandleInput(KeyboardLetterToStringMapper.MapKeysToStrings(Keyboard.GetState().GetPressedKeys()));
                WorldManager.Move(deltaTime);
                WorldManager.UpdateWorldState(deltaTime);
                GameState = WorldManager.CheckEndConditions();

                if (GameState == GameState.RUNNING)
                {
                    WorldManager.AddNewElements(WorldManager.GetNumberOfElementsToAdd());
                    WorldManager.RemoveOldElements();
                }
            }

            // TODO: Add your update logic here

            base.Update(gameTime);
        }