Inheritance: IInputDevice
Exemple #1
1
        public static Vector4 UnProject(ref Matrix4 projection, Matrix4 view, Size viewport, MouseDevice mouse)
        {
            Vector4 vec;

            if (mouse.X > 0)
            {
                vec = new Vector4();
            }
            vec.X = 2.0f * mouse.X / (float)viewport.Width -1;
            vec.Y = -(2.0f * mouse.Y / (float)viewport.Height -1);
            vec.Z = 0;
            vec.W = 1.0f;

            Matrix4 viewInv = Matrix4.Invert(view);
            Matrix4 projInv = Matrix4.Invert(projection);

            Vector4.Transform(ref vec, ref projInv, out vec);
            Vector4.Transform(ref vec, ref viewInv, out vec);

            if (vec.W > float.Epsilon || vec.W < float.Epsilon)
            {
                vec.X /= vec.W;
                vec.Y /= vec.W;
                vec.Z /= vec.W;
            }

            return (vec);
        }
Exemple #2
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;
        }
        public PlayerNameState(GameEngine engine, MainMenuState ms)
        {
            eng = engine;
            mouse = eng.Mouse;
            savedGameStates = new Stack<XmlNodeList>();
            savedGameChoices = new Stack<string>();
            _ms = ms;

            Assembly assembly = Assembly.GetExecutingAssembly();
            
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            lookat = new Vector3(0, 0, 2);
            eye = new Vector3(0, 0, 5);

            _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard

            eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png"));
            menu = eng.StateTextureManager.GetTexture("menu");

            saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true));
            saveFont.Options.DropShadowActive = true;

            start_x = saveFont.Measure("Name: ").Width;

            //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true));
            title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true));
            title.Options.DropShadowActive = true;

            name = "";          

            numOfButtons = savedGameChoices.Count - 1;
        }
        internal void RegisterRawDevice(OpenTK.Input.MouseDevice mouse)
        {
            RawInputDevice[] rid = new RawInputDevice[1];
            // Mouse is 1/2 (page/id). See http://www.microsoft.com/whdc/device/input/HID_HWID.mspx
            rid[0]           = new RawInputDevice();
            rid[0].UsagePage = 1;
            rid[0].Usage     = 2;
            rid[0].Flags     = RawInputDeviceFlags.INPUTSINK;
            rid[0].Target    = window;

            if (!Functions.RegisterRawInputDevices(rid, 1, API.RawInputDeviceSize))
            {
                throw new ApplicationException(
                          String.Format(
                              "Raw input registration failed with error: {0}. Device: {1}",
                              Marshal.GetLastWin32Error(),
                              rid[0].ToString())
                          );
            }
            else
            {
                Debug.Print("Registered mouse {0}", mouse.ToString());
                System.Drawing.Point p = new System.Drawing.Point();
                if (Functions.GetCursorPos(ref p))
                {
                    mouse.Position = p;
                }
            }
        }
        public LevelSelect(GameEngine engine) : base(engine)
        {
            eng = engine;
            savedGameStates = new Stack<XmlNodeList>();
            savedGameChoices = new Stack<string>();
            mouse = eng.Mouse;
            // Load all the textures
            eng.StateTextureManager.RenderSetup();
            Assembly assembly = Assembly.GetExecutingAssembly();
            eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png"));
            menu = eng.StateTextureManager.GetTexture("menu");
            eng.StateTextureManager.LoadTexture("arrow", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.arrow.png"));
            arrow = eng.StateTextureManager.GetTexture("arrow");
            eng.StateTextureManager.LoadTexture("load", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_loadlevel.png"));
            load_nopress = eng.StateTextureManager.GetTexture("load");
            eng.StateTextureManager.LoadTexture("loadpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_loadlevel_hover.png"));
            load_press = eng.StateTextureManager.GetTexture("loadpress");
            eng.StateTextureManager.LoadTexture("quit", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_exit.png"));
            quit_nopress = eng.StateTextureManager.GetTexture("quit");
            eng.StateTextureManager.LoadTexture("quitpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_exit_hover.png"));
            quit_press = eng.StateTextureManager.GetTexture("quitpress");
            eng.StateTextureManager.LoadTexture("play", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_play.png"));
            play_nopress = eng.StateTextureManager.GetTexture("play");
            eng.StateTextureManager.LoadTexture("playpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_play_hover.png"));
            play_press = eng.StateTextureManager.GetTexture("playpress");
            eng.StateTextureManager.LoadTexture("ld", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_leveldesign.png"));
            ld_nopress = eng.StateTextureManager.GetTexture("ld");
            eng.StateTextureManager.LoadTexture("ldpress", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.btn_leveldesign_hover.png"));
            ld_press = eng.StateTextureManager.GetTexture("ldpress");

            musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Sound.Retribution.ogg"));
            musicFile.Play();

            // Setup saved game data 
            SavedGameDataSetup();

            // Display available saved game states
            DisplayAvailableSaves();

            // Clear the color to work with the SplashScreen so it doesn't white out
            GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            lookat = new Vector3(0, 0, 2);
            eye = new Vector3(0, 0, 5);

            _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard           

            arX = -150.0f;
            b1Y = 0.0f;
            b2Y = -100.0f;
            b3Y = -200.0f;
            b4Y = -250.0f;

            // TEST //
            enterdown = false;
            LoadSavedState(1);

        }
Exemple #6
0
        public MouseGL3x(MouseDevice mouse)
        {
            _mouse = mouse;

            _mouse.ButtonDown += OpenTKButtonDown;
            _mouse.ButtonUp += OpenTKButtonUp;
            _mouse.Move += OpenTKMove;
        }
 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]);
 }
Exemple #8
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);
 }
Exemple #9
0
 /// <summary>
 /// Creates a new <see cref="InputManager" /> with only basic low-level input support.
 /// </summary>
 /// <remarks>
 /// Creating <see cref="InputManager" /> without a driver container will cause the events
 /// to be useless and never be raised, only the methods on this class will return any useful info.
 /// If you want event support, construct the InputManager with a <see cref="GameWindow" />
 /// or other supported driver providers (NYI).
 /// </remarks>
 public InputManager()
 {
     // We're assigning an empty mouse device.
     // This will make position functions return a constant 0.
     // Instead of being null and causing exceptions.
     _mouse = new MouseDevice();
     // We don't have to assign an empty keyboard device,
     // since we don't have any code that directly relies on it being present.
 }
		public GameWindowMouseInputSource(MouseDevice device, CursorPosSetter cursorPosSetterX, CursorPosSetter cursorPosSetterY)
		{
			this.device = device;
			this.cursorPosSetterX = cursorPosSetterX;
			this.cursorPosSetterY = cursorPosSetterY;

			this.device.Enter += this.device_Enter;
			this.device.Leave += this.device_Leave;
		}
Exemple #11
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];
        }
Exemple #12
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;
 }
Exemple #13
0
        /// <summary>Initializes this mouse object with a pointer to the OpenTK mouse object.</summary>
        /// <param name="mouse">The reference to the OpenTK mouse object.</param>
        public Mouse(MouseDevice mouse)
        {
            _mouse = mouse;
              _stateOne = new bool[_numberOfMouseButtons];
              _stateTwo = new bool[_numberOfMouseButtons];
              _currentState = _stateOne;
              _previousState = _stateTwo;

              // Reset the mouse position
              _previousX = _mouse.X;
              _previousY = _mouse.Y;
        }
Exemple #14
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;
                }
            }

                
        }
        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);
        }
Exemple #16
0
        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 X11Mouse(WindowInfo window)
        {
            this.window = window;

            // Just create one mouse now.
            // TODO: support for multiple devices through evdev.
            // TODO: Should call XSelectInput for mouse pointer events.
            MouseDevice m = new MouseDevice();
            m.Description = "Default X11 mouse";
            m.DeviceID = IntPtr.Zero;
            m.NumberOfButtons = 5;
            m.NumberOfWheels = 1;
            mice.Add(m);
        }
Exemple #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
        }
Exemple #19
0
        /// <summary>
        /// The default Constructor.
        /// </summary>
        public Camera(float prefWidth, float prefHeight, float windowWidth, float windowHeight, MouseDevice m)
        {
            OriginalBounds = CameraBounds = new Polygon();
            TargetScale = Scale = new Vector2(1f, 1f);
            MinimumScale = new Vector2(0.5f, 0.5f);
            MaximumScale = new Vector2(20, 20);
            CameraBox = new Polygon();
            Mouse = m;
            PreferredWidth = prefWidth;
            PreferredHeight = prefHeight;
            UpdateResize(windowWidth, windowHeight);


            UpdateProjectionMatrix();
        }
        public LoadGameState(GameEngine engine, MainMenuState ms)
        {
            eng = engine;
            mouse = eng.Mouse;
            savedGameStates = new Stack<XmlNodeList>();
            savedGameChoices = new Stack<string>();
            _ms = ms;

            Assembly assembly = Assembly.GetExecutingAssembly();
            musicFile = new AudioFile(assembly.GetManifestResourceStream("U5Designs.Resources.Music.Menu.ogg"));
            musicFile.Play();

            // Clear the color to work with the SplashScreen so it doesn't white out
            //GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            lookat = new Vector3(0, 0, 2);
            eye = new Vector3(0, 0, 5);

            _old_state = OpenTK.Input.Keyboard.GetState(); // Get the current state of the keyboard

            eng.StateTextureManager.LoadTexture("menu", assembly.GetManifestResourceStream("U5Designs.Resources.Textures.menu.png"));
            menu = eng.StateTextureManager.GetTexture("menu");

            saveFont = QFont.FromQFontFile("Fonts/myHappySans.qfont", new QFontLoaderConfiguration(true));
            saveFont.Options.DropShadowActive = true;

            //title = QFont.FromQFontFile("myHappySans.qfont", new QFontLoaderConfiguration(true));
            title = QFont.FromQFontFile("Fonts/myRock.qfont", new QFontLoaderConfiguration(true));
            title.Options.DropShadowActive = true;

            saveFontHighlighted = QFont.FromQFontFile("Fonts/myHappySans2.qfont", new QFontLoaderConfiguration(true));
            saveFont.Options.DropShadowActive = true;

            //QFont.CreateTextureFontFiles("Fonts/HappySans.ttf", 48, "myHappySans2");

            // Load available saved games
            // Setup saved game data 
            SavedGameDataSetup();

            numOfButtons = savedGameChoices.Count - 1;
        }
Exemple #21
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;
     }
 }
 public void OnKeyDown(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
     if (e.Key == Key.Escape)
         StateManager.ClearStates();
 }
Exemple #23
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);
        }
Exemple #24
0
 public void OnMouseUp(object sender, MouseEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
Exemple #25
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;
     }
 }
Exemple #26
0
 public virtual void Input_Controller(MouseDevice md, KeyboardDevice kd) { }
 public void OnKeyUp(object sender, KeyboardKeyEventArgs e, KeyboardDevice Keyboard, MouseDevice Mouse)
 {
 }
        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)
 {
 }
Exemple #30
0
 public Mouse(MouseDevice md)
 {
     Cursor = PointerCursor;
     md.Move += (sender, e) => Position = e.Position;
     Tasks.Add(() => drawCursor(Cursor, Position.X, Position.Y));
 }
 /// <summary>This initializes the reference to OpenTK's mouse.</summary>
 /// <param name="mouseDevice">Reference to OpenTK's MouseDevice class within their GameWindow class.</param>
 internal static void InitializeMouse(MouseDevice mouseDevice)
 {
     _mouse = new SevenEngine.Input.Mouse(mouseDevice);
 }
        public int RegisterDevices()
        {
            int count = WinRawInput.DeviceCount;

            RawInputDeviceList[] ridl = new RawInputDeviceList[count];
            for (int i = 0; i < count; i++)
            {
                ridl[i] = new RawInputDeviceList();
            }
            Functions.GetRawInputDeviceList(ridl, ref count, API.RawInputDeviceListSize);

            // Discover mouse devices:
            for (int i = 0; i < count; i++)
            {
                uint size = 0;
                Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, IntPtr.Zero, ref size);
                IntPtr name_ptr = Marshal.AllocHGlobal((IntPtr)size);
                Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICENAME, name_ptr, ref size);
                string name = Marshal.PtrToStringAnsi(name_ptr);
                Marshal.FreeHGlobal(name_ptr);

                if (name.ToLower().Contains("root"))
                {
                    // This is a terminal services device, skip it.
                    continue;
                }
                else if (ridl[i].Type == RawInputDeviceType.MOUSE || ridl[i].Type == RawInputDeviceType.HID)
                {
                    // This is a mouse or a USB mouse device. In the latter case, discover if it really is a
                    // mouse device by qeurying the registry.

                    // remove the \??\
                    name = name.Substring(4);

                    string[] split = name.Split('#');

                    string id_01 = split[0];    // ACPI (Class code)
                    string id_02 = split[1];    // PNP0303 (SubClass code)
                    string id_03 = split[2];    // 3&13c0b0c5&0 (Protocol code)
                    // The final part is the class GUID and is not needed here

                    string findme = string.Format(
                        @"System\CurrentControlSet\Enum\{0}\{1}\{2}",
                        id_01, id_02, id_03);

                    RegistryKey regkey = Registry.LocalMachine.OpenSubKey(findme);

                    string deviceDesc = (string)regkey.GetValue("DeviceDesc");
                    deviceDesc = deviceDesc.Substring(deviceDesc.LastIndexOf(';') + 1);
                    string deviceClass = (string)regkey.GetValue("Class");

                    if (!String.IsNullOrEmpty(deviceClass) && deviceClass.ToLower().Equals("mouse"))
                    {
                        OpenTK.Input.MouseDevice mouse = new OpenTK.Input.MouseDevice();
                        mouse.Description = deviceDesc;

                        // Register the keyboard:
                        RawInputDeviceInfo info = new RawInputDeviceInfo();
                        int devInfoSize         = API.RawInputDeviceInfoSize;
                        Functions.GetRawInputDeviceInfo(ridl[i].Device, RawInputDeviceInfoEnum.DEVICEINFO,
                                                        info, ref devInfoSize);

                        mouse.NumberOfButtons = info.Device.Mouse.NumberOfButtons;
                        mouse.NumberOfWheels  = info.Device.Mouse.HasHorizontalWheel ? 1 : 0;

                        mouse.DeviceID = ridl[i].Device;//(IntPtr)info.Device.Mouse.Id;

                        this.RegisterRawDevice(mouse);
                        mice.Add(mouse);
                    }
                }
            }

            return(count);
        }