/// <summary>
        /// Check if networkinputcomponent's parameters are true and do actions on remote player
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="playerEntity"></param>
        private void ParseNetworkInput(GameTime gameTime, Entity playerEntity)
        {
            NetworkInputComponent networkInputComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <NetworkInputComponent>(playerEntity);
            VelocityComponent     velocityComponent     = ComponentManager.Instance.ConcurrentGetComponentOfEntity <VelocityComponent>(playerEntity);
            TransformComponent    transformComponent    = ComponentManager.Instance.ConcurrentGetComponentOfEntity <TransformComponent>(playerEntity);
            GravityComponent      gravityComponent      = ComponentManager.Instance.ConcurrentGetComponentOfEntity <GravityComponent>(playerEntity);

            if (networkInputComponent.MoveForward)
            {
                PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveLeft)
            {
                PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveRight)
            {
                PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent);
            }
            if (networkInputComponent.Jump)
            {
                PlayerActions.PlayerJump(gameTime, velocityComponent);
            }
            if (networkInputComponent.MoveBackward)
            {
                PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent);
            }
        }
Example #2
0
        /*
         * Gets player keyboard input and takes appropriate action.
         */
        public void ParsePlayerInput(GameTime gameTime, Entity playerEntity)
        {
            VelocityComponent velocityComponent = componentManager.ConcurrentGetComponentOfEntity <VelocityComponent>(playerEntity);
            KeyboardComponent keyboardComponent = componentManager.ConcurrentGetComponentOfEntity <KeyboardComponent>(playerEntity);
            GamePadComponent  gamePadComponent  = componentManager.ConcurrentGetComponentOfEntity <GamePadComponent>(playerEntity);
            GravityComponent  gravityComponent  = componentManager.ConcurrentGetComponentOfEntity <GravityComponent>(playerEntity);

            /* Keyboard actions */
            if (keyboardComponent != null && velocityComponent != null)
            {
                KeyboardState state = Keyboard.GetState();

                if (state.IsKeyDown(Keys.Up) && !state.IsKeyDown(Keys.Down))
                {
                    PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent);
                }
                if (state.IsKeyDown(Keys.Down) && !state.IsKeyDown(Keys.Up))
                {
                    PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent);
                }

                if (state.IsKeyDown(Keys.Left) && !state.IsKeyDown(Keys.Right))
                {
                    PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent);
                }
                if (state.IsKeyDown(Keys.Right) && !state.IsKeyDown(Keys.Left))
                {
                    PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent);
                }
                if (state.IsKeyDown(Keys.Space))
                {
                    if (!gravityComponent.HasJumped)
                    {
                        PlayerActions.PlayerJump(gameTime, velocityComponent, playerEntity);
                        gravityComponent.HasJumped = true;
                    }
                }
            }
            #region
            /* Gamepad actions */
            if (gamePadComponent != null && velocityComponent != null)
            {
                GamePadState state = GamePad.GetState(gamePadComponent.Index);

                if (state.IsButtonDown(Buttons.A) && !state.IsButtonDown(Buttons.B))
                {
                    PlayerActions.AcceleratePlayerForwards(gameTime, velocityComponent);
                }
                if (state.IsButtonDown(Buttons.B) && !state.IsButtonDown(Buttons.A))
                {
                    PlayerActions.AcceleratePlayerBackwards(gameTime, velocityComponent);
                }
                if (state.IsButtonDown(Buttons.LeftThumbstickLeft) && !state.IsButtonDown(Buttons.LeftThumbstickRight))
                {
                    PlayerActions.AcceleratePlayerLeftwards(gameTime, velocityComponent);
                }
                if (state.IsButtonDown(Buttons.LeftThumbstickRight) && !state.IsButtonDown(Buttons.LeftThumbstickLeft))
                {
                    PlayerActions.AcceleratePlayerRightwards(gameTime, velocityComponent);
                }
                if (state.IsButtonDown(Buttons.Y) && !state.IsButtonDown(Buttons.A))
                {
                    if (!gravityComponent.HasJumped)
                    {
                        PlayerActions.PlayerJump(gameTime, velocityComponent, playerEntity);
                        gravityComponent.HasJumped = true;
                    }
                }
            }
            #endregion
        }