Exemplo n.º 1
0
        public bool HandleInput(InputState inputState, IMap map) {
            var potential_new_x = X;
            var potential_new_y = Y;
            bool trying_to_move = false;

            if (inputState.IsLeft(PlayerIndex.One)) {
                potential_new_x = X - speed;
                trying_to_move = true;
            } else if (inputState.IsRight(PlayerIndex.One)) {
                potential_new_x = X + speed;
                trying_to_move = true;
            } else if (inputState.IsUp(PlayerIndex.One)) {
                potential_new_y = Y - speed;
                trying_to_move = true;
            } else if (inputState.IsDown(PlayerIndex.One)) {
                potential_new_y = Y + speed;
                trying_to_move = true;
            }


            if (trying_to_move) {
                if (map.IsWalkable(potential_new_x, potential_new_y)) {
                    var enemy = Global.CombatManager.EnemyAt(potential_new_x, potential_new_y);
                    if (enemy == null) {
                        X = potential_new_x;
                        Y = potential_new_y;
                    } else {
                        Global.CombatManager.Attack(this, enemy);
                    }

                    return true;
                }
            }
            return false;
        }
Exemplo n.º 2
0
        public Game1() {
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferHeight = Global.MapHeight * Global.SpriteWidth;
            graphics.PreferredBackBufferWidth = Global.MapWidth * Global.SpriteWidth;
            graphics.ApplyChanges();

            _inputState = new InputState();

            Content.RootDirectory = "Content";
        }
Exemplo n.º 3
0
        // Move the camera's position based on input
        public void HandleInput(InputState inputState, PlayerIndex? controllingPlayer) {
            Vector2 cameraMovement = Vector2.Zero;

            if (inputState.IsScrollLeft(controllingPlayer)) {
                cameraMovement.X = -1;
            } else if (inputState.IsScrollRight(controllingPlayer)) {
                cameraMovement.X = 1;
            }
            if (inputState.IsScrollUp(controllingPlayer)) {
                cameraMovement.Y = -1;
            } else if (inputState.IsScrollDown(controllingPlayer)) {
                cameraMovement.Y = 1;
            }
            if (inputState.IsZoomIn(controllingPlayer)) {
                AdjustZoom(0.25f);
            } else if (inputState.IsZoomOut(controllingPlayer)) {
                AdjustZoom(-0.25f);
            }

            // to match the thumbstick behavior, we need to normalize non-zero vectors in case the user
            // is pressing a diagonal direction.
            if (cameraMovement != Vector2.Zero) {
                cameraMovement.Normalize();
            }

            // scale our movement to move 25 pixels per second
            cameraMovement *= 25f;

            // move the camera
            MoveCamera(cameraMovement, true);
        }