Exemplo n.º 1
0
        public static void UpdateInputStates(bool adjustPosition = false)
        {
            if (!inputHandlersReady)
            {
                return;
            }
            prevKeys = currKeys;
            currKeys = KeyboardInputHandler.GetState();



            if (adjustPosition)
            {
                prevMouse = currMouse;
            }
            else
            {
                MouseState newState = new MouseState(prevMouse.X, prevMouse.Y, currMouse.ScrollWheelValue, currMouse.LeftButton, currMouse.MiddleButton, currMouse.RightButton, currMouse.XButton1, currMouse.XButton2);
                prevMouse = newState;
            }
            currMouse    = MouseInputHandler.MouseState;
            currWheelVal = prevMouse.ScrollWheelValue;
            newWheelVal  = currMouse.ScrollWheelValue;
            //if (currWheelVal != newWheelVal)
            //{
            //    if (newWheelVal > currWheelVal)
            //        currWheelVal+= 60/ 6;
            //    else
            //        currWheelVal -= 60 / 6;
            //}
        }
Exemplo n.º 2
0
    private void Start()
    {
        _gamepadInput            = GetComponentInParent <GamepadInputHandler>();
        _gamepadInput.OnAttack  += OnAttack;
        _keyboardInput           = GetComponentInParent <KeyboardInputHandler>();
        _keyboardInput.OnAttack += OnAttack;

        _playerMovement = GetComponentInParent <PlayerMovement>();

        anim = GetComponentInParent <Animator>();
    }
Exemplo n.º 3
0
        public static void UpdateInputStates()
        {
            if (!inputHandlersReady)
            {
                return;
            }

            previousKeys  = currentKeys;
            previousMouse = currentMouse;

            currentKeys  = KeyboardInputHandler.GetState();
            currentMouse = MouseInputHandler.MouseState;
        }
    private void Start()
    {
        canMove                    = true;
        rb                         = GetComponent <Rigidbody>();
        anim                       = GetComponent <Animator>();
        gamepadInput               = GetComponent <GamepadInputHandler>();
        gamepadInput.OnMovement   += OnMove;
        gamepadInput.OnStopMoving += OnStopMoving;

        keyboardInput               = GetComponent <KeyboardInputHandler>();
        keyboardInput.OnMovement   += OnMove;
        keyboardInput.OnStopMoving += OnStopMoving;
    }
Exemplo n.º 5
0
        protected override void Initialize()
        {
            redShip = new Ship(this,graphics,Vector2.Zero);
            redShip.LoadContent(Content, "RedTriangle");

            Vector2 position = new Vector2(200, 200);
            greenShip = new Ship(this, graphics,position);
            greenShip.LoadContent(Content, "GreenTriangle");

            AutoResetEvent autoEvent = new AutoResetEvent(false);
            keyboardInputHandler = new KeyboardInputHandler();
            //TimerCallback tcb = keyboardInputHandler.WriteBuffer;
            //Timer keyboardTimer = new Timer(tcb, autoEvent, 1000, 250);

            base.Initialize();
        }
Exemplo n.º 6
0
    private void Start()
    {
        _inputHandler             = GetComponent <GamepadInputHandler>();
        _inputHandler.OnAPressed += Skip;

        _keyboardInput         = GetComponent <KeyboardInputHandler>();
        _keyboardInput.OnSkip += Skip;

        alphaValue = 0;
        text.GetComponent <CanvasRenderer>().SetAlpha(alphaValue);
        sentencesCounter   = 0;
        fadeInOutDuration *= 60;
        text.text          = sentences[sentencesCounter];
        //textRyhtm = (sentences[sentencesCounter].Length)*2;
        //text.CrossFadeAlpha(1, fadeInOutDuration, false);
        nextSentence = (sentences[sentencesCounter].Length);
    }
    private void Start()
    {
        _gamepadInput                     = GetComponentInParent <GamepadInputHandler>();
        _gamepadInput.OnAttack           += OnAttack;
        _gamepadInput.OnEnterFirstPerson += EnterFP;
        _gamepadInput.OnExitFirstPerson  += ExitFP;
        _gamepadInput.OnTakeAim          += TakeAim;
        _gamepadInput.OnReleaseArrow     += Shoot;

        _keyboardInput                     = GetComponentInParent <KeyboardInputHandler>();
        _keyboardInput.OnAttack           += OnAttack;
        _keyboardInput.OnEnterFirstPerson += EnterFP;
        _keyboardInput.OnExitFirstPerson  += ExitFP;

        _playerMovement = GetComponentInParent <PlayerMovement>();

        anim = GetComponentInParent <Animator>();
    }
Exemplo n.º 8
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            IsMouseVisible    = true;
            TargetElapsedTime = TimeSpan.FromTicks(166666);
            Console.WriteLine("Initializing...");

            var basicGameElementFactory = new BasicGameElementFactory();
            var gameScene = new GameScene(basicGameElementFactory.MakeScene(Content, graphics));

            gameScene.GameManagers.Add(typeof(KeyboardInputManager), new KeyboardInputManager(gameScene.EventAggregator));
            gameScene.GameManagers.Add(typeof(MouseInputManager), new MouseInputManager(gameScene.EventAggregator));

            var keyboardInputHandler = new KeyboardInputHandler(basicGameElementFactory.MakeComponent());

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.Up),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(0, -2, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.Down),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(0, 2, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.Left),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(-2, 0, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.Right),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(2, 0, 0));

            gameScene.EventAggregator.SubsribeEvent(keyboardInputHandler);
            gameScene.GameObjects.First(go => go.Name == "Camera")
            .AddComponent <KeyboardInputHandler>(keyboardInputHandler);

            _sceneManager = new SceneManager(gameScene, Content);

            base.Initialize();
        }
Exemplo n.º 9
0
 public void SetKeyboardInputHandler(KeyboardInputHandler onKeyboardEvent)
 {
   _onKeyboardEvent = onKeyboardEvent;
 }
Exemplo n.º 10
0
 private void Start()
 {
     _playerInput          = GameObject.FindGameObjectWithTag("Player").GetComponent <GamepadInputHandler>();
     _playerKeyboardInput  = GameObject.FindGameObjectWithTag("Player").GetComponent <KeyboardInputHandler>();
     _playerInput.OnPause += OpenCloseMenu;
 }
Exemplo n.º 11
0
        public GameScene(IScene scene) : base(scene)
        {
            var         gameElementFactory = new BasicGameElementFactory();
            IGameObject gameObject         = new BasicGameObject("Mario")
                                             .AddComponent <Transform>(new Transform(gameElementFactory.MakeComponent()))
                                             .AddComponent <Text>(new Text(gameElementFactory.MakeComponent(), "Terminus"))
                                             .AddComponent <Sprite>(new Sprite(gameElementFactory.MakeComponent(), "MarioSprite", 1)) as IGameObject;
            var mouseInputHandler = new MouseInputHandler(gameElementFactory.MakeComponent());

            EventAggregator.SubsribeEvent(mouseInputHandler);
            var mouseWhatever = new MouseState().ScrollWheelValue;

            mouseInputHandler.AddEventListener(mouseState => true, (mouseState, dependencies) =>
            {
                var camera = GameObjects.First(go => go.Name == "Camera").GetComponent <Camera>();
                dependencies.GetComponent <Transform>().Position = new Vector3(camera.ScreenToWorld(mouseState.Position.ToVector2()), 0);
                dependencies.GetComponent <Text>().TextContent   = "Current mouse pos in screen space \nx: " + mouseState.X + "\ny: " + mouseState.Y;
                dependencies.GetComponent <Text>().TextContent  += "\nCurrent camera pos in world space \nx: " +
                                                                   camera.Dependencies.GetComponent <Transform>().Position.X +
                                                                   "\ny: " + camera.Dependencies.GetComponent <Transform>().Position.Y +
                                                                   "\nCurrent mouse pos in world space \nx: " +
                                                                   dependencies.GetComponent <Transform>().Position.X +
                                                                   "\ny: " + dependencies.GetComponent <Transform>().Position.Y;

                var scale = (mouseWhatever - mouseState.ScrollWheelValue) * 0.001f;
                if (Math.Abs(scale) > 0.001f)
                {
                    mouseWhatever = mouseState.ScrollWheelValue;
                    camera.Dependencies.GetComponent <Transform>().Scale += new Vector3(scale, scale, 0);
                }
            }
                                               );
            gameObject.AddComponent <MouseInputHandler>(mouseInputHandler);
            GameObjects.Add(gameObject);

            gameObject = new BasicGameObject("InvertedMario")
                         .AddComponent <Transform>(new Transform(gameElementFactory.MakeComponent(), new Vector3(50, 200, 0), new Vector3(0.5f, 1f, 1f)))
                         .AddComponent <Sprite>(new Sprite(gameElementFactory.MakeComponent(), "InvertedMarioSprite")) as IGameObject;

            var keyboardInputHandler = new KeyboardInputHandler(gameElementFactory.MakeComponent());

            EventAggregator.SubsribeEvent(keyboardInputHandler);
            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.W),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(0, -2, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.S),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(0, 2, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.A),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(-2, 0, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.D),
                (keyboardState, components) => components.GetComponent <Transform>().Position += new Vector3(2, 0, 0));

            keyboardInputHandler.AddEventListener(
                keyboardState => keyboardState.IsKeyDown(Keys.Space),
                (keyboardState, components) => components.GetComponent <Transform>().Rotation *= Matrix.CreateFromYawPitchRoll(0, 0, MathHelper.PiOver4 / 10));

            gameObject.AddComponent <KeyboardInputHandler>(keyboardInputHandler);
            gameObject.GetComponent <Transform>().Rotation = Matrix.CreateFromYawPitchRoll(0, 0, MathHelper.PiOver4);
            GameObjects.Add(gameObject);
            var invertedMario = gameObject;

            gameObject = new BasicGameObject("RedMario")
                         .AddComponent <Transform>(new Transform(gameElementFactory.MakeComponent(), new Vector3(200, 0, 0)))
                         .AddComponent <Sprite>(new Sprite(gameElementFactory.MakeComponent(), "RedMarioSprite", 2)) as IGameObject;
            //gameObject.AddComponent<Transform>(new Transform(new Vector3(100, 0, 0), new Vector3(1, 2, 1), Matrix.CreateFromYawPitchRoll(0, 0, -MathHelper.PiOver2)));gameObject.AddComponent<Transform>(new Transform_	Transform_	()S)_	Transform_<	AddComponent();addcompob
            GameObjects.Add(gameObject);
            gameObject.GetComponent <Transform>().SetTransformParent(invertedMario.GetComponent <Transform>());
        }
Exemplo n.º 12
0
 public ComposeMessage(WindowManager owner, KeyboardInputHandler <UserCommand> keyboardInput, Game game)
     : base(owner, DecorationSize.X + owner.TextFontDefault.Height * 37, DecorationSize.Y + owner.TextFontDefault.Height * 2 + ControlLayout.SeparatorSize * 1, Viewer.Catalog.GetString("Compose Message (e.g.   receiver1, receiver2: message body)"))
 {
     this.keyboardInput = keyboardInput;
     this.game          = game;
 }
Exemplo n.º 13
0
 private void Update()
 {
     MouseInputHandler?.Invoke();
     KeyboardInputHandler?.Invoke();
 }