private void HandleMouseMovement()
        {
            MouseState state = Mouse.GetState();

            Point point = new Point(state.X, state.Y);

            if (AllowInput())
            {
                Point delta = new Point(_mouseLast.X - point.X, _mouseLast.Y - point.Y);

                Camera.yaw   -= delta.X / 1000f * _sensitivity;
                Camera.pitch -= delta.Y / 1000f * _sensitivity;

                //ResetMouse();

                if (KeyboardState.IsKeyDown(Key.Space) && !_wasSpaceDown && Player.onGround)
                {
                    _wasSpaceDown   = true;
                    Player.Motion.Y = 0.475F;
                }
                else if ((!KeyboardState.IsKeyDown(Key.Space) || Player.onGround) && _wasSpaceDown)
                {
                    _wasSpaceDown = false;
                }
            }

            _mouseLast = point;
        }
示例#2
0
    private void UpdateInput()
    {
        MouseState mouseState = Mouse.GetCursorState();

        OpenTK.Point mousePos = this.PointToClient(new OpenTK.Point(mouseState.X, mouseState.Y));

        // Now use our point definition
        Point adjustedMousePoint = new Point();

        adjustedMousePoint.X = (float)mousePos.X - ((float)ClientSize.Width / 2);
        adjustedMousePoint.Y = ((float)ClientSize.Height / 2) - (float)mousePos.Y;

        _input.MousePosition = new Point(adjustedMousePoint.X, adjustedMousePoint.Y);
    }
        public void LoadWorld(string saveName)
        {
            if (World != null)
            {
                return;
            }

            ParticleRenderer = new ParticleRenderer();
            SkyboxRenderer   = new SkyboxRenderer();

            World loadedWorld = WorldLoader.LoadWorld(saveName);

            if (loadedWorld == null)
            {
                Console.WriteLine("DEBUG: generating World");

                BlockPos playerPos = new BlockPos(MathUtil.NextFloat(-100, 100), 10, MathUtil.NextFloat(-100, 100));

                World = new World("MyWorld", "Tomlow's Fuckaround",
                                  SettingsManager.GetValue("worldseed").GetHashCode());

                Player = new EntityPlayerSP(World, playerPos.ToVec());

                World.AddEntity(Player);

                Player.SetItemStackInInventory(0, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockCraftingTable>())));
                Player.SetItemStackInInventory(1, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockFurnace>())));
                Player.SetItemStackInInventory(2, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockCobbleStone>())));
                Player.SetItemStackInInventory(3, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockPlanks>())));
                Player.SetItemStackInInventory(4, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockGlass>())));
                Player.SetItemStackInInventory(5, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockCraftingTable>())));
                Player.SetItemStackInInventory(6, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockSlab>())));
                Player.SetItemStackInInventory(7, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockLadder>())));
                Player.SetItemStackInInventory(8, new ItemStack(new ItemBlock(BlockRegistry.GetBlock <BlockTallGrass>())));
            }
            else
            {
                World = loadedWorld;
            }

            ResetMouse();

            MouseState state = OpenTK.Input.Mouse.GetState();

            _mouseLast = new Point(state.X, state.Y);
        }
        public void OpenGuiScreen(GuiScreen guiScreen)
        {
            if (guiScreen == null)
            {
                CloseGuiScreen();
                return;
            }

            GuiScreen = guiScreen;

            if (guiScreen.DoesGuiPauseGame)
            {
                IsPaused = true;
            }

            Point middle = new Point(ClientRectangle.Width / 2, ClientRectangle.Height / 2);

            middle = PointToScreen(middle);

            OpenTK.Input.Mouse.SetPosition(middle.X, middle.Y);
        }
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            base.OnMouseDown(e);

            if (e.IsPressed)
            {
                if (GuiScreen == null)
                {
                    GetMouseOverObject();

                    //pickBlock
                    if (e.Button == MouseButton.Middle)
                    {
                        Player?.PickBlock();
                    }

                    //place/interact
                    if (e.Button == MouseButton.Right || e.Button == MouseButton.Left)
                    {
                        _interactionTickCounter = 0;
                        Player?.OnClick(e.Button);
                    }
                }
                else
                {
                    MouseState state = OpenTK.Input.Mouse.GetCursorState();
                    Point      point = PointToClient(new Point(state.X, state.Y));

                    GuiScreen.OnMouseClick(point.X, point.Y, e.Button);
                }

                if (!_mouseButtonsDown.Contains(e.Button))
                {
                    _mouseButtonsDown.Add(e.Button);
                }
            }
        }
示例#6
0
 public static void Viewport(OpenTK.Point location, OpenTK.Size size)
 {
     GL.Viewport(location.X, location.Y, size.Width, size.Height);
 }
示例#7
0
 private void MoveWindowsCommand(object sender, MoveWindowEventArgs e)
 {
     Location = new OpenTK.Point(e.X, e.Y);
 }
        private void ResetMouse()
        {
            Point middle = PointToScreen(new Point(ClientSize.Width / 2, ClientSize.Height / 2));

            OpenTK.Input.Mouse.SetPosition(middle.X, middle.Y);
        }