Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Gamemaker Essentials

You're reading from   Gamemaker Essentials Learn all the essential skills of GameMaker: Studio and start making your own impressive games with ease

Arrow left icon
Product type Paperback
Published in Mar 2015
Publisher
ISBN-13 9781784396121
Length 154 pages
Edition 1st Edition
Arrow right icon
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime