Exemple #1
0
 public void Hit_ReflectOffNormal(Player player, InputData inputData, InputSettings inputSettings)
 {
     Vector2 normal = new Vector2(inputData.xValue, inputData.yValue);
     if (Vector2.Dot(normal, Velocity) < 0)
     {
         // Indicates the ball is going towards normal surface
         Velocity = Vector2.Reflect(Velocity, normal);
         //lastPlayerToHit = player;
     }
 }
        public void MainClick_Down(Object sender, InputData inputData, InputSettings inputSettings)
        {
            // Test to see if the player is inbound

            foreach (ICollidable movable in collisionManager.Movables)
            {
                if (movable is Ball)
                    ((Ball)movable).Hit((Player)sender, inputData, inputSettings);
            }

            //Console.WriteLine("In Click Down event");
        }
Exemple #3
0
 public void Hit(Player player, InputData inputData, InputSettings inputSettings)
 {
     if (lastPlayerToHit == player)
     {
         return;
     }
     else if (inputSettings.timeSinceLastInput >= inputSettings.InputDelay)
     {
         lastPlayerToHit = player;
         inputSettings.ResetDelay();
         switch (inputSettings.ballHitMethod)
         {
             case InputSettings.BallHitMethod.SetVelocity:
                 Hit_SetVelocity(player, inputData, inputSettings);
                 break;
             case InputSettings.BallHitMethod.ReflectOffNormal:
                 Hit_ReflectOffNormal(player, inputData, inputSettings);
                 break;
         }
     }
 }
 public void SecondaryClick_Down(Object sender, InputData inputData, InputSettings inputSettings)
 {
     Console.WriteLine("In Secondary Down event");
 }
Exemple #5
0
 public void Hit_SetVelocity(Player player, InputData inputData, InputSettings inputSettings)
 {
     Vector2 newVelocity = new Vector2(inputData.xValue, inputData.yValue);
     Velocity = newVelocity * inputSettings.ballVelocity;
     lastPlayerToHit = player;
 }
Exemple #6
0
            /// <summary>
            /// Returns the mouse state in the form of InputData
            /// Sets x and y based on the angle it makes with a fixed out
            /// </summary>
            /// <param name="data"></param>
            /// <param name="settings"></param>
            /// <returns></returns>
            private static InputData GetMouseInput(InputData data, InputSettings settings)
            {
                InputData newData = new InputData();
                MouseState mouseState = Mouse.GetState();

                if (mouseState.LeftButton == ButtonState.Pressed)
                    newData.mainButtonDown = true;
                if (mouseState.RightButton == ButtonState.Pressed)
                    newData.secondaryButtonDown = true;
                if (mouseState.XButton2 == ButtonState.Pressed)
                    newData.leftButtonDown = true;
                if (mouseState.XButton1 == ButtonState.Pressed)
                    newData.rightButtonDown = true;

                //TODO: Set x and y values off settings (vector from fixed point)
                Vector2 mouseDir = new Vector2(mouseState.X - settings.mouseOriginOfRotation.X,
                    mouseState.Y - settings.mouseOriginOfRotation.Y);
                mouseDir.Normalize();

                newData.xValue = mouseDir.X;
                newData.yValue = mouseDir.Y;

                return newData;
            }
Exemple #7
0
            /// <summary>
            /// Uses the data and settings to return the correct input state
            /// </summary>
            /// <param name="data"></param>
            /// <param name="settings"></param>
            /// <returns></returns>
            private static InputData GetGamePadInput(InputData data, InputSettings settings)
            {

                InputData newData = new InputData();
                GamePadState padState = GamePad.GetState(settings.playerIndex, GamePadDeadZone.Circular);

                if (padState.IsButtonDown(Buttons.A))
                    newData.mainButtonDown = true;
                if (padState.IsButtonDown(Buttons.B))
                    newData.secondaryButtonDown = true;
                if (padState.IsButtonDown(Buttons.LeftShoulder))
                    newData.leftButtonDown = true;
                if (padState.IsButtonDown(Buttons.RightShoulder))
                    newData.rightButtonDown = true;

                newData.xValue = padState.ThumbSticks.Left.X * -1;
                newData.yValue = padState.ThumbSticks.Left.Y;

                return newData;                    
            }
Exemple #8
0
 /// <summary>
 /// Returns the input state based on the type of controller
 /// </summary>
 /// <param name="data"></param>
 /// <param name="settings"></param>
 /// <returns></returns>
 public static InputData GetInputData(InputData data, InputSettings settings)
 {
     switch (settings.inputType)
     {
         case InputType.GamePad:
             return GetGamePadInput(data, settings);                        
         case InputType.Mouse:
             return GetMouseInput(data, settings);
         default:
             throw new Exception();
     }                
 }
Exemple #9
0
 public Player(InputSettings settings)
 {
     inputSettings = settings;
     inputData = new InputData();
 }