Exemplo n.º 1
0
        public InputHandler(SFML.Graphics.RenderWindow window)
        {
            //Defining the Commands here
            _go         = new GoCommand();
            _jump       = new JumpCommand();
            turnCommand = new TurnCommand();
            attack      = new AttackCommand();
            //Building the Commandlist
            commandList     = new List <Command>();
            GameCommandList = new List <GameCommand>();
            restartCommand  = new restartCommand();

            //Setup the Joysticksettings
            joystickNr = 0;
            setupJoystick(joystickNr);
            //Setup the Keys of the Keyboard
            setupKeyboard();

            caX   = new CommandAttributes(1);
            caY   = new CommandAttributes(0, 1);
            caXN  = new CommandAttributes(-1);
            caYN  = new CommandAttributes(0, -1);
            timed = new CommandAttributes(Time.FromSeconds(.5f));

            mousePosition = Mouse.GetPosition();
            this.window   = window;
        }
Exemplo n.º 2
0
 private void AddCommandToList(Command item, CommandAttributes ca)
 {
     if (!commandList.Contains(item))
     {
         item.Ca = ca;
         commandList.Add(item);
     }
     else
     {
         Output.Instance.print("Command was not added, because it already exists.");
     }
 }
Exemplo n.º 3
0
        private void HandleKeyboardInput()
        {
            CommandAttributes _temp = new CommandAttributes(0, 0);

            if (KeyDown(leftKey))
            {
                _temp.Add(new Vector2f(-1, 0));
            }
            if (KeyDown(rightKey))
            {
                _temp.Add(new Vector2f(1, 0));
            }
            if (KeyDown(jumpKey))
            {
                AddCommandToList(_jump, caX);
            }
            if (KeyDown(upKey))
            {
                _temp.Add(new Vector2f(0, -1));
            }
            if (KeyDown(downKey))
            {
                _temp.Add(new Vector2f(0, 1));
            }
            if (_temp.IsValid())
            {
                _temp.Normalize();
                AddCommandToList(_go, _temp);
            }
            if (MousePositionChanged())
            {
                Vector2f          worldPos = window.MapPixelToCoords(new Vector2i(mousePosition.X, mousePosition.Y));
                CommandAttributes _ca      = new CommandAttributes(worldPos.X, worldPos.Y);
                AddCommandToList(turnCommand, _ca);
            }
            if (mouseButtonDown(leftClick))
            {
                AddCommandToList(attack, timed);
            }
            if (KeyDown(escKey))
            {
                System.Environment.Exit(0);
            }
            if (KeyDown(rKey))
            {
                AddCommandToGameCommandList(restartCommand);
            }
        }
Exemplo n.º 4
0
        private void HandleJoystickInput()
        {
            if (joystickConnected)
            {
                //Always update the Joystick (otherwise it doesn't work.)
                Joystick.Update();
                //Check for the Buttons to be pressed
                if (Joystick.IsButtonPressed(joystickNr, jumpJoy))
                {
                    AddCommandToList(_jump, caX);
                }
                if (Joystick.IsButtonPressed(joystickNr, attackJoy))
                {
                    AddCommandToList(attack, timed);
                }
                if (Joystick.IsButtonPressed(joystickNr, altAttackJoy))
                {
                    //CommandAttributes _t = new CommandAttributes(1, false);

                    //AddCommandToList(attack, _t);
                }
                float _axisDirection  = axisDirection(runAxis);
                float _axisDirectionY = axisDirection(upAxis);

                if (Math.Abs(_axisDirection) > threshold || Math.Abs(_axisDirectionY) > threshold)
                {
                    CommandAttributes _ca = new CommandAttributes(_axisDirection / 100, _axisDirectionY / 100);
                    AddCommandToList(_go, _ca);
                }

                float _axisRightL = axisDirection(rightAxisL);
                float _axisRightU = axisDirection(rightAxisU);
                if (Math.Abs(_axisRightU) > 50 || Math.Abs(_axisRightL) > 50)
                {
                    Vector2f          worldPos = window.MapPixelToCoords(new Vector2i((int)(_axisRightL + window.DefaultView.Size.X / 2), (int)(_axisRightU + window.DefaultView.Size.Y / 2)));
                    CommandAttributes _ca      = new CommandAttributes(worldPos.X, worldPos.Y);

                    AddCommandToList(turnCommand, _ca);
                }
                if (Joystick.IsButtonPressed(0, 14))
                {
                    AddCommandToGameCommandList(restartCommand);
                }
                JoystickDebug();
            }
        }