public void Update(InputState input)
        {
            _model.Frozen = input.WentActive(Keys.Space, false) ? !_model.Frozen : _model.Frozen;

            if (input.IsActive(Modifiers.Control) && input.WentActive(Keys.Right))
            {
                _model.Speed++;
            }

            if (input.IsActive(Modifiers.Control) && input.WentActive(Keys.Left))
            {
                _model.Speed--;
            }
        }
 public void UpdateSelectionBox(InputState input)
 {
     if (input.WentInactive(Buttons.LeftButton))
     {
         _selectionBoxP1 = Vector2.Zero;
         _selectionBoxP2 = Vector2.Zero;
     } else if (input.WentActive(Buttons.LeftButton))
     {
         _selectionBoxP1 = input.ScreenMouse;
         _selectionBoxP2 = input.ScreenMouse;
     }
     else if (input.IsActive(Buttons.LeftButton))
     {
         _selectionBoxP2 = input.ScreenMouse;
     }
 }
        public void Update(InputState input)
        {
            if (input.WentActive(Keys.F1))
            {
                _dialogMgr.Add(new Prompt(Console.WriteLine));
            }

            AABB selectionBox = new AABB(_selectionBoxP1, _selectionBoxP2);

            int id;
            if (_provinces.TryGetProvinceFromPoint(input.Mouse, out id))
            {
                if (input.WentActive(Buttons.LeftButton) && 
                    _labelClickableBoundaries.ContainsKey(id) &&
                    _labelClickableBoundaries[id].IsPointInside(input.ScreenMouse) &&
                    _units.IsPlayerArmy(id))
                {
                    _unitsSelection.Select(id, input.IsActive(Keys.LeftControl));    
                }
                // Only handle new selections.
                else if (input.WentActive(Buttons.LeftButton))
                {
                    _provinceSelection.Select(id);
                }
                else if (input.WentInactive(Buttons.LeftButton)
                    && selectionBox.Area < _minimumSelectionSize
                    && _unitsSelection.Count > 0)
                {
                    _units.AddOrder(_unitsSelection.Set, id);
                }
                    
                SwapInstrs(_provinceSelection.Hovering);
                _provinceSelection.Hover(id);
                SwapInstrs(id);
            }
            else
            {
                SwapInstrs(_provinceSelection.Hovering);
                _provinceSelection.StopHovering();    
            }

            if (input.WentActive(Keys.G))      MergeSelectedArmies();
            if (input.WentActive(Keys.Escape)) _unitsSelection.DeselectAll();
            if (input.WentActive(Keys.Delete)) DeleteSelectedArmies();

            if (input.WentInactive(Buttons.LeftButton) && selectionBox.Area > _minimumSelectionSize)
            {
                _unitsSelection.DeselectAll();

                // Find all units within the area and select them.
                _labelClickableBoundaries
                    .FindAll(p => _units.IsPlayerArmy(p.Key) && p.Value.Intersects(selectionBox))
                    .ForEach(p => _unitsSelection.Select(p.Key, true));
            }

            UpdateSelectionBox(input);

            if (_unitsSelection.Count > 0)
            {
                Debug.WriteToScreen("Armies", _unitsSelection.Set.Join(", "));    
            }
        }
Esempio n. 4
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>
        public void Update(GameTime gameTime)
        {
            // Read input.
            Vector2 screenDim = _spriteBatch.GetScreenDimensions();
            _input = Input.GetState(screenDim,  _renderer.RenderState.ScreenToWorldCoordinates);
            _renderer.RenderState.UpdateAspectRatio(screenDim);

            _tickTime = gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_input.IsActive(Keys.LeftControl) && _input.IsActive(Keys.Q))
            {
                IsRunning = false;
                return;
            }
            if (_input.IsActive(Keys.LeftControl) && _input.IsActive(Keys.S) && !_startServer)
            {
                _startServer = true;
                _trollServer = new Network.Server(6667);
                _trollServer.start();
            }
            if (_input.IsActive(Keys.LeftShift) && _input.IsActive(Keys.S) && _startServer)
            {
                _trollServer.stop();
                _startServer = false;
            }
            if (_input.IsActive(Keys.LeftControl) && _input.IsActive(Keys.C) && !_startClient)
            {
                _startClient = true;
                _trollClient= new Network.Client("192.168.0.3",6667);
                _trollClient.start();
            }
            if (_input.IsActive(Keys.LeftShift) && _input.IsActive(Keys.C) && _startClient)
            {
                _trollClient.stop();
                _startClient = false;
            }
                
            // It is important that _worldDate is updated first of all,
            // since the other components depend on it being in sync.
            _worldDate.Update(gameTime);

            // We update the views in reverse order,
            // because if the input state gets updated by an entity,
            // enties behind (meaning draw before, meaning having a higher index in _views) it
            // should get notified, but not entities in front of it.
            foreach (IView view in _views.Reverse())
            {
                view.Update(_input);
            }

            foreach (IModel entity in _models)
            {
                entity.Update(_worldDate);
            }

            UpdateCamera();

            Debug.WriteToScreen("Slow"     , gameTime.IsRunningSlowly ? "Yes" : "No");
            Debug.WriteToScreen("Zoom"     , _renderer.RenderState.Camera.Zoom);
            Debug.WriteToScreen("Mouse"    , _input.ScreenMouse);
            Debug.WriteToScreen("Mouse rel", _input.MouseRelativeToCenter);
        }