Pong Game

Open the starting file in your Z: folder with all the sprites. If you expand the Sprites folder, it should look like this...


1. Bats moving

OBJ: wall

Create a new wall object - just set the sprite and make it solid.

OBJ: bat_left

Create new object bat_left, select the sprite.

Add a new event: W-Key (under Keyboard>Letters>..."W")

Add the following action:

  • Jump to Position: (0,-7), relative
    (negative y coordinate means going upwards)

Now duplicate the previous event and set it to the S-Key...

  • Jump to Position: (0,7), relative 
    (positive y coordinate means going down)

Obj: bat_right

Duplicate to create bat_right object.

Change the sprite name and sprite ...

Change events so the player on the right will use the up and down arrow keys.

  • Change event "W-key" to <Up> arrow key

  • Change event "S-key" to <Down> arrow key

Room

Test this in a level. Create a room, leave grid default size 16x16. 

  • Insert the bat_left object on the left side of the room (2nd column in) and the bat_right object on the right side of the room. 
  • Line the top and bottom of the room with the wall object.

Test it out; make sure the bats move up and down with the right keys.

Problem:

So far the bats can move, but there's a problem. They can also move out of the room! So we have to fix this with the following. 

Go back into the bat_left object...

  • add a Collision with wall event.
    • Set it to Bounce (against all objects)

Go back into the bat_right object...

  • add a Collision with wall event.
    • Set it to Bounce (against all objects)

Test it out - make sure it works before moving on to the next stage.


2. Ball moving, bouncing

Obj: score_left, score_right

Create 2 new objects. Set them to the right sprite. Make them invisible so the player doesn't see it (uncheck the "Visible" box).


Obj: ball

Create a new object ball. Set the sprite. 

First, we'll get it to move on its own and bounce off the walls and bats... 

  • Create
    • Move Fixed: set it to the 4 corner directions, speed 8
  • Collision with wall:
    • Bounce (against all objects)
  • Collision with bat_left:
    • Bounce (precisely, against all objects)
  • Collision with bat_right (can just duplicate previous event)
    • Bounce (precisely, against all objects)

Now we'll make sure that if it leaves the room, instead of disappearing, the ball will go back to its starting position...

  • Collision with score_left:
    • Jump to Start
    • Sleep - makes the game pause a bit before it restarts (leave at default)
    • Set Score - give the player 1 pt, relative

You can duplicate the previous event for the Collision with score_right event...

Then just delete the Set Score action and replace it with Set Lives - set it to "1", relative (we'll use this to keep track of the right player's points)

Room

  • Place only one instance of the ball object in the middle of the room.
  • Line the right side with the score_left object (=what will gives the left player points)
  • Line the left side with the score_right object (=what will gives the right player points)

Test it out.


3. Score

Obj: ball

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

Obj: scores

Create a new object scores; no sprite.

  • Draw
    • Draw Score: (40,40), for the caption type in "Player left: "
      make sure you include a space after the colon.
    • Draw Lives: (450,40), make the caption say "Player right: "
      make sure you include a space after the colon.

Room

Place the scores object anywhere in your room (it'll be marked with a question mark). 


Test it out. You're done. Play it for a bit so I can see the score shows up and is working...