Beispiel #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;
     }
 }
Beispiel #2
0
 public InputData(InputData input)
 {
     this.previousData = null;
     this.mainButtonDown = input.mainButtonDown;
     this.secondaryButtonDown = input.secondaryButtonDown;
     this.leftButtonDown = input.leftButtonDown;
     this.rightButtonDown = input.rightButtonDown;
     this.xValue = input.xValue;
     this.yValue = input.yValue;     
 }
        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");
        }
Beispiel #4
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;
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Updates the list of button changes and button states
        /// </summary>
        /// <param name="newInput"></param>
        public void Update(InputData newInput, Player player)
        {                   
            // Change the members to that of newInput
            this.previousData = new InputData(this);

            mainButtonDown = newInput.mainButtonDown;
            secondaryButtonDown = newInput.secondaryButtonDown;
            leftButtonDown = newInput.leftButtonDown;
            rightButtonDown = newInput.rightButtonDown;
            xValue = newInput.xValue;
            yValue = newInput.yValue;
            
            
            if (!previousData.mainButtonDown && mainButtonDown)            
                player.OnMainDown();
            
            if (!previousData.secondaryButtonDown && secondaryButtonDown)
                player.OnSecondaryDown();
            if (!previousData.leftButtonDown && leftButtonDown)
                player.OnLeftDown();
            if (!previousData.rightButtonDown && rightButtonDown)
                player.OnRightDown();
        }        
 public void SecondaryClick_Down(Object sender, InputData inputData, InputSettings inputSettings)
 {
     Console.WriteLine("In Secondary Down event");
 }
Beispiel #7
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;
 }
Beispiel #8
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;
            }
Beispiel #9
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;                    
            }
Beispiel #10
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();
     }                
 }
Beispiel #11
0
 public Player(InputSettings settings)
 {
     inputSettings = settings;
     inputData = new InputData();
 }