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.
To add a new PlayerBall:
Expand the GameScreen's Objects folder
Select the PlayerBallList object
Select the Quick Actions tab
Click the Add a new PlayerBall to PlayerBall List. Alternatively, you can right-click on the PlayerBallList and select Add Object
Change the new PlayerBall's X value to 180
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.
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:
Select the PlayerBallList
Select the Collision tab
Find the PlayerBallList in the list of items
Click the Add button
Set Collision Physics to Bounce
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.
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:
Now each PlayerBall uses a different Xbox360GamePad or set of keys.
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.