Tutorial:  Pong
Copyright 2008, WPI
First Version created by Eric Sutman
Subsequent versions modified by Mark Claypool
Version 1.3

Task - Create a simple 2-player Pong from scratch using Game Maker

Getting Started

We’ll assume you are familiar with the classic game Pong.  If not, go surf the Web and find an online/Web-based version to try out.  This tutorial also assumes you have done at least one Game Maker tutorial, such as “Your First Game” where you click on the clown in a game of “Catch the Clown”.  If not, go do that tutorial. Once ready:
1)	Open up Game Maker
2)	Save a blank file as “Pong.gmk” in your home directory (or desktop) by selecting FileSave As to make it easier to save later on.

Creating Sprites

Pong is not a game known for its graphics (no 3d rendered graphics here), hence a good choice for a game to make from scratch in a few hours.  However, even Pong needs some graphics, no matter how simple they are.  With many game engines, including Game Maker, often graphics can be drawn in another tool and imported.  However, since Pong's graphics are so simple, it's just as easy to create them with Game Maker's built-in paint program.

Ball
To create our (ironically-shaped) square ball:
1)	Right-clicking on the Sprites folder and select Add Sprite.  
2)	In the Sprite Properties window that pops up, name the sprite “spr_Ball”.  
3)	We'll also need to unclick the Transparent check box in the lower left of the window.  We'll deal with transparencies plenty in later labs.  
4)	Just above the Transparent check box, click Edit Sprite. 
5)	When Sprite Editor window appears, select FileNew.  
6)	Input 16 in both fields and click Ok.  Double-click on the newly created sprite (probably called “image0”).  
7)	From here enter the Image Editor, which is a fairly generic painting program.  Use the Fill Bucket to paint the block white
8)	Click the Ok check at the left of the top toolbar
9)	And again for the Sprite Editor and the Sprite Properties windows.

Red versus Blue
We're going to:
1)	Create 2 more sprites, using the exact same steps as we did with the ball, only this time, instead of making them white, make them red and blue. If really wanted, make them blue or green or mauve electric sunshine orange, but the point is they aren't black or white.
2)	Name one of them “spr_Wall” and the other “spr_Goal”.  
As you may have already guessed, these sprites will be used for the wall and goal objects of the game.  They won't be visible in-game, but will be when placed in our level (room).

Paddle
To create the paddle:
1)	Use a process similar to the one used to create the ball.  The only difference for this sprite is that when you put in a size for the sprite, put in 16 for width, and 64 for height.

Tip! Before moving on, click the Save button (the disk in the top toolbar), just as a safety.  In general, it is a good idea to save your work often, in case of a computer crash or in case you accidentally close Game Maker.  You might even rename your previously saved games with a version number (i.e. “Pongv0.1.gm6”).

Creating Objects

Getting the Ball Rolling
Much like when creating sprites, start by:
1)	Right-clicking on the Objects folder and selecting Add Object.  
2)	At the top-left of the Object Properties window, rename the object “obj_Ball”.  
3)	Below that, select the Ball sprite by clicking on the icon to the right of the text-field and clicking on its name.

Next insert the behavior of the ball in the Events and Actions windows.  Simply put, when anything occurs during the game, such as keys being pressed or objects colliding, the object has the ability to react to it.  Thus, program the game by coherently piecing together actions that are called by events.

4)	Click the Add Event, and select Create.  This allows calling actions when the object is first created.  
5)	In the toolbar on the right, click and drag the first icon (red arrows in the 8 basic directions) for “Start Moving in a Direction"” over to the Actions window.  A new window will appear to set the parameters of the action.  
6)	By directions, click the 4 diagonal buttons.  The depressed buttons represent directions the ball might begin moving.  We do not want to allow purely vertical or horizontal directions, because the ball would be stuck on that axis.  
7)	Set the speed to 4.  This will move the ball 4 pixels each “step” (there are 30 steps per second by default in Game Maker).

We will return to the ball object, but we must first create the other objects (since we are not able to tell it how to interact with objects that do not exist yet).

Player Paddles
Next, make the players' paddles. 
1)	Create a new object, and call it "obj_Player1".  
2)	For the sprite, select our Paddle sprite.  
3)	Click Add Event, and select KeyboardLettersW.  Select the icon on the right for “Jump to a Given Position” (a blue ‘x’ with a red arrow pointing to another ‘x’).  
4)	In its parameters window, input 0 for x, and -4 for y, and click the Relative check box at the bottom.  This will move the paddle up 4 pixels at a time while the ‘w’ key is being held.  The Relative check box tells Game Maker that we want the paddle to move those distances from its current location.  Otherwise it will read them as coordinates.  The reason we put a negative number to move up is because in Game Maker (and many graphics applications), the origin (0,0) is on the top-left of the screen, and the y axis grows down from it.  
5)	To finish this event, drag over the icon for “Bounce against solid objects” (a red arrow bouncing off a dark blue line).  This will tell Game Maker that, while holding the ‘w’ key, to keep the paddle from going through other solid objects.

Now, repeat the previous action for the ‘s’ key:
6)	Right-click on the W-Key Event, click Duplicate Event and select KeyboardLettersS. 
7)	With the new event highlighted, double-click the “Jump to a Given Position” action to bring up it's parameters, and change -4 to 4. 
8)	Close the parameters window and Object windows by clicking Ok.  

Tip! In general, you should always close the object windows this way as it will save the changes you have made.  If you close the windows with the ‘x’ in the right corner, the changes will not automatically be saved (although Game Maker will ask you before closing).

Next:
9)	Right-click on “obj_Player1” in the Objects folder and duplicate the object.  
10)	Right-click on W-Key and select Change Event.  Change it to Keyboard<Up> and then change S-Key to Keyboard<Down>. 
11)	Click Ok and our paddles are complete!  

Once again, this is a convenient place to click Save.

Building the Wall
On to creating the bounding walls of the game: 
1)	First create a new object, and name it “obj_Wall”
2)	Assigning it the Wall sprite.  
3)	Next, unclick the Visible check box under the sprite section, click Ok 
That's all that is needed for our Walls.

Goooooooooooooooooal
To create the Goals: 
1)	Just make a new object, name it “obj_Goal” and uncheck Visible.   
2)	Click Add Event and choose CollisionBall.  
3)	On the right-side of the window, click on the Main1 tab of Actions, and drag over “Restart the current room” just above the bottom-right corner (a program window with a green arrow pointing up).  This will restart our Pong game every time the ball reaches the left or right side.

Finishing our Ball
The last thing to do before we run our Pong game is to set-up the ball's relationship to the paddles and the walls.  
1)	Double-click on the Ball object and add the event CollisionPlayer1.  
2)	Now drag over the Action “Reverse horizontal direction” (a red horizontal arrow turning around), click Ok, and then pull over “Set the horizontal speed” located directly above “Reverse...”.  
3)	In the “Set...” parameters window, check the Relative box, and input “0.5” into the field.  This will increase the speed of the ball by .5 pixels per step.  
4)	Duplicate the event for CollisionPlayer2, but change the .5 to -.5, because the ball is going in the opposite direction now.  The cumulative effect of the increases will speed the ball up over time, so that game becomes more challenging.  (There are certainly other ways to make Pong more challenging.  Feel free to experiment later!)
5)	Next, add the event for CollisionWall.  This time pull over “Reverse vertical direction”, and repeat the above.  

That’s it, we've finished our objects!

Now's another good time to Save your work so far.

Setting up the Room
We're now ready to lay out our actual level.  
1)	Right-click on the Rooms folder and click Add Room.  You won't have to change any parameters of the new room before placing your objects.  
2)	First click on the Backgrounds tab of your Room Properties window, and change the color box to black.  
3)	Switch to the Objects tab, select each object and lay them out as pictures below, with our Player1 on the left and Player2 on the right, and with the Goals in red, and the Walls in blue.  After the level is arranged, it may look like the picture below. 

4)	Give it a quick Save and press the Run Game button (the green triangle) on the top toolbar to test it out!

Extensions

There are numerous ways you might consider extending your basic Pong game.  Some suggestions include:
1)	Adding different, angled bounced depending upon where on the paddle the ball hits
2)	Adding additional rooms with obstacles
3)	Having two (or a variable number) of balls or even paddles for each player.

Feel free to use your own creative ideas.  Have fun!