Book Image

Gamemaker Essentials

4 (1)
Book Image

Gamemaker Essentials

4 (1)

Overview of this book

Table of Contents (16 chapters)

Programming the game


With our object created and ready to go, we are now also ready to program the game and make it work. All this will be done in the player object.

Add a Create event to the player object and then drag in a code block from the control tab on the right. You can actually change the default tab for objects in the GameMaker preferences.

The first thing we need to do is think about what variables we are going to need. We are going to make the game record the score, so we will need a variable for this. To make the code easier to edit, we can also create a variable for storing the maximum speed we want the player to move at. Finally, we can store our controls in variables to make the code easier to edit later on. The reason we store key controls in variables is so that if we want to change the controls later on, we can simply change the variable instead of changing every keyboard check.

Here is the code for our speed and control variables:

S=0; //score
max_spd=10;

key_right=vk_right...