示例#1
0
        public void Initialize(Level levelInput ,Texture2D textureInput, Vector2 positionInput)
        {
            this._level = levelInput;

            _texture = textureInput;

            //set the starting position of the player around the middle of the scrren and to the back
            _position = positionInput;

            //set the player to be alive
            _isAlive = true;

            //set the player health
            _health = 100;

            loadContent();

            //sets the player movement speed
            _velocity = Vector2.Zero;

            //constructs the list of moves
            _moves = new Move[]
                {
                    new Move("RunLeft",     Direction.Left) { IsSubMove = true },
                    new Move("RunRight",    Direction.Right) { IsSubMove = true },
                    new Move("SprintLeft",  Direction.Left, Direction.Left),
                    new Move("SprintRight", Direction.Right, Direction.Right),
                    //new Move("Jump",        Buttons.A) { IsSubMove = true },
                };
            //constructs a move list which will store its own copy of the moves array.
            _currentMoveList = new MovesList(_moves);

            //create an InputManager for the player with a sufficiently large buffer
            _inputManager = new InputManager(_currentMoveList.LongestMoveLength);
        }
 ///<summary>
 /// Finds the longest Move which matches the given input, if any.
 /// </summary>
 public Move DetectMove(InputManager input)
 {
     //perform a linear search for a move which matches the input.
     //this relies on the move array being in order of decreasing sequence length
     foreach (Move move in movesList)
     {
         if (input.SequenceMatchesMove(move))
         {
             return move;
         }
     }
     return null;
 }