Ejemplo n.º 1
0
        public Game1()
        {
            graphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                IsFullScreen       = true,
                HardwareModeSwitch = false
            };

            IsMouseVisible           = false;
            Window.AllowUserResizing = false;

            keyboardInputHelper = new KeyboardInputHelper();
            mouseInputHelper    = new MouseInputHelper();
            inputHelper         = new InputHelper(keyboardInputHelper, mouseInputHelper);

            Content.RootDirectory = "Content";
            Camera = new Camera();

            player = new Player();

            var cells = new WorldCell[Constants.WorldWidth, Constants.WorldHeight];

            for (var x = 0; x < Constants.WorldWidth; x++)
            {
                for (var y = 0; y < Constants.WorldHeight; y++)
                {
                    var cellCenterPosition = new Position(Constants.WorldCellWidth * x, Constants.WorldCellHeight * y);
                    var cell = new WorldCell(cellCenterPosition);
                    cells[x, y] = cell;
                }
            }

            world = new World(cells);
        }
            /// <summary>
            /// Presses a button on the mouse.
            /// </summary>
            /// <param name="key">The mouse button to press.</param>
            /// <param name="state">The new state of the mouse button.</param>
            /// <param name="useMouseEvent">Determines whether to use the mouse_event API or not.</param>
            /// <returns>Returns true on success.</returns>
            public static bool Press(Keys key, KeyStates state, bool useMouseEvent = false)
            {
                if (ValidationHelper.IsKeyOutOfRange(key))
                {
                    ThrowHelper.ArgumentOutOfRangeException(nameof(key));
                }
                if (ValidationHelper.IsKeyStatesOutOfRange(state))
                {
                    ThrowHelper.ArgumentOutOfRangeException(nameof(state));
                }

                return(useMouseEvent
                                        ? MouseInputHelper.SendMouseEvent(key, state)
                                        : MouseInputHelper.SendMouseInput(key, state));
            }
 /// <summary>
 /// Moves the mouse to a specific coordinate on the screen or relative by an amount of pixels.
 /// </summary>
 /// <param name="x">The absolute x-coordinate of the mouse or a relative amount of pixels.</param>
 /// <param name="y">The absolute y-coordinate of the mouse or a relative amount of pixels.</param>
 /// <param name="relative">Determines whether the coordinates are absolute.</param>
 /// <param name="useMouseEvent">Determines whether to use the mouse_event API or not.</param>
 /// <returns>Returns true on success.</returns>
 public static bool Move(int x, int y, bool relative = false, bool useMouseEvent = false)
 {
     return(useMouseEvent
                             ? MouseInputHelper.SendMouseMoveEvent(x, y, relative)
                             : MouseInputHelper.SendMouseMoveInput(x, y, relative));
 }