예제 #1
0
        /// <summary>
        /// This method handles the player input for this world.
        /// </summary>
        /// <param name="bind">The bind who's state has changed.</param>
        protected override void HandleInputActive(Bind bind)
        {
            base.HandleInputActive(bind);

            // Process move forward bind
            if (bind.Name.CompareTo("FWD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveForward = true;
                }
                else
                {
                    PlayerMarine.MoveForward = false;
                }
            }
            // Process move back bind
            else if (bind.Name.CompareTo("BAC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveBack = true;
                }
                else
                {
                    PlayerMarine.MoveBack = false;
                }
            }
            // Process move left bind
            else if (bind.Name.CompareTo("LFT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveLeft = true;
                }
                else
                {
                    PlayerMarine.MoveLeft = false;
                }
            }
            // Process move right bind
            else if (bind.Name.CompareTo("RHT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.MoveRight = true;
                }
                else
                {
                    PlayerMarine.MoveRight = false;
                }
            }
            // Switch movement style (relative/absolute)
            else if (bind.Name.CompareTo("MOV") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _Manager.Input.AbsoluteMovement = !_Manager.Input.AbsoluteMovement;
                }
            }
            // Switch on/off flashlight
            else if (bind.Name.CompareTo("FLI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.FlashLight.Active = !PlayerMarine.FlashLight.Active;
                }
            }
            // Primary fire
            else if (bind.Name.CompareTo("PRI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.CurrentWeapon.IsFiring = true;
                }
                else
                {
                    PlayerMarine.CurrentWeapon.IsFiring = false;
                }
            }
            // Secondary fire
            else if (bind.Name.CompareTo("SEC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (PlayerMarine.Disposed)
                    {
                        PlayerMarine = new Marine(this, new Vector3(TileCols * Tile.TileWidth / 2, TileRows * Tile.TileHeight / 2, 0));
                    }
                }
            }
            // Reload
            else if (bind.Name.CompareTo("RLD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.CurrentWeapon.Reload();
                }
            }
            // Night vision on/off
            else if (bind.Name.CompareTo("NVI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    PlayerMarine.NightVision.Active = !PlayerMarine.NightVision.Active;
                }
            }
            // Toggle fps display
            else if (bind.Name.CompareTo("FPS") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (_FPSDisplay)
                    {
                        _FPSDisplay = false;
                        _Message    = _HelpMessage;
                    }
                    else
                    {
                        _FPSDisplay = true;
                    }
                }
            }
            // Load world editor
            else if (bind.Name.CompareTo("EDI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    // Remove world gui
                    _Manager.GetScreen("WorldGUI").Remove();

                    // Remove world screen
                    Remove();

                    // Add editor screen
                    _Manager.AddScreen(new EditorScreen(_Manager));

                    // Add editor gui
                    _Manager.AddScreen(new EditorGUI(_Manager));
                }
            }
            // Exit game
            else if (bind.Name.CompareTo("ESC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Up)
                {
                    //Application.AppReference.Exit();
                    throw new Exception("LOL: " + PlayerEntity.Position.X + ":" + PlayerEntity.Position.Y);
                }
            }

            /*
             * else if (bind.Name.CompareTo("WP1") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 0)
             *      {
             *          Player.currentWeapon = Player.weaponList[0];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP2") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 1)
             *      {
             *          Player.currentWeapon = Player.weaponList[1];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP3") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 2)
             *      {
             *          Player.currentWeapon = Player.weaponList[2];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP4") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 3)
             *      {
             *          Player.currentWeapon = Player.weaponList[3];
             *      }
             *  }
             * }
             * else if (bind.Name.CompareTo("WP5") == 0)
             * {
             *  if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
             *  {
             *      if (Player.weaponList.Count > 4)
             *      {
             *          Player.currentWeapon = Player.weaponList[4];
             *      }
             *  }
             * }*/
        }
예제 #2
0
        private bool ForEachUpdate(Bind bind, object keystate, object mState, object p3)
        {
            if (bind.MouseBind)
            {
                MouseState state = (MouseState)mState;

                // Check left mouse button
                if (bind.MouseButton == MouseButtons.LeftButton)
                {
                    if (state.LeftButton == ButtonState.Pressed && bind.State == KeyState.Up)
                    {
                        bind.State = KeyState.Down;
                        OnStateChanged(bind);
                    }
                    else if (state.LeftButton == ButtonState.Released && bind.State == KeyState.Down)
                    {
                        bind.State = KeyState.Up;
                        OnStateChanged(bind);
                    }
                }
                // Check right mouse button
                else if (bind.MouseButton == MouseButtons.RightButton)
                {
                    if (state.RightButton == ButtonState.Pressed && bind.State == KeyState.Up)
                    {
                        bind.State = KeyState.Down;
                        OnStateChanged(bind);
                    }
                    else if (state.RightButton == ButtonState.Released && bind.State == KeyState.Down)
                    {
                        bind.State = KeyState.Up;
                        OnStateChanged(bind);
                    }
                }
                // Check middle mouse button
                else if (bind.MouseButton == MouseButtons.MiddleButton)
                {
                    if (state.MiddleButton == ButtonState.Pressed && bind.State == KeyState.Up)
                    {
                        bind.State = KeyState.Down;
                        OnStateChanged(bind);
                    }
                    else if (state.MiddleButton == ButtonState.Released && bind.State == KeyState.Down)
                    {
                        bind.State = KeyState.Up;
                        OnStateChanged(bind);
                    }
                }
                // Check scroll up
                else if (bind.MouseButton == MouseButtons.ScrollUp)
                {
                    if (_ScrollValue < state.ScrollWheelValue)
                    {
                        OnStateChanged(bind);
                    }
                }
                // Check scroll down
                else if (bind.MouseButton == MouseButtons.ScrollDown)
                {
                    if (_ScrollValue > state.ScrollWheelValue)
                    {
                        OnStateChanged(bind);
                    }
                }
            }
            else
            {
                // Check keyboard binds
                KeyboardState state = (KeyboardState)keystate;
                if (state.IsKeyDown(bind.Key) && bind.State == KeyState.Up)
                {
                    bind.State = KeyState.Down;
                    OnStateChanged(bind);
                }
                else if (state.IsKeyUp(bind.Key) && bind.State == KeyState.Down)
                {
                    bind.State = KeyState.Up;
                    OnStateChanged(bind);
                }
            }
            return(true);
        }
예제 #3
0
 /// <summary>
 /// Attempts to find the binding for the given binding name.
 /// </summary>
 /// <param name="name">The name of the binding to lookup.</param>
 /// <param name="bind">The binding where the result will be stored if it finds the bind.</param>
 /// <returns>True if the binding was found and false otherwise.</returns>
 public virtual bool LookupBind(String name, out Bind bind)
 {
     return(_Binds.TryGetValue(name, out bind));
 }
예제 #4
0
 /// <summary>
 /// Adds a binding to the list to be monitored.
 /// </summary>
 /// <param name="bind">The new key binding to monitor.</param>
 public virtual void AddBind(Bind bind)
 {
     _Binds.Add(bind.Name, bind);
 }
예제 #5
0
        public override void HandleInput(Bind bind)
        {
            //base.HandleInput(bind);
            MouseState mState    = Mouse.GetState();
            Vector3    mWorldLoc = new Vector3(mState.X / _Manager.Resolution.X * _ViewPort.Size.X + _ViewPort.ActualLocation.X,
                                               mState.Y / _Manager.Resolution.Y * _ViewPort.Size.Y + _ViewPort.ActualLocation.Y, 0);
            Vector3 diff = Vector3.Zero;

            if (bind.Name.CompareTo("PRI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (_TextureBox_GUI.Hide == false)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            diff = mWorldLoc - _TextureBoxEntities[i].Position;
                            if (diff.Length() < _TextureBoxEntities[i].Radius)
                            {
                                EditorScreen editor = _Manager.GetScreen("Editor") as EditorScreen;
                                editor.TileIndex = i % Tile.TileGen.Length;
                                _TemporaryTile   = Tile.TileGen[editor.TileIndex](this, new Vector3());
                                _PreviewEntityA.Dispose();
                                _PreviewEntityA = new Entity_Quad(_Entities, PreviewPositionA, new Vector3(30, 30, 0), Vector3.Zero);
                                _PreviewEntityA.Animations.AddAnimation(_TemporaryTile.Animations.Current);
                                _PreviewEntityA.Depth = 0.17f;
                                _TemporaryTile.Dispose();
                            }
                        }
                    }
                }
            }

            if (bind.Name.CompareTo("SEC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (_TextureBox_GUI.Hide == false)
                    {
                        for (int i = 0; i < 16; i++)
                        {
                            diff = mWorldLoc - _TextureBoxEntities[i].Position;
                            if (diff.Length() < _TextureBoxEntities[i].Radius)
                            {
                                EditorScreen editor = _Manager.GetScreen("Editor") as EditorScreen;
                                editor.SecondaryIndex = i % Tile.TileGen.Length;
                                _TemporaryTile        = Tile.TileGen[editor.SecondaryIndex](this, new Vector3());
                                _PreviewEntityB.Dispose();
                                _PreviewEntityB = new Entity_Quad(_Entities, PreviewPositionB, new Vector3(30, 30, 0), Vector3.Zero);
                                _PreviewEntityB.Animations.AddAnimation(_TemporaryTile.Animations.Current);
                                _PreviewEntityB.Depth = 0.17f;
                                _TemporaryTile.Dispose();
                            }
                        }
                    }
                }
            }

            if (bind.Name.CompareTo("FLA") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    if (_TextureBox_GUI.Hide)
                    {
                        ShowTextureList();
                    }
                    else
                    {
                        HideTextureList();
                    }
                }
            }
        }
예제 #6
0
        protected override void HandleInputActive(Bind bind)
        {
            //base.HandleInputActive(bind);

            if (bind.Name.CompareTo("PRI") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _SecondaryDragging = false;
                    _Dragging          = true;
                }
                else
                {
                    _Dragging = false;
                }
            }
            else if (bind.Name.CompareTo("SEC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _Dragging          = false;
                    _SecondaryDragging = true;
                }
                else
                {
                    _SecondaryDragging = false;
                }
            }
            else if (bind.Name.CompareTo("LFT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _ViewPort.TargetLocation.X -= ScreenMoveRate;
                }
            }
            else if (bind.Name.CompareTo("RHT") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _ViewPort.TargetLocation.X += ScreenMoveRate;
                }
            }
            else if (bind.Name.CompareTo("FWD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _ViewPort.TargetLocation.Y -= ScreenMoveRate;
                }
            }
            else if (bind.Name.CompareTo("BAC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _ViewPort.TargetLocation.Y += ScreenMoveRate;
                }
            }
            else if (bind.Name.CompareTo("SAV") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _Message       = "Saved map to world.awo";
                    worker.DoWork += SaveMap;
                    worker.RunWorkerAsync();
                }
            }
            else if (bind.Name.CompareTo("ESC") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    Remove();
                    _Manager.GetScreen("EditorGUI").Remove();

                    _Manager.AddScreen(new WorldScreen(_Manager, "Content/Maps/world.awo"));
                    _Manager.AddScreen(new WorldGUI(_Manager));
                }
            }
            else if (bind.Name.CompareTo("RLD") == 0)
            {
                if (bind.State == Microsoft.Xna.Framework.Input.KeyState.Down)
                {
                    _ViewPort.TargetLocation = new Vector3(TileCols * Tile.TileWidth / 2, TileRows * Tile.TileHeight / 2, 0);
                    _ViewPort.Size           = new Vector2(800, 500);
                }
            }
            else if (bind.Name.CompareTo("ZIN") == 0)
            {
                _ViewPort.Size -= new Vector2(_Manager.Resolution.X / 20, _Manager.Resolution.Y / 20);
                //_ViewPort.TargetLocation = _Crosshair.Position - _ViewPort.Size / 2;
                _LoadPort.Size = _ViewPort.Size * 1.20f;
                //_LoadPort.LoadContent(null, null);
            }
            else if (bind.Name.CompareTo("ZOU") == 0)
            {
                _ViewPort.Size += new Vector2(_Manager.Resolution.X / 20, _Manager.Resolution.Y / 20);
                //_ViewPort.TargetLocation = _Crosshair.Position - _ViewPort.Size / 2;
                _LoadPort.Size = _ViewPort.Size * 1.20f;
                //_LoadPort.LoadContent(null, null);
            }
        }