CREATING YOUR FIRST GAME IN GAME MAKER
Introduction: Before starting a Game, always decide what this game is all about and things you will need to create a base of the game. “Hit the Ball” is a damn simple game, in which there will be two moving balls and you have to hit them with the cursor. With every hit you earn the points.
Sprites are just simple images. These are your game graphics that will be displayed on the screen.
So, sprites we need:
- A ball
- A wall
As you can see its pretty simple game, so the only things you need for the game is two sprites,
We just need two sounds, a Hit sound, when the mouse will hit the ball and a background music.
- Hit sound
- Background music
You can select any background from Game Maker directory. I used this:
You have to create just 2 objects.
- Create a new object and name it obj_ball and in the sprite field, select spr_bat.
As you can see that there are two empty fields EVENTS and ACTIONS. In Events field you have to specify on which event what actions will takes place, those actions will go into ACTIONS filed. For example, if want to delete an object when we click Mouse Left button. Here When Mouse left button is pressed is an EVENT and Deleting the object is an ACTION.
- First thing we want is our ball to move in random directions. So from ADD EVENT choose CREATE. Drag MOVE FIXED
from move tab.
Now you can place obj_ball in the room and run the game.
Select all the direction except middle one, and enter speed = 4.
Since there are no walls to bounce back the balls, we have to create walls around the room so the balls don’t go outside the room.
Create a new object and name it obj_wall. In the Sprite field, select spr_wall. You don’t have to add any events, because this object will only work as a block to stop the ball from going outside. Don’t forget to check Solid. We have checked Solid so that we can add a collision with the ball.
- Let’s add a collision with the wall, so ball bounce back when it hits the wall. So reopen obj_ball properties and from ADD EVENT choose Collision event with obj_wall.
- We want our ball to bounce when it collides with the wall, so there is already a predefined action for that. So select Bounce from move tab.
If you set the parameter precise to false, only horizontal and vertical walls are treated correctly. When you set precise to true also slanted (and even curved) walls are treated correctly.
Now you can place walls in the room and test the code.
Now we have to add Mouse events, So when the player hit the ball with cursor, we want three things to happen
- Play a hit sound
- Add 1 point in the score
- Send the ball to a random position so that it feels like that it’s a new ball
- Play a hit sound
- So select Mouse left button from Add event.
In the action field start dragging Actions as per requirement.
a) Play a Hit sound
So drop Play sound from main1 tab.
Loop : false
b) Add 1 point in the score
Drop Set Score from Score
In its values, enter:
Don’t forget to check the Relative box, So Game Maker will add 1 point every time, when the cursor hits the ball. If we uncheck Relative, Game Maker will set the score to 1 every time Player hits the ball.
c) Send the ball to a random position
Select Jump to random from move tab and leave its value same.
Snap vert. = 0
Snap hori. = 0
d) Now since you have added all the requirements, but one more action you have to add with these three actions. Its Move fixed and enter the same values as before.
Explanation: We have added this action again, because when the ball will move at random position, we want our ball to move in different direction. If you will not add this action, then the ball will be placed at a random position, but it will move in the same direction in which it was moving before the Player hit it.
Now your game is ready to run. But before
we run it lets add a background to the room.
Open the room properties you have created.
Choose your desired background and check Visible when room starts. For reference you can see the picture attached below.
Congratulations! You have created your first game. Why not show it to your friends.
Congratulations! You created your first game. Your journey starts from here. Don’t give up. Start small and learn from everywhere.