Beispiel #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)
        {
            oldMouse = mouse;
            mouse    = Mouse.GetState();
            oldKbd   = kbd;
            kbd      = Keyboard.GetState();

            foreach (GameObject obj in positiveObjects)
            {
                obj.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            foreach (GameObject obj in negativeObjects)
            {
                obj.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
            }

            positiveInfluenceMap.Update(positiveObjects);
            negativeInfluenceMap.Update(negativeObjects);
            blockedMap.Update(gameObjects);

            if (kbd.IsKeyDown(Keys.D1) && oldKbd.IsKeyUp(Keys.D1))
            {
                objSelect = 1;
            }
            else if (kbd.IsKeyDown(Keys.D2) && oldKbd.IsKeyUp(Keys.D2))
            {
                objSelect = 2;
            }

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                AddGameObject();
            }
            else if (kbd.IsKeyDown(Keys.R) && oldKbd.IsKeyUp(Keys.R))
            {
                ClearMap();
            }

            influenceMap.FinalizeInfluence(positiveInfluenceMap, negativeInfluenceMap);

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