public static Movement Create <T>(IKeyState keyState, Camera camera, Scene scene) where T : Movement, new()
        {
            T ret = new T();

            ret.camera     = camera;
            ret.cameraNode = camera.ParentNode;
            ret.keyState   = keyState;
            ret.Initialize(scene);
            return(ret);
        }
Beispiel #2
0
 public void SwitchState()
 {
     if (_currentKeyState is KeyStateUnshifted)
     {
         _currentKeyState = _keyStates[1];
     }
     else
     {
         _currentKeyState = _keyStates[0];
     }
     _currentKeyState.CreateKeys();
 }
Beispiel #3
0
        /*******************************
        ****** Key State Tracking ******
        *******************************/

        // Update all Key States for Assigned Frame
        public void UpdateKeyStates(int frame)
        {
            // Loop through existing keys and update accordingly:
            for (byte i = 1; i < this.iKeyTrack.Count; i++)
            {
                IKeyState keyState = this.iKeyTrack[(IKey)i];

                if (keyState == IKeyState.Pressed)
                {
                    this.iKeyTrack[(IKey)i] = IKeyState.On;
                }
                else if (keyState == IKeyState.Released)
                {
                    this.iKeyTrack[(IKey)i] = IKeyState.Off;
                }
            }

            // Handle changes affected by this frame:
            if (inputLog.TryGetValue(frame, out byte[] kElements))
        private void ReadKeyboardInput(IKeyState leftArrowState, IKeyState rightArrowState)
        {
            if (leftArrowState.IsPressed && rightArrowState.IsPressed)
            {
                if (Velocity.Magnitude() < maxAcceleration.Magnitude() * 1.5)
                    Velocity = new Vector2D(0, 0);
                else if (Velocity.X > 0)
                    Velocity -= 5 * maxAcceleration;
                else if (Velocity.X < 0)
                    Velocity += 5 * maxAcceleration;
            }
            else if (leftArrowState.IsPressed)
            {
                if (Velocity.X > 0)
                {
                    this.Velocity -= 5 * maxAcceleration;
                    if (this.Velocity.X < 0)
                        this.Velocity.X = 0;
                }
                else
                {
                    this.Velocity -= maxAcceleration;
                }

                if (Velocity.Magnitude() > maxVelocity.Magnitude())
                {
                    Velocity = -maxVelocity;
                }
            }
            else if (rightArrowState.IsPressed)
            {

                if (Velocity.X < 0)
                {
                    this.Velocity += 5 * maxAcceleration;
                    if (this.Velocity.X > 0)
                        this.Velocity.X = 0;
                }
                else
                {
                    this.Velocity += maxAcceleration;
                }

                if (Velocity.Magnitude() > maxVelocity.Magnitude())
                {
                    Velocity = maxVelocity;
                }
            }
            else if (!rightArrowState.IsPressed && !leftArrowState.IsPressed)
            {
                if (Velocity.Magnitude() < maxAcceleration.Magnitude())
                    Velocity = new Vector2D(0, 0);
                else if (Velocity.X > 0)
                    Velocity -= maxAcceleration;
                else if (Velocity.X < 0)
                    Velocity += maxAcceleration;
            }
        }
Beispiel #5
0
 public KeyStateContext(KeyboardHelper parent)
 {
     _keyStates       = new IKeyState[] { new KeyStateUnshifted(parent), new KeyStateShifted(parent) };
     _currentKeyState = _keyStates[0];
 }