Open the starting file in your OneDrive > COMP 8 > GameMaker folder – it will contain all the starting sprites and objects. You can be in Simple Mode for this game.
Bat Right Moving
The right player will use the Up & Down arrow keys to move the right bat up & down.
Go into the object bat_right. Add an <Up> Keyboard event…
- Jump to Position: (0,-7), relative
negative y coordinate means going upwards
Then add the <Down> Keyboard event…
- Jump to Position: (0,7), relative
positive y coordinate means going down
Now add a Collision with wall event, and have it bounce so the bat can’t leave the room.
- Bounce (against all objects)
Bat Left Moving
The left player will use the “W” & “S” keys to move the left bat up & down.
Go into the bat_left object. Add the W-key event (under Keyboard > Letters)…
- Jump to Position: (0,-7), relative
negative y coordinate means going upwards
Then add the S-key Keyboard event…
- Jump to Position: (0,7), relative
positive y coordinate means going down
Now add a Collision with wall event, and have it bounce so the bat can’t leave the room.
- Bounce (against all objects)
Save your game/file, then test it out. Make sure the bats are moving and staying the room.
Ball Moving
Go into the ball object.
- Create event – when the room loads we want it to move diagonally…
- Move Fixed: set it to the 4 corner directions, speed 8
Ball Bouncing
Make sure the ball bounces off the wall and the bats…
- Collision with wall event
- Bounce (against all objects)
- Collision with bat_left:
- Bounce (precisely, against all objects)
- Collision with bat_right
- Bounce (precisely, against all objects)
Left Playing scoring
Now we’ll make sure that if it leaves the room, instead of disappearing, the ball will go back to its starting position…
Still in the ball object, add Collision with score_left:
- Sleep – makes the game pause a bit before it restarts (leave at default)
- Jump to Start
- Set Score – give the player 1 pt, make sure it’s relative
Right Player Scoring
The Collision with score_right event is the same as the previous one, except we will use the Set Lives action to keep track of the right player’s points/score…
Start the Game at Zero
We need to make sure the score is zero every time the game starts, so in the ball object’s Create event, add the following actions:
- Set Score to 0, not relative
- Set Lives to 0, not relative
Draw the Score
Go into the object scores and add a Draw event with the following actions…
- Draw Text: “PLAYER LEFT” (all caps), X=50, Y=30
- Draw Text: “PLAYER RIGHT” (all caps), X=400, Y=30
- Draw Score: (100,60), delete the caption
- Draw Lives: (450,60), delete the caption
Play the Game
Save your game/file, then test it out.
Keep it open in playing mode. Play it for a bit so I can see the score shows up and is working…