# Adding Multiple Players

### Introduction

Beefball is intended to be a competitive multiplayer game. So far we only have one PlayerBall instance, so let's add some more PlayerBall instances. Previously we added a list for our PlayerBall. We can now add a second PlayerBall with minimal changes to our project.

### Adding a new PlayerBall

To add a new PlayerBall:

1. Expand the GameScreen's Objects folder
2. Select the PlayerBallList object
3. Select the **Quick Actions** tab
4. Click the **Add a new PlayerBall to PlayerBallList**. Alternatively, you can right-click on the PlayerBallList and select Add Object

<figure><img src="/files/ukX18XPvS1dLU9sdkBcT" alt=""><figcaption></figcaption></figure>

5. Change the new PlayerBall's X value to 180

   ![](/files/A6gaJQ8Kf3aTgUs2sjiA)

You should now see two PlayerBall instances under the PlayerBallList and in game. Also, since we created our collision relationships between the lists, the new PlayerBall can already collide against the walls and the Puck.

<figure><img src="/files/1JLIaAgUKTECtHZ3dm5T" alt=""><figcaption></figcaption></figure>

### Player vs. Player collision

Now that we have two PlayerBall instances, we need to add a new collision relationship. This time, we will create a collision relationship between the PlayerBallList vs itself. To do this:

1. Select the **PlayerBallList**
2. Select the **Collision** tab
3. Find the **PlayerBallList** in the list of items
4. Click the **Add** button
5. Set **Collision Physics** to **Bounce**

<figure><img src="/files/hmeA03X7Uo79jNMVYNMc" alt=""><figcaption></figcaption></figure>

If you run you game now, the two PlayerBall instances collide against each other. Also, if we added more players (a third or fourth player) those would also collide with each other automatically.

### Adding input for Player 2

We'll assign input on PlayerBall2Instance with code similar to the input-assigning code for PlayerBallInstance. To do this, open **GameScreen.cs** and modify AssignInput as shown in the following code:

```csharp
private void AssignInput()
{
    if (InputManager.Xbox360GamePads[0].IsConnected)
    {
        PlayerBall1.MovementInput =
            InputManager.Xbox360GamePads[0].LeftStick;
        PlayerBall1.BoostInput =
            InputManager.Xbox360GamePads[0].GetButton(Xbox360GamePad.Button.A);
    }
    else
    {
        PlayerBall1.MovementInput =
            InputManager.Keyboard.Get2DInput(Microsoft.Xna.Framework.Input.Keys.A,
            Microsoft.Xna.Framework.Input.Keys.D,
            Microsoft.Xna.Framework.Input.Keys.W,
            Microsoft.Xna.Framework.Input.Keys.S);
        PlayerBall1.BoostInput =
            InputManager.Keyboard.GetKey(Microsoft.Xna.Framework.Input.Keys.B);
    }

    if (InputManager.Xbox360GamePads[1].IsConnected)
    {
        PlayerBall2.MovementInput =
            InputManager.Xbox360GamePads[1].LeftStick;
        PlayerBall2.BoostInput =
            InputManager.Xbox360GamePads[1].GetButton(Xbox360GamePad.Button.A);
    }
    else
    {
        PlayerBall2.MovementInput =
            InputManager.Keyboard.Get2DInput(Microsoft.Xna.Framework.Input.Keys.Left,
            Microsoft.Xna.Framework.Input.Keys.Right,
            Microsoft.Xna.Framework.Input.Keys.Up,
            Microsoft.Xna.Framework.Input.Keys.Down);
        PlayerBall2.BoostInput = 
            InputManager.Keyboard.GetKey(Microsoft.Xna.Framework.Input.Keys.RightShift);
    }
}
```

Now each PlayerBall uses a different Xbox360GamePad or set of keys.

### Conclusion

Now that we have multiple PlayerBall instances, we have a game that is playable, but it's missing scoring and game rules. The next tutorial adds the ability to score goals.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.flatredball.com/flatredball/tutorials/beefball/adding-multiple-players.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
