Creating Your Own Video Game with Game Maker 8.0 PART TWO Pong Example.

Now that the basics are out of the way let me take you through the first game I decided to do. Remember the original Pong game I figured what game could be simpler to set up than a two player Pong game? Not much, so let's get started. Another good thing about this example is that you can use the sprites that are built into Game Maker 8.0 without creating your own or searching the internet for the right ones.

Step #1 Import All The Sprites You'll Need

You'll need two one sprite for the two paddles left click on the sprites folder, click "load sprite" load the file from Program Files->Game_Maker8->Sprites->Bouncing Balls->bat_large.png
Change the name to whatever you like I used "paddle_spr" just make sure the names are descriptive. That way you can remember them later.

Now we need a ball do the same thing and load the  file: Program Files->Game_Maker8->Sprites->Bouncing Balls->ball_blue.png

Now we are going to use a wall for the ball to bounce against, so go to:
Program Files->Game_Maker8->Sprites->Tutorial1->wall.png

That's all we need as far as sprites go. Now onto our sounds.

Step #2 Add All The Sounds And Music

Being as this is a very simple example we will only use one sound for when the ball hits the paddle. Go load the file at: Program Files->Game_Maker8->Sounds-> wood1.wav. Save it as bounce_snd.

Step #3 Create The Controls For Player One and Two

We're going to skip the other folders for now and go to the object folder. Left click on the folder and choose "create new object" let's start with the object's which will be under our control. So name the first object player1_obj and assign the paddle_spr as the sprite the object will use.

Now we want this object to respond to our controls so click on "Add Event" and then "Key Press" and choose "press ". Now drag "Move Fixed" into the action box. Click on it and new box will open choose the left arrow key and choose a speed I found for Pong a good speed is 6 or 7. Do the same process except now do it for "press ". Player can move left and right now! We're not quite done though we want the paddle to stop moving when we stop pressing the keys. So now will add two more events under "Key Release" for "release " and "release ". For the direction we will choose the middle square and add a speed of 0. Now when the player let's go of the keys the paddle will stop moving.


Next create player2_obj and follow the same process only instead of using the and you want to use two different keys preferably far away from the and . I chose the "a" and "d" keys for left and right.


Step #4 Create The Non-player Objects For The Game

First up is our ball for the paddles to hit, we want it to start moving when the game starts but we want to give the players a chance to respond. So first create an object ball_obj and attache the sprite ball_spr. Now we are going to use the "Create" event so when the ball is created which will be when the game starts we can have some actions occur. First we want to make sure both players are ready so under the "Actions" go to "Main2" and select "Display Message" enter "READY?". Now this message will be displayed before the game starts. Next we want the ball to move so add the action "Move Fixed" and select Up, Down and all the diagonals set a speed of about 6 or 7. When the game starts the ball will start moving in a random direction. Now let's add one more event under "Other Events" choose "Outside Room" and for the action go to "Main2" and choose "Restart Game". When a player misses and the ball leaves the screen the game will start over.

Now we need something for the ball to bounce against so create a new object wall_obj and attache the sprite wall_spr.  Go to "Add Event" and to "Collision" and from the drop down menu choose ball_obj and add the action "Bounce Against" for the ball_obj and also add a sound event from "Main1" choose bounce_snd. Now when the ball hits the wall it will bounce and make a sound. We also want the paddles to stop moving when they hit the wall so add to more "Collision" events for player1_obj and player2_obj instead of bouncing though we are going to choose "Move Fixed" choose the center direction and a speed of zero. When the paddles reach the wall they will stop moving.


Now let's modify player1_obj and player2_obj add a "Collision" event for both. Like the wall we want the ball to also bounce against the paddles so add a "Collision" event for ball_obj exactly like we did for the wall_obj. So now the ball bounces off the walls and off both paddles all we need now is our game space.


Step #5 Create The Room For The Game Space


We are almost done now go to the room folder and create a new room since we only have one room in our game the name is not important. I left it as the default room0. Now open up the room. You can add a background but I opted just to use a black background. I then put the wall objects up the left and right sides a player1_obj on the bottom, player2_obj on the top and ball_obj in the middle. Now save everything and run your game.





Post a Comment

0 Comments