Multiplayer
Activity
Go to Activity: Multiplayer. Complete student tasks 2-5.
Tasks
Task 2
- Create a function called newBall.
- Set currentBall to a sprite with an image of a ball; assign it of kind Ball.
- Give the ball a vx of either -75 or 75, with a 50 % chance of each (use an if then ... else block to handle this).
- Give the ball a random vy between -75 and 75.
- Create a newball when the game starts.
- Comment your code.
Shared project link:
Task 3
- Place an if then ... else if then block inside of on game update.
- First, check if currentBall‘s y position is less than or equal to 0
- If it is, set currentBall‘s y position to 0 set currentBall‘s vy to its current vy multiplied by -1
- Next, check if currentBall‘s y position is greater than or equal to screen height.
- If it is, set currentBall‘s y position to screen height set currentBall‘s vy to its current vy multiplied by -1
- Comment your code.
Shared project link:
Task 4
- Add another if then ... else then block inside on game update.
- If the currentBall‘s x position is greater than screen width, then destroy the currentBall, increase player one’s score by 1, create a newBall.
- Otherwise, if the currentBall‘s x position is less than 0, then destroy the currentBall, increase player two’s score by 1, create a newBall.
- In on start, set players one and two’s score to start at 0.
- Add comments to your code.
Shared project link:
Task 5
Shared project link:
- Create an on overlap event between a Player and a Ball, so that sprite corresponds to the Player.
- Reverse the Ball‘s vx by setting it to the current vx multiplied by -1.
- Comment your code.
Shared project link:
Task 5 Challenge
- When reversing the Ball‘s vx, multiply the current vx by -1.1 instead of -1 on each volley.
- Add change otherSprite vy by 0 to change the vertical speed of the Ball when it collides with a paddle. Replace the 0 with sprite vy multiplied by 0.33.
Shared project link:
Extension
- Use JavaScript or Python to create this project.
- How might you improve game play? Modify your game accordingly.
Shared project link:
Reflection/Homework
How does having multiple players at once in a single game allow for new and compelling games?
Were there any difficulties in implementing the multiplayer game? Was it easier or harder than a single player game?
How might/did you debug your code?