Exemplo n.º 1
0
        public static void Handle(AvatarState state)
        {
            if (state.MovementState == MovementState.Lag)
            {
                state.MovementState = MovementState.Idle;
                return;
            }
            state.Position += state.KeyboardState.GetPressedKeys().Aggregate(Vector2.Zero, (acc, cur) =>
            {
                if (cur == Keys.W && state.Position.Y == _floorY)
                {
                    acc += _up;
                }
                else if (cur == Keys.A)
                {
                    acc += _left;
                }
                else if (cur == Keys.S)
                {
                    acc += _down;
                }
                else if (cur == Keys.D)
                {
                    acc += _right;
                }
                return(acc);
            });

            state.Position += _gravity * state.GameTime.ElapsedGameTime.Milliseconds;
            state.Position  = state.Position.Ceiling(300, _floorY);
        }
Exemplo n.º 2
0
 public Avatar(Texture2D texture, Action <AvatarState> updateLogic, Vector2?initialPosition = null)
 {
     _texture     = texture;
     _updateLogic = updateLogic;
     _state       = new AvatarState()
     {
         Texture  = _texture,
         Position = initialPosition ?? Vector2.Zero
     };
 }