Represents a keyboard device and provides methods to query its status.
Inheritance: IInputDevice
		public OpenTKKeyboardInputSource(KeyboardDevice device)
		{
			this.device = device;
			this.device.GotFocus += this.device_GotFocus;
			this.device.LostFocus += this.device_LostFocus;
			this.device.KeyDown += this.device_KeyDown;
		}
Example #2
0
 public GameKeyboard(KeyboardDevice Keyboard)
 {
     keyboard = Keyboard;
     keyboard.KeyDown += keyboard_KeyDown;
     keyboard.KeyUp += keyboard_KeyUp;
     keyStates = new bool[keyboard.NumberOfKeys];
 }
Example #3
0
    public static void update_internal()
    {
        if (!OG_Graphics.Window.IsExiting)
        {
            OG_Graphics.Window.ProcessEvents();
        }

        OpenTK.Input.KeyboardDevice kb = OG_Graphics.Window.Keyboard;
        KeyCounters[0]  = (kb[OpenTK.Input.Key.S] || kb[OpenTK.Input.Key.Down]) ? KeyCounters[0] + 1 : 0;
        KeyCounters[1]  = (kb[OpenTK.Input.Key.A] || kb[OpenTK.Input.Key.Left]) ? KeyCounters[1] + 1 : 0;
        KeyCounters[2]  = (kb[OpenTK.Input.Key.D] || kb[OpenTK.Input.Key.Right]) ? KeyCounters[2] + 1 : 0;
        KeyCounters[3]  = (kb[OpenTK.Input.Key.W] || kb[OpenTK.Input.Key.Up]) ? KeyCounters[3] + 1 : 0;
        KeyCounters[4]  = (kb[OpenTK.Input.Key.LShift]) ? KeyCounters[4] + 1 : 0;
        KeyCounters[5]  = (kb[OpenTK.Input.Key.X] || kb[OpenTK.Input.Key.Escape]) ? KeyCounters[5] + 1 : 0;
        KeyCounters[6]  = (kb[OpenTK.Input.Key.Z] || kb[OpenTK.Input.Key.Enter]) ? KeyCounters[6] + 1 : 0;
        KeyCounters[7]  = (kb[OpenTK.Input.Key.PageUp]) ? KeyCounters[7] + 1 : 0;
        KeyCounters[8]  = (kb[OpenTK.Input.Key.PageDown]) ? KeyCounters[8] + 1 : 0;
        KeyCounters[9]  = (kb[OpenTK.Input.Key.LShift] || kb[OpenTK.Input.Key.RShift]) ? KeyCounters[9] + 1 : 0;
        KeyCounters[10] = (kb[OpenTK.Input.Key.LControl] || kb[OpenTK.Input.Key.RControl]) ? KeyCounters[10] + 1 : 0;
        KeyCounters[11] = (kb[OpenTK.Input.Key.LAlt] || kb[OpenTK.Input.Key.RAlt]) ? KeyCounters[11] + 1 : 0;
        KeyCounters[12] = (kb[OpenTK.Input.Key.F5]) ? KeyCounters[12] + 1 : 0;
        KeyCounters[13] = (kb[OpenTK.Input.Key.F6]) ? KeyCounters[13] + 1 : 0;
        KeyCounters[14] = (kb[OpenTK.Input.Key.F7]) ? KeyCounters[14] + 1 : 0;
        KeyCounters[15] = (kb[OpenTK.Input.Key.F8]) ? KeyCounters[15] + 1 : 0;
        KeyCounters[16] = (kb[OpenTK.Input.Key.F9]) ? KeyCounters[16] + 1 : 0;
        KeyCounters[17] = (kb[OpenTK.Input.Key.F2]) ? KeyCounters[17] + 1 : 0;
        KeyCounters[18] = (kb[OpenTK.Input.Key.F12]) ? KeyCounters[18] + 1 : 0;
        KeyCounters[19] = (kb[OpenTK.Input.Key.B]) ? KeyCounters[19] + 1 : 0;
        KeyCounters[20] = (kb[OpenTK.Input.Key.S]) ? KeyCounters[20] + 1 : 0;
        KeyCounters[21] = (kb[OpenTK.Input.Key.D]) ? KeyCounters[21] + 1 : 0;
    }
Example #4
0
        public KeyboardGL3x(KeyboardDevice keyboard)
        {
            _keyboard = keyboard;

            _keyboard.KeyDown += OpenTKKeyDown;
            _keyboard.KeyUp += OpenTKKeyUp;
        }
Example #5
0
 public X11Input(IWindowInfo attach)
 {
     if (attach == null)
     throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");
       X11WindowInfo x11WindowInfo = (X11WindowInfo) attach;
       this.mouse.Description = "Default X11 mouse";
       this.mouse.DeviceID = IntPtr.Zero;
       this.mouse.NumberOfButtons = 5;
       this.mouse.NumberOfWheels = 1;
       this.dummy_mice_list.Add(this.mouse);
       using (new XLock(x11WindowInfo.Display))
       {
     API.DisplayKeycodes(x11WindowInfo.Display, ref this.firstKeyCode, ref this.lastKeyCode);
     IntPtr keyboardMapping = API.GetKeyboardMapping(x11WindowInfo.Display, (byte) this.firstKeyCode, this.lastKeyCode - this.firstKeyCode + 1, ref this.keysyms_per_keycode);
     this.keysyms = new IntPtr[(this.lastKeyCode - this.firstKeyCode + 1) * this.keysyms_per_keycode];
     Marshal.PtrToStructure(keyboardMapping, (object) this.keysyms);
     API.Free(keyboardMapping);
     KeyboardDevice keyboardDevice = new KeyboardDevice();
     this.keyboard.Description = "Default X11 keyboard";
     this.keyboard.NumberOfKeys = this.lastKeyCode - this.firstKeyCode + 1;
     this.keyboard.DeviceID = IntPtr.Zero;
     this.dummy_keyboard_list.Add(this.keyboard);
     bool supported;
     Functions.XkbSetDetectableAutoRepeat(x11WindowInfo.Display, true, out supported);
       }
 }
Example #6
0
        internal LegacyInputDriver(INativeWindow window)
        {
            if (window == null)
                throw new ArgumentNullException();

            var mouse = new MouseDevice();
            mouse.Description = "Standard Mouse";
            mouse.NumberOfButtons = 3;
            mouse.NumberOfWheels = 1;
            dummy_mice_list.Add(mouse);

            var keyboard = new KeyboardDevice();
            keyboard.Description = "Standard Keyboard";
            keyboard.NumberOfKeys = 101;
            keyboard.NumberOfLeds = 3;
            keyboard.NumberOfFunctionKeys = 12;
            dummy_keyboard_list.Add(keyboard);

            // Hook mouse events
            window.MouseDown += mouse.HandleMouseDown;
            window.MouseUp += mouse.HandleMouseUp;
            window.MouseMove += mouse.HandleMouseMove;
            window.MouseWheel += mouse.HandleMouseWheel;

            // Hook keyboard events
            window.KeyDown += keyboard.HandleKeyDown;
            window.KeyUp += keyboard.HandleKeyUp;
        }
Example #7
0
 public InputManager(KeyboardDevice keyboard)
 {
     _config = new CameraConfig(new Vector3d(10, 0, 0), new Vector3d(-1, 0, 0), new Vector3d(0, 1, 0), 1, 0, 1);
     _keyboard = keyboard;
     _bindings = new Dictionary<Key, Action<float>>
         {
             {Key.W, dt => _config.Position += _config.Lookat * dt * _config.MoveSpeed},
             {Key.S, dt => _config.Position -= _config.Lookat * dt * _config.MoveSpeed},
             {Key.A, dt => _config.Position += Vector3d.Cross(_config.Up, _config.Lookat) * dt * _config.MoveSpeed},
             {Key.D, dt => _config.Position -= Vector3d.Cross(_config.Up, _config.Lookat) * dt * _config.MoveSpeed},
             {Key.ShiftLeft, dt => _config.Position += _config.Up * dt * _config.MoveSpeed},
             {Key.Space, dt => _config.Position -= _config.Up * dt * _config.MoveSpeed},
             {Key.Q, dt => _config.Up = Vector3d.Transform(_config.Up, Matrix4d.CreateFromAxisAngle(_config.Lookat, TurnSpeed * dt))},
             {Key.E, dt => _config.Up = Vector3d.Transform(_config.Up, Matrix4d.CreateFromAxisAngle(_config.Lookat, -TurnSpeed * dt))},
             {Key.Left, dt => _config.Lookat = Vector3d.Transform(_config.Lookat, Matrix4d.CreateFromAxisAngle(_config.Up, TurnSpeed * dt * _config.Fov))},
             {Key.Right, dt => _config.Lookat = Vector3d.Transform(_config.Lookat, Matrix4d.CreateFromAxisAngle(_config.Up, -TurnSpeed * dt * _config.Fov))},
             {Key.Up, dt => _config.Lookat = Vector3d.Transform(_config.Lookat, Matrix4d.CreateFromAxisAngle(Vector3d.Cross(_config.Up, _config.Lookat), TurnSpeed * dt * _config.Fov))},
             {Key.Down, dt => _config.Lookat = Vector3d.Transform(_config.Lookat, Matrix4d.CreateFromAxisAngle(Vector3d.Cross(_config.Up, _config.Lookat), -TurnSpeed * dt * _config.Fov))},
             {Key.R, dt => _config.MoveSpeed *= 1 + dt},
             {Key.F, dt =>  _config.MoveSpeed *= 1 - dt},
             {Key.N, dt => _config.Fov *= 1 + dt},
             {Key.M, dt => _config. Fov *= 1 - dt}
         };
     _keyboard.KeyDown += KeyboardOnKeyDown;
 }
Example #8
0
        public void KeyboardMove(KeyboardDevice Keyboard, FrameEventArgs e)
        {
            if (Keyboard[Key.Right])
                pos += new Vector3 (-0.1f, 0, 0);

            if (Keyboard[Key.Left])
                pos += new Vector3 (0.1f, 0, 0);

            if (Keyboard[Key.Up])
                pos += new Vector3 (0, 0, -0.1f);

            if (Keyboard[Key.Down])
                pos += new Vector3 (0, 0, 0.1f);

            if (Keyboard[Key.PageUp])
            {
                pos += new Vector3 (0, 0.1f,0.0f);
                angle += 10f;
            }

            if (Keyboard[Key.PageDown])
            {
                pos += new Vector3 (0, -0.1f, 0.0f);
                angle -= 10f;
            }
        }
Example #9
0
 /// <summary>This initializes the reference to OpenTK's keyboard.</summary>
 /// <param name="keyboardDevice">Reference to OpenTK's KeyboardDevice class within their GameWindow class.</param>
 public Keyboard(KeyboardDevice keyboardDevice)
 {
     _keyboard = keyboardDevice;
       _stateOne = new bool[_numberOfKeyboardKeys];
       _stateTwo = new bool[_numberOfKeyboardKeys];
       _currentState = _stateOne;
       _previousState = _stateTwo;
 }
 public Forgottenvoxels()
     : base()
 {
     instance = this;
     mouse = Mouse;
     keyboard = Keyboard;
     string versionOpenGL = GL.GetString(StringName.Version);
     Console.WriteLine("OpenGL Version: {0}.{1}", versionOpenGL[0],versionOpenGL[2]);
 }
Example #11
0
 public Camera(KeyboardDevice k, MouseDevice m, CameraBehavior behavior = CameraBehavior.Flight)
 {
     Behavior = behavior;
     _keyboard = k;
     _mouse = m;
     _mouse.ButtonDown += new EventHandler<MouseButtonEventArgs>(OnMouseButtonDown);
     _mouse.ButtonUp += new EventHandler<MouseButtonEventArgs>(OnMouseButtonUp);
     _mouse.Move += new EventHandler<MouseMoveEventArgs>(OnMouseMove);
 }
Example #12
0
        public void Update(KeyboardDevice keyboard, MouseDevice mouse, double time)
        {
            int file = 0, rank = 0;
            Vector2 coords;
            //= Board.bottomLeft;

            coords.X = (float)mouse.X / (float)SCREEN_WIDTH;
            //temp *= 8.0f;
            //file = (int)temp;
            coords.Y = (float)(SCREEN_HEIGHT - mouse.Y) / (float)SCREEN_HEIGHT;

            coords *= 2.0f;
            coords -= new Vector2(1.0f, 1.0f);
            //temp = 1.0f - temp;
            //temp *= 8.0f;
            //rank = (int)temp;

            coords -= Board.bottomLeft;
            coords.X /= 1.6f;
            coords.Y *= 0.5f;

            file = (int)(coords.X * 8.0f);
            rank = (int)(coords.Y * 8.0f);

            //Console.WriteLine(file  + ", " + rank);

            if(!paused)
                board.SubtractTime(time);

            if (keyboard[Key.Z] & keyboard[Key.Z] != prevZ)
            {
                board.UndoLastMove();
            }
            if (keyboard[Key.R])
            {
                board.SetBoard();
                board.GameOver = false;
            }
            if (keyboard[Key.Space] & keyboard[Key.Space] != prevSpace)
            {
                paused = !paused;
            }

            if (mouse[MOUSE0] & mouse[MOUSE0] != prevMouseButton)
            {
                board.OnClick(file, rank);
            }
            else
            {
                board.OnHover(file, rank);
            }

            prevMouseButton = mouse[MOUSE0];
            prevSpace = keyboard[Key.Space];
            prevZ = keyboard[Key.Z];
        }
Example #13
0
 /// <summary>
 /// Creates a new <see cref="InputManager" /> associated with the specified <see cref="GameWindow" />.
 /// </summary>
 /// <param name="window">The <see cref="GameWindow" /> this <see cref="InputManager" /> will interface with.</param>
 public InputManager(GameWindow window)
 {
     _keyboard = window.Keyboard;
     _mouse = window.Mouse;
     _keyboard.KeyDown += OnKeyDown;
     _keyboard.KeyUp += OnKeyUp;
     window.KeyPress += OnKeyPress;
     _mouse.ButtonDown += OnMouseDown;
     _mouse.ButtonUp += OnMouseUp;
     _mouse.WheelChanged += OnMouseWheelChanged;
 }
Example #14
0
        //AppSettings.screenWidth, AppSettings.screenHeight, GraphicsMode.Default, AppSettings.gameTitle
        public Game()
            : base(AppSettings.screenWidth, AppSettings.screenHeight, new GraphicsMode(32,24,0,AppSettings.fsaa), AppSettings.gameTitle)
        {
            VSync = VSyncMode.Off;
            if (AppSettings.verticalSync)
                VSync = VSyncMode.On;

            SetWindowState();
            this.keyboard = Keyboard;

            viewport = new Size(Width, Height);
        }
Example #15
0
        public override void Input_Controller(MouseDevice md, KeyboardDevice kd)
        {
            for (Int16 i = 0; i < 6; i++)
            {
                btnHover[i] = false;
                if ((md.X > menuVects[i][0].X && md.X < menuVects[i][1].X) && ((Settings.Height - md.Y) > menuVects[i][0].Y && (Settings.Height - md.Y) < menuVects[i][2].Y))
                {
                    btnHover[i] = true;
                }
            }

                
        }
Example #16
0
File: Game.cs Project: mokujin/DN
        protected override void OnLoad(EventArgs e)
        {
            GL.ClearColor(Color4.Black);
            LoadContent();

            g_Keyboard = Keyboard;
            g_Mouse = Mouse;
            g_Gamepad = new GamepadState(GamepadIndex.One);

            _stateManager = new StateManager();
            _stateManager.SetState(new LevelGenerationState(_stateManager));

            Keyboard.KeyRepeat = false;
        }
        public GUIEventSystem(GUIContainer root, MouseDevice mouse, KeyboardDevice keyboard, INativeWindow window)
        {
            this.root = root;

            mouse.Move += new EventHandler<OpenTK.Input.MouseMoveEventArgs>(mouse_Move);
            mouse.ButtonDown += new EventHandler<OpenTK.Input.MouseButtonEventArgs>(mouse_ButtonDown);
            mouse.ButtonUp += new EventHandler<OpenTK.Input.MouseButtonEventArgs>(mouse_ButtonUp);
            mouse.WheelChanged += new EventHandler<OpenTK.Input.MouseWheelEventArgs>(mouse_WheelChanged);

            this.keyboard = keyboard;
            keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(keyboard_KeyDown);
            keyboard.KeyUp += new EventHandler<KeyboardKeyEventArgs>(keyboard_KeyUp);
            window.KeyPress += new EventHandler<KeyPressEventArgs>(window_KeyPress);
        }
Example #18
0
        public Input(KeyboardDevice keyboard, MouseDevice mouse)
        {
            Loc2D dirLoc = new Loc2D();

            if (keyboard[Key.Down]) {
                Operations.MoveInDirection8(ref dirLoc, Direction8.Down, 1);
            }
            if (keyboard[Key.Left]) {
                Operations.MoveInDirection8(ref dirLoc, Direction8.Left, 1);
            }
            if (keyboard[Key.Up]) {
                Operations.MoveInDirection8(ref dirLoc, Direction8.Up, 1);
            }
            if (keyboard[Key.Right]) {
                Operations.MoveInDirection8(ref dirLoc, Direction8.Right, 1);
            }

            dir = Operations.GetDirection8(new Loc2D(), dirLoc);

            inputStates[(int)InputType.X] = keyboard[Key.X];
            inputStates[(int)InputType.Z] = keyboard[Key.Z];
            inputStates[(int)InputType.C] = keyboard[Key.C];
            inputStates[(int)InputType.A] = keyboard[Key.A];
            inputStates[(int)InputType.S] = keyboard[Key.S];
            inputStates[(int)InputType.D] = keyboard[Key.D];

            inputStates[(int)InputType.Q] = keyboard[Key.Q];
            inputStates[(int)InputType.W] = keyboard[Key.W];

            inputStates[(int)InputType.Enter] = (keyboard[Key.Enter]);

            LeftMouse = mouse[MouseButton.Left];
            RightMouse = mouse[MouseButton.Right];

            MouseWheel = mouse.Wheel;

            MouseLoc = new Loc2D(mouse.X, mouse.Y);

            Shift = keyboard[Key.ShiftLeft] || keyboard[Key.ShiftRight];

            ShowDebug = keyboard[Key.F1];
            SpeedDown = keyboard[Key.F2];
            SpeedUp = keyboard[Key.F3];
            #if GAME_MODE
            Intangible = keyboard[Key.F4];
            Print = keyboard[Key.F5];
            Restart = keyboard[Key.F12];
            #endif
        }
Example #19
0
        //bool disposed;

        #region --- Constructors ---

        /// <summary>
        /// Constructs a new X11Input driver. Creates a hidden InputOnly window, child to
        /// the main application window, which selects input events and routes them to 
        /// the device specific drivers (Keyboard, Mouse, Hid).
        /// </summary>
        /// <param name="attach">The window which the InputDriver will attach itself on.</param>
        public X11Input(IWindowInfo attach)
        {
            Debug.WriteLine("Initalizing X11 input driver.");
            Debug.Indent();

            if (attach == null)
                throw new ArgumentException("A valid parent window must be defined, in order to create an X11Input driver.");

            //window = new X11WindowInfo(attach);
            X11WindowInfo window = (X11WindowInfo)attach;

            // Init mouse
            mouse.Description = "Default X11 mouse";
            mouse.DeviceID = IntPtr.Zero;
            mouse.NumberOfButtons = 5;
            mouse.NumberOfWheels = 1;
            dummy_mice_list.Add(mouse);
            
            using (new XLock(window.Display))
            {
                // Init keyboard
                API.DisplayKeycodes(window.Display, ref firstKeyCode, ref lastKeyCode);
                Debug.Print("First keycode: {0}, last {1}", firstKeyCode, lastKeyCode);
    
                IntPtr keysym_ptr = API.GetKeyboardMapping(window.Display, (byte)firstKeyCode,
                    lastKeyCode - firstKeyCode + 1, ref keysyms_per_keycode);
                Debug.Print("{0} keysyms per keycode.", keysyms_per_keycode);
    
                keysyms = new IntPtr[(lastKeyCode - firstKeyCode + 1) * keysyms_per_keycode];
                Marshal.PtrToStructure(keysym_ptr, keysyms);
                API.Free(keysym_ptr);
    
                KeyboardDevice kb = new KeyboardDevice();
                keyboard.Description = "Default X11 keyboard";
                keyboard.NumberOfKeys = lastKeyCode - firstKeyCode + 1;
                keyboard.DeviceID = IntPtr.Zero;
                dummy_keyboard_list.Add(keyboard);
    
                // Request that auto-repeat is only set on devices that support it physically.
                // This typically means that it's turned off for keyboards (which is what we want).
                // We prefer this method over XAutoRepeatOff/On, because the latter needs to
                // be reset before the program exits.
                bool supported;
                Functions.XkbSetDetectableAutoRepeat(window.Display, true, out supported);
            }

            Debug.Unindent();
        }
Example #20
0
 public void Move(KeyboardDevice KD, Vector2 MouseDelta)
 {
     Vector3 moveForce = new Vector3(0, 0, 0);
     bool moved = false;
     if (KD [Key.W]) {
         moveForce.Z -= (float)Math.Cos(-Yaw) * MOVE_SPEED;
         moveForce.X -= (float)Math.Sin(-Yaw) * MOVE_SPEED;
         moved = true;
     }
     if (KD [Key.S]) {
         moveForce.Z += (float)Math.Cos(-Yaw) * MOVE_SPEED;
         moveForce.X += (float)Math.Sin(-Yaw) * MOVE_SPEED;
         moved = true;
     }
     if (KD [Key.A]) {
         moveForce.Z -= (float)Math.Cos(-Yaw + HALFPI) * MOVE_SPEED;
         moveForce.X -= (float)Math.Sin(-Yaw + HALFPI) * MOVE_SPEED;
         moved = true;
     }
     if (KD [Key.D]) {
         moveForce.Z += (float)Math.Cos(-Yaw + HALFPI) * MOVE_SPEED;
         moveForce.X += (float)Math.Sin(-Yaw + HALFPI) * MOVE_SPEED;
         moved = true;
     }
     if (KD [Key.Space] && this.OnGround) {
         //moveForce.Y += JUMP_FORCE;
     }
     if (moved)
         ++_walkFrame;
     Yaw += MouseDelta.X * MOUSE_SPEED;
     Pitch += MouseDelta.Y * MOUSE_SPEED;
     if (Pitch < WorldRenderer.MIN_PITCH) {
         Pitch = WorldRenderer.MIN_PITCH;
     }
     if (Pitch > WorldRenderer.MAX_PITCH) {
         Pitch = WorldRenderer.MAX_PITCH;
     }
     if (_swingFrame < SWING_FRAMES)
         ++_swingFrame;
     ApplyForce(moveForce);
     if (Health <= 0)
         Dead = true;
 }
Example #21
0
        /// <summary> Determines whether a hotkey is active based on the given key, 
        /// and the currently active control, alt, and shift modifiers </summary>
        public bool IsHotkey( Key key, KeyboardDevice keyboard,
            out string text, out bool moreInput)
        {
            byte flags = 0;
            if( keyboard[Key.ControlLeft] || keyboard[Key.ControlRight] ) flags |= 1;
            if( keyboard[Key.ShiftLeft] || keyboard[Key.ShiftRight] ) flags |= 2;
            if( keyboard[Key.AltLeft] || keyboard[Key.AltRight] ) flags |= 4;

            foreach( Hotkey hKey in hotkeys ) {
                if( (hKey.Flags & flags) == hKey.Flags && hKey.BaseKey == key ) {
                    text = hKey.Text;
                    moreInput = hKey.MoreInput;
                    return true;
                }
            }

            text = null;
            moreInput = false;
            return false;
        }
Example #22
0
 public void OnKeyDown(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
     switch (e.Key)
     {
         case Key.Escape:
             MainWindow.exit = true;
             break;
         case Key.Left:
             player.Angle = MathHelper.PiOver2;
             break;
         case Key.Right:
             player.Angle = 3 * MathHelper.PiOver2;
             break;
         case Key.Up:
             player.Angle = 0;
             break;
         case Key.Down:
             player.Angle = 3 * MathHelper.Pi;
             break;
     }
 }
Example #23
0
        public void KeyboardMove(KeyboardDevice Keyboard,FrameEventArgs e)
        {
            float speed = 1f;
            float time;
            time = (float)e.Time;
            speed *=time;

            if (Keyboard[Key.T]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateTranslation (0f, 0f, speed*10));
            }

            if (Keyboard[Key.G]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateTranslation (0f, 0f, -speed*10));
            }

            if (Keyboard[Key.W]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationX (speed));
            }

            if (Keyboard[Key.S]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationX (-speed));
            }

            if (Keyboard[Key.D]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationY (speed));
            }

            if (Keyboard[Key.A]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationY (-speed));
            }

            if (Keyboard[Key.E]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationZ (speed));
            }

            if (Keyboard[Key.Q]) {
                cameraMatrix = Matrix4.Mult (cameraMatrix, Matrix4.CreateRotationZ (-speed));
            }
        }
Example #24
0
 void Keyboard_KeyUp(OpenTK.Input.KeyboardDevice sender, OpenTK.Input.Key key)
 {
     ActualizarEstadoInput(key, false);
 }
Example #25
0
        public void OnUpdateFrame(FrameEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            if (!fadingOut && fadeBox.Color.A > 0)
            {
                fadeBox.Color = new Color4(0, 0, 0, fadeBox.Color.A - (float)e.Time * fadeTime);
            }

            if (fadingOut)
            {
                if (fadeBox.Color.A < 1)
                    fadeBox.Color = new Color4(0, 0, 0, fadeBox.Color.A + (float)e.Time * fadeTime);
                else
                {
                    if (gameWon)
                    {
                        MainWindow.state = new EndMenuState();
                        Resources.StopAllAudio();
                        //Resources.UnloadAudioBuffers();
                    }
                    else
                    {
                        Type oldAreaType = area.GetType();
                        area.Unload();
                        area = tempNewArea;
                        area.LoadContent(data);
                        player.MoveTo(area.SetPlayerStartLocation(oldAreaType));
                        GL.ClearColor(area.ClearColor);
                        fadingOut = false;
                    }
                }

            }

            player.Moving = false;

            if (Keyboard[Key.Up])
            {
                player.MoveBy(new Vector2(0, (float)(e.Time * Player.MoveSpeed)));
                player.Moving = true;
            }

            if (Keyboard[Key.Down])
            {
                player.MoveBy(new Vector2(0, -(float)(e.Time * Player.MoveSpeed)));
                player.Moving = true;
            }

            if (Keyboard[Key.Left])
            {
                player.MoveBy(new Vector2(-(float)(e.Time * Player.MoveSpeed), 0));
                player.Moving = true;
            }

            if (Keyboard[Key.Right])
            {
                player.MoveBy(new Vector2((float)(e.Time * Player.MoveSpeed), 0));
                player.Moving = true;
            }

            c.Update(e.Time);
            player.Update(e.Time);

            message = string.Empty;

            foreach (TriggerChangeArea trigger in area.AreaChangeTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    tempNewArea = trigger.Area;
                    fadingOut = true;
                    break;
                }
            }

            foreach (TriggerButtonPress trigger in area.ButtonPressTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    trigger.Button.Activated = true;
                }

                else
                {
                    if (trigger.Button.Activated)
                    {
                        trigger.Activate();
                    }
                }
            }

            foreach (TriggerEndgame trigger in area.EndgameTrigger)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        fadingOut = true;
                        gameWon = true;
                    }
                    else
                    {
                        message = "Press Z to repair the ship and leave!";
                    }
                }
            }

            foreach (TriggerReading trigger in area.ReadingTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        trigger.Activate();
                    }
                    else
                    {
                        message = "Press Z to read the note";
                    }
                }
            }

            List<TriggerDoorOpen> openedList = new List<TriggerDoorOpen>();
            foreach (TriggerDoorOpen trigger in area.DoorOpenTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    Entity ent = player.FindNameInInventory(trigger.LockCode);
                    if (ent != null)
                    {
                        if (Keyboard[Key.Z])
                        {
                            ChangeGameDataDoor(trigger.Door);
                            player.Inventory.Remove(ent);
                            area.EntList.Remove(trigger.Door);
                            ent.Unload();
                            trigger.Door.Unload();
                        }
                        else
                            message = "Press Z to open the " + trigger.Door.Name;
                    }
                }
            }

            List<TriggerPickup> pickedUpList = new List<TriggerPickup>();
            foreach (TriggerPickup trigger in area.PickupTriggers)
            {
                if (PhysicsManager.IsColliding(player.BoundingBox, trigger.BBox))
                {
                    if (Keyboard[Key.Z])
                    {
                        ChangeGameDataItem(trigger.Ent);
                        player.Inventory.Add(trigger.Ent);
                        area.EntList.Remove(trigger.Ent);
                        pickedUpList.Add(trigger);
                    }
                    else
                        message = "Press Z to pick up the " + trigger.Ent.Name;
                }
            }
            foreach (TriggerPickup trigger in pickedUpList)
                area.PickupTriggers.Remove(trigger);

            foreach (Entity ent in area.EntList)
            {
                if (PhysicsManager.IsColliding(player, ent) && ent.Solid)
                    player.MoveBy(PhysicsManager.ReactCollision(player, ent));
            }
            c.JumpTo(player.Position);
        }
Example #26
0
 public void OnMouseUp(object sender, MouseEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
Example #27
0
 public void OnKeyUp(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
     switch (e.Key)
     {
         case Key.Left:
             if (Keyboard[Key.Right]) player.Angle = 3 * MathHelper.PiOver2;
             if (Keyboard[Key.Up]) player.Angle = 0;
             if (Keyboard[Key.Down]) player.Angle = MathHelper.Pi;
             break;
         case Key.Right:
             if (Keyboard[Key.Left]) player.Angle = MathHelper.PiOver2;
             if (Keyboard[Key.Up]) player.Angle = 0;
             if (Keyboard[Key.Down]) player.Angle = MathHelper.Pi;
             break;
         case Key.Up:
             if (Keyboard[Key.Left]) player.Angle = MathHelper.PiOver2;
             if (Keyboard[Key.Right]) player.Angle = 3 * MathHelper.PiOver2;
             if (Keyboard[Key.Down]) player.Angle = MathHelper.Pi;
             break;
         case Key.Down:
             if (Keyboard[Key.Left]) player.Angle = MathHelper.PiOver2;
             if (Keyboard[Key.Right]) player.Angle = 3 * MathHelper.PiOver2;
             if (Keyboard[Key.Up]) player.Angle = 0;
             break;
     }
 }
Example #28
0
 public virtual void Input_Controller(MouseDevice md, KeyboardDevice kd) { }
 public void OnKeyUp(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
 public void OnKeyDown(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
     if (e.Key == Key.Escape)
         StateManager.ClearStates();
 }
        public void OnUpdateFrame(FrameEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
        {
            if (fadingIn)
            {
                fadePercent -= (float)e.Time;
                if (fadePercent <= 0)
                    fadingIn = false;
            }

            if (fadingOut)
            {
                fadePercent += (float)e.Time;
                if (fadePercent >= 1)
                {
                    StateManager.PopState();
                    if (level + 1 > maxLevel)
                        StateManager.PushState(new MenuState("You escaped!", "\n\n\nPlay again?"));
                    else
                        StateManager.PushState(new GameState(level + 1));
                }
            }

            float time = (float)e.Time;
            bool up = Keyboard[Key.W], left = Keyboard[Key.A], down = Keyboard[Key.S], right = Keyboard[Key.D];

            player.Update(time);

            Entity prevCollidedWith = lastCollidedWith;
            lastCollidedWith = null;

            Vector2 realPrevPos = player.Position;

            if (up && left)
                player.MoveUpLeft(time);
            else if (up && right)
                player.MoveUpRight(time);
            else if (down && left)
                player.MoveDownLeft(time);
            else if (down && right)
                player.MoveDownRight(time);
            else if (up)
                player.MoveUp(time);
            else if (left)
                player.MoveLeft(time);
            else if (down)
                player.MoveDown(time);
            else if (right)
                player.MoveRight(time);
            else
            {
                lastCollidedWith = prevCollidedWith; //if no key was pressed, restore the old one. HACK
                player.moving = false;
            }

            if (map.IsColliding(player.BoundingBox))
                player.Position = realPrevPos;

            foreach (var ent in entities)
            {
                if (ent is Pickaxe)
                    ((Pickaxe)ent).AIUpdate(player);

                if (ent is Goblin)
                    ((Goblin)ent).AIUpdate(player);
            }

            for (int i = entities.Count - 1; i >= 0; i--)
            {
                Entity ent = entities[i];

                ent.Update(time);
                if (map.IsColliding(ent.BoundingBox))
                    ent.ResetPos();

                if (PhysicsManager.IsColliding(player.BoundingBox, ent.BoundingBox))
                {
                    lastCollidedWith = ent;

                    if (ent is Generator)
                    {
                        player.Position = realPrevPos;
                    }
                    else if (ent is Lift)
                    {
                        if (((Lift)ent).enabled)
                        {
                            ((Lift)ent).source.Play();
                            fadingOut = true;
                        }
                    }
                    else if (ent is Pickaxe)
                    {
                        if (((Pickaxe)ent).active)
                        {
                            entities.Remove(ent);
                            player.health--;
                        }
                    }
                    else if (ent is Goblin)
                    {
                        entities.Remove(ent);
                        player.health -= 2;
                    }
                    else if (ent is Endgame)
                    {
                        fadingOut = true;
                    }
                }
            }

            if (Keyboard[Key.E] && lastCollidedWith != null)
            {
                if (lastCollidedWith is Generator)
                {
                    ((Generator)lastCollidedWith).Used = true;
                    player.drawShadow = false;
                    lift.Enable();
                }
            }

            camera.Position = player.Position;
            AudioManager.ListenerPos = new Vector3(player.Position);

            if (generator != null && generator.Used)
            {
                for (int i = entities.Count - 1; i >= 0; i--)
                {
                    var ent = entities[i];
                    if (ent is Goblin)
                        entities.Remove(ent);
                    if (ent is Pickaxe)
                        ((Pickaxe)ent).active = false;
                }
            }

            if (player.health <= 0)
            {
                StateManager.PopState();
                StateManager.PushState(loseState);
            }
        }
 public void OnMouseDown(object sender, MouseButtonEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
Example #33
0
 void Keyboard_KeyDown(OpenTK.Input.KeyboardDevice sender, OpenTK.Input.Key key)
 {
     ActualizarEstadoInput(key, true);
 }