game maker book 1 tutorial coding all items and one example also

56
Game Maker Book – 1 - Preview Game Maker Book 1 - Preview

Upload: apoorv-nema

Post on 14-Apr-2015

56 views

Category:

Documents


4 download

DESCRIPTION

it is a game maker book coding all items and one example also

TRANSCRIPT

Page 1: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game Maker Book 1 - Preview

Page 2: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

THIS IS JUST A FREE PREVIEWOF

GAME MAKER BOOK – 1

THE FULL BOOK IS A MASSIVE

180 PAGES

BUY THE FULL VERSIONPRINTED AND SENT BY POST

AT

WWW.GAMEMAKERBOOK.COM

Game Maker Book 1 - Preview

Page 3: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game Maker Book – 1

If Only I'd had this book when I started programming!

Game Maker Book 1 - Preview

Page 4: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Published by GameMakerBook.Com

Copyright 2012 Ben Tyers

ISBN: 978-1-4717-8715-7

All rights reserved. No part of this publication may be reproduced, stored in or reproduced or introduced in a retrieval system, or transmitted , in any form, or by any

means (electronic, mechanical, photocopying, PDF, digital, recording, or otherwise) without the prior written

permission of the publisher.

Parts of this book may photocopied for use in an educational environment. One printed copy required for

each location used.

YoYo Games, Game Maker and GameMaker, are Copyright © 2007-2012 YoYo Games Ltd. All rights

reserved. Permission has been granted to allow this publication to use images and code from their software.

Nice one YoYo Games!

All graphics contained within this book are either open source, public domain, created by/for me or used with

permission.

Includes extracts from wikipedia.

Game Maker Book 1 - Preview

Page 5: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Download Free Resources Used in This Book At: www.GameMakerBook.com/download/

The first part of this book deals mainly with game design, the second half with drag and drop and some basic coding with the view of creating a brick and ball game. It's recommended that you read the first half before you start making your first game. This will prepare you better for when you are ready start making your first game.

For the purpose of this book, references, drag and drop and coding relate to the registered Windows version 8.1 of GameMaker. This will be pretty generic, so it doesn't matter too much if you're using 8.1, Mac Version or GameMaker Studio.

Sometimes there will be more than one way to achieve the same result. The methods I use are purely subjective, I don't claim them to be the best, but are the approach that I consider the easiest or most logical in preparing you for a career or hobby in game making.

Game Maker Book 1 - Preview

Page 6: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Contents

Introduction and Questions & Answers - 16

Chapter 1 – Designing Your First Game - 34

Chapter 2 – Variables - 43

Chapter 3 – Sprites - 53

Chapter 4 – Sounds - 54

Chapter 5 – Events, Objects, Actions and Rooms - 55

Chapter 6 – Refining Your Game and More D&D - 82

Chapter 7– Publishing Your Game - 101

Chapter 8 - Book Review - 102

Appendix A – Drag and Drop Reference - 103

Appendix B – Constants - 160

Appendix C – Obsolete Functions - 172

Appendix D – Graph Paper - 180

Game Maker Book 1 - Preview

Page 7: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Introduction

Congratulations if you've just download GameMaker, you could be on the path to a career in game design and programming!

I guess you're eager to get going and make your first game, but I suggest you spend some time reading this introduction. This introduction will prepare you better, ensuring you approach your game design and programming in logical and methodical way, and answer some general questions about games, game design and programming.

What is GameMaker

GameMaker (originally named Game Maker and often abbreviated to GM) is a Windows and Mac IDE originally developed by Mark Overmars in the Delphi programming language. It is currently developed and published by YoYo Games, a software company in which Overmars is involved. GameMaker allows users to easily develop computer games without the requirement of prior computer programming experience, while allowing advanced users to create complex applications much faster than possible with most other programming languages with its built-in scripting language.The latest stable Windows release is GameMaker:Studio as of May 2012 and version 7 on Macintosh as of 11 August 2010. Game Maker Studio was released on the 22nd May 2012 with the latest GameMaker Standard release being GameMaker 8.1. Since its initial release in 1999, GameMaker gained many new features, notably 3D graphics support, cross-platform support, as well as a significant user base, with YoYo Games providing free hosting for user-created games.

YoYo Games has just undertaken a serious overhaul of the GameMaker software in the form GameMaker Studio. GameMaker Studio allows development for platforms including iOS, Android, Windows, Macintosh, and HTML5, and more

Game Maker Book 1 - Preview

Page 8: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

platform options are planned. The main difference between GameMaker Studio and the other GameMaker releases (GameMaker Standard and GameMaker Mac) is the fact that it is possible to export to other platforms. There are also other changes, including the look of the default skin (and the option to change the skin), as well as the removal of some statements in the GameMaker language for ensured compatibility.

What is a video / computer game?

A video game is an electronic game that involves human interaction with a user interface to generate visual feedback on a video device. The word video in video game traditionally referred to a raster display device, but following popularization of the term "video game", it now implies any type of display device. The electronic systems used to play video games are known as platforms; examples of these are personal computers and video game consoles. These platforms range from large mainframe computers to small handheld devices. Specialized video games such as arcade games, while previously common, have gradually declined in use. Video games have gone on to become an art form and industry.

The input device used to manipulate video games is called a game controller, and varies across platforms. For example, a controller might consist of only a button and a joystick, while another may feature a dozen buttons and one or more joysticks. Early personal computer games often needed a keyboard for gameplay, or more commonly, required the user to buy a separate joystick with at least one button. Many modern computer games allow or require the player to use a keyboard and a mouse simultaneously. A few of the most common game controllers are gamepads, mice, keyboards, and joysticks.Video games typically use additional means of providing interactivity and information to the player. Audio is almost universal, using sound reproduction devices, such as speakers and headphones. Other feedback may come via haptic peripherals, such as vibration or force feedback, with vibration sometimes used to simulate force feedback.

Game Maker Book 1 - Preview

Page 9: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

What is AI?

Artificial intelligence (AI) is the intelligence of machines and the branch of computer science that aims to create it. AI textbooks define the field as "the study and design of intelligent agents" where an intelligent agent is a system that perceives its environment and takes actions that maximize its chances of success. John McCarthy, who coined the term in 1955, defines it as "the science and engineering of making intelligent machines."AI research is highly technical and specialized, deeply divided into subfields that often fail to communicate with each other. Some of the division is due to social and cultural factors: subfields have grown up around particular institutions and the work of individual researchers. AI research is also divided by several technical issues. There are subfields which are focussed on the solution of specific problems, on one of several possible approaches, on the use of widely differing tools and towards the accomplishment of particular applications. The central problems of AI include such traits as reasoning, knowledge, planning, learning, communication, perception and the ability to move and manipulate objects. General intelligence (or "strong AI") is still among the field's long term goals. Currently popular approaches include statistical methods, computational intelligence and traditional symbolic AI. There are an enormous number of tools used in AI, including versions of search and mathematical optimization, logic, methods based on probability and economics, and many others.

The field was founded on the claim that a central property of humans, intelligence—the sapience of Homo sapiens—can be so precisely described that it can be simulated by a machine. This raises philosophical issues about the nature of the mind and the ethics of creating artificial beings, issues which have been addressed by myth, fiction and philosophy since antiquity. Artificial intelligence has been the subject of optimism, but has also suffered setbacks and, today, has become an essential part of the technology industry, providing the heavy lifting for many of the most difficult problems in computer science.

Game Maker Book 1 - Preview

Page 10: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

For the purposes of this book, only the basics of AI are covered. This will include such things as making an enemy move by itself or respond to interactions with the player. As your knowledge of GameMaker improves, and in books 2 and 3, you'll encounter and learn some more advanced ways to make your program more 'intelligent', such as how to make objects move around a maze, find the shortest route to a location, using maths and scripting to attack a player, and more.

How do I use GameMaker?

To start off with you'll learn the basics of GameMaker (GM) using it's built in GUI system known as Drag and Drop (referred to in future as D&D). This system allows you to create simple games without the need for any programming or coding knowledge. As you work through this book series you'll learn how to replace this with the more flexible coding known as GML (Game Maker Language). This book, Game Maker Book 1, deals primarily with D&D.

Your game will be made up of a number of elements. The main ones, as used in this book, are: sprites, sounds, objects, events, rooms and backgrounds. Others dealt with in later books in the series are scripts, dlls, coding (GML) and tilesets.

Sprites

A sprite is basically a graphical element that displays on the screen. Sprites are displayed using objects. Examples of sprite graphics are:

• Ball – like the ball you'll create later in this book that bounces around the screen.

• Key – something you need to collect to open a door or go to the next level

• Ghost – an enemy that follows you around and tries to kill you in a maze game.

Game Maker Book 1 - Preview

Page 11: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

at the top of the screen. You will then choose the image file and give it a name. You can call the sprite anything you want (excluding words that are pre-assigned to GM see appendix in back of this book for information on this). Various image files can be imported into GM, the main ones being: GIF, JPG, BMP,PNG

A good housekeeping practice is reduce the file size of your graphics files using an external software. This will reduce the overall size of your game, make it load quicker and may reduce some problems when playing. Sprites are drawn by using an object event or code. See objects later in this introduction.

Although you can call your sprite almost anything, it's good practice, especially when it comes to coding, to be descriptive. For a sprite, start the name with sprite_ or spr_ . The main reasons for this is:

• That you may create a lot of sprites, so using this method allows you to easily identify it and make changes.

• When you do start using GML, this will prevent errors in your code (if you use a space in a name in your GML will not understand the coding and will think it's two separate items).

Do not use spaces in your description, instead use _ (underscore), as you may also create similarly named objects or sounds, and having sprite_ or spr_, sounds_ or snd_, or object_ or obj_, allows you to identify it as a sprite, sound or object.

Game Maker Book 1 - Preview

Page 12: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Good examples of names are: (for sprites)

• spr_ball

• spr_chicken

• spr_enemy_ghost

(or for sounds)

• snd_bounce

• snd_background_music_track_1

(or objects)

• obj_ball

• obj_wall

Bad examples are:

• ball

• music

• ghost enemy

• object arrow

• bouncing sound

You can download for free a selection of resources at:www.GameMakerBook.com/download/

Game Maker Book 1 - Preview

Page 13: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Sounds

Various sound files can be used in GM, the main ones being, mp3, wav, ogg and MIDI – this may vary depending on which version of GM you are using. Sounds can be things such as sound effects (bounces, boings, animal sounds, and other effects, voices or dialogues) or background music.

Depending which version of GM you are using, you may offered to choose sound type, standard or background. Standard is generally used for sound effects, where as background is used my background music.

at the top of the screen.

Sounds are called to play in events (see topic later in this introduction) or in scripts.

It's good practice, as before with sprites, to name them descriptively as possible, starting with snd_ or sound_. A good example is 'snd_score_point', some bad examples 'beep','extra life' and 'hello'.

A good housekeeping practice is reduce the file size of your sound files using an external software. This will reduce the overall size of your game, make it load quicker and may reduce some problems when playing.

Game Maker Book 1 - Preview

Page 14: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Background

A background is another type of image used in GM. Generally it's a static background that appears below your sprites. For example an image of some grass with clouds that appear below a duck shooting game. You can set your background in room settings, or later on in code. As before, name starting with bgr_ or background_.

Game Maker Book 1 - Preview

Page 15: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Room

A room is the place where your game takes place. It will generally consist of a background and objects. A game can have multiple rooms, for example a game may have a menu room, a room where the main game-play takes place and a shop to buy things. When you're starting it's fine just to have one room. As you get more advance in GM you'll learn how to do things such as: use multiple rooms, change the size of rooms, create views for scrolling games and transition effects (making a room appear using different effects).

You'll learn in chapter 5 and 6 how to add objects to your room.Use:

to create a room. As before use a good name like room_level_1.

Game Maker Book 1 - Preview

Page 16: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Objects

Objects are the main blood of GM. Objects are the devices you'll use to do most things, such as:

• Display a sprite on screen

• Make something move

• Detect a key-press, mouse button or moving of the mouse

• Play a sound effect

• Create AI for objects

• Detect collisions

• Change rooms

• Play background music

• Animate a sprite

• Display a message

• Respond to an event

• Change/Display the score/lives

• Draw something

• Create another object

• Create an effect

• Do / Create / change something else

Throughout this book you'll gradually learn how to do all above, so I won't go into any more detail here, but feel free to experiment with it as you go along.

In simple terms, you place an object in your room. You'll then program it, using D&D or code, to do certain things, such as the examples above. In the most part you will make it react to events (see next section) and do something as a result.

A good name for the start of an object is obj_ or object_. Objects can be visible (using a draw event) or invisible (such as a control object – control objects will be dealt with in chapter 5).

Game Maker Book 1 - Preview

Page 17: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Events

An event, in simple terms, is something that happens, for the purposes of this book, I'll be focusing mainly on:

• Create event (happens only once)

• Key press

• Object hitting another object (called a collision event)

• An alarm event (something happening after a set period of time)

• A step event (something that occurs at regular intervals)

• An object being destroyed

• Click a mouse button

• Draw event (draws the sprite, score, lives, text on the screen)

Events are then used to test, change or make something else happen:

• increase score

• reduce lives

• create a bullet

• stop something

• start something

• change something

• create something

• move something

• test something – like how many lives left or which levelIt's these interactions and changes that work together to

create a game that interacts with you, the player.Using events and combining with D&D allows you to

manage, design and decide what events happen if certain conditions are met. By combining the events and D&D in a logical way, you can start to implement the design of your game. This

Game Maker Book 1 - Preview

Page 18: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

can also be used as a basis of an AI system to control objects not controlled by the player. Events will be dealt with more in chapter 5.

Events are selected by clicking the add object button and then clicking 'Add Event'.

Game Maker Book 1 - Preview

Page 19: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Drag and Drop

Drag and Drop (D&D) is GameMaker's inbuilt GUI for creating games without any prior programming knowledge. It allows for an easy way to create basic games. D&D also has it's GML (Game Maker Language) equivalent in code. As you get more advanced you'll learn to use a combination of D&D and GML.

D&D is a great way to start developing games as the logic and approach is similar to GML. As you progress through this book you'll learn most of the main functions of D&D and be introduced to GML. GML is introduced more in book 2.

Using D&D you'll learn how to make things happen in response to another event, action, or value, or occurrence.

For example:Make a player move left if left cursor is clickedDecrease lives by 1 if player hits enemyCreate a moving bullet if fire button is pressedMake ball bounce if it hits edge of screen

Looking at the previous examples you'll see that each consists of two parts, part one something happening, part two do something because of this. That's the basic of logical programming, you're well on your way to becoming a great games programmer.

In chapter 1 you'll learn how to incorporate this into your design process. As you get more advanced in D&D and coding you'll discover other logics, such as:

• Do something if something isn't true

• Do something if (something and something else) is/isn't true

These conditions (sometimes known as a conditional statement) are what provides you with interaction within your game and form a basis for an AI system. Most of these condition

Game Maker Book 1 - Preview

Page 20: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

checks will be placed main 'Create Event' or in the 'Step Event'. In D&D conditionals are octagon shaped.

Below are some examples of D&D and an explanation of

Game Maker Book 1 - Preview

Page 21: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Take sometime to look at other D&D in GM. Hover your mouse over them to get there name. You don't need to learn how to use each of them just yet, just try and familiarize yourself with them.

Game Maker Book 1 - Preview

Page 22: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

How Do I Develop a Game?

The design process of any game is probably one of the most important steps in the development process. Having a properly designed game speeds up the whole development process. You may think that a simple game wouldn't need much planning, but as you'll find in Chapter 1, when you design a brick a ball game, having a well designed game makes the programming of it much simpler. To start with you'll probably be designing and making your game by yourself, so you won't need to consider team collaboration, but imagine what would happen if you had a big team and no game design - it just wouldn't work. Having a well thought-out plan will allow you to create resources for your game much more easily, set out rooms quickly – as you'll know where everything needs to go, quickly track down bugs and errors, and easily designate different parts of the process to other people. You will also know what events, conditionals or interactions your game will require.

For a minute, consider the film industry. If you've ever watched one of those bonus DVDs that come in some sets, you would have seen something called a story board. Every scene is planned out well in advance using a storyboard, like a comic, with each action or camera angle in a different cell. This advance planning allows the actual filming process to be completed more accurately, and on time. Just imagine the chaos on set if no one knew where to stand or where to point a camera?

I'm not saying you need to plan your games in as much detail as a film, just that planning and design plays a very important part in the overall process.

It's also OK to ad-lib now and again if a great idea pops into your head when you're programming – just remember to add it to your design notes. Chapter 1 deals with the game design process in more detail.

Game Maker Book 1 - Preview

Page 23: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Can I Sell My Game? How Do I Make Money?

Yes, you can sell your game. YoYo Games' Terms and Conditions for GM are pretty relaxed and allow you to make and sell pretty much anything (except another Game Maker). You don't have to acknowledge you used their software or pay any commission if you make some or lots of money. Given that GM is so reasonably priced, you'd only have to sell a few copies of your software before turning a profit.

With the ability to release your game on a variety of platforms, at time of writing – Windows, Mac, HTML5, Android and iOS, the opportunity of multiple revenue streams is available. You can for example release a demo version and charge for the full version, or display on screen ads and earn a revenue from each click or sale. If you're interested in this, I suggest you check out: http://www.truevalhalla.com/blog/ where you can buy a great ebook providing a wealth of information about making money from HTML5 games.

Game Maker Book 1 - Preview

Page 24: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Chapter 1 – Designing Your First Game

After reading the introduction, you'll have a basic knowledge of the different elements. Don't worry if you don't understand everything just yet – this will come with time and practice, and be introduced and explained through this book. Later in the book you'll discover more ways and techniques to use these elements. At the moment it's just important that you are aware of the basic elements that make up a game: sprites, objects, sounds, backgrounds, events, conditional structures and basic variables, such as score and lives. If you're still a little unsure what the elements are, and their basic usage, please go back and re-read chapter 1 again, and perhaps make a few notes in this book or note-book or similar. This will be time well spent.

This chapter deals with how to design a game, and consider what elements will be used in the game and how they will react to the player (user input) and with itself (the AI). The importance with initial game design, similar to other industries where designing something, is to get as many ideas and sketches down as quickly as possible. It's not an art competition, in fact being a poor artist probably helps, crude basic sketches are just fine – so along as you understand the idea trying to be portrayed.

In this chapter you'll be introduced to D&D, these will be dealt with continually throughout the rest of the book, and looked at in more detail. For the purpose of this chapter you'll just be shown the D&D icon and a brief explanation of what it does. This gradual exposure will help you learn and understand them better.

At the back of this book you'll find a complete run-down of most of D&D functions, what they do, and their equivalent in GML. Feel free to refer to this guide as often as you wish. Also remember the F1 key to look at the, some-what impressive and very detailed, help pages.

Game Maker Book 1 - Preview

Page 25: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Basic Game Design – Brick and Ball Game – Image 1

Game Maker Book 1 - Preview

Page 26: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game OutlineSo my game idea is:The player controls a bat left and right. The game is to

control a ball using the bat and then try and hit and destroy the bricks. Along the way the player can collect bonus items. If the ball hits the bottom of the screen the player loses a life. The aim is to a get as high a score as possible.

On the facing page you'll see a scan of my basic idea for brick and ball game. This gives me an idea of what's visible on the screen and what the basic elements are. I've numbered each element from 1 to 11. They are:

1. The Players Bat2. The Ball3. Brick Type 14. Brick Type 25. Bonus Brick6. The Sides and Top7. The Bottom8. The Score9. The Lives10. Bonus11. The Whole Room (everything on the page)

So initially lets look at each element in more detail.

1: The Players BatThis is object the player will control. The controls will be pressing left to move left and right to move right.

2: The BallThis object will bounce around the screen.

3: Brick Type 1This is one object that the player tries to hit with the ball. It only needs to be hit once.

Game Maker Book 1 - Preview

Page 27: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

4: Brick Type 2This is another object that the player tries to hit with the ball. It needs to be hit twice.

5: Bonus BrickThis object needs to be hit by the player. Hitting it will create an instance of a Bonus (no. 10)

6: WallThis object marks the top, left and right of the playing area.

7: Bottom WallThis object marks the bottom of the play area

8: ScoreThis displays the player's score

9: LivesDisplays the players lives as images

10: BonusThe player collects this and gets extra points

11: RoomThis is the play area(known as a room). It holds all the above elements (1 to 10) in it.

Game Maker Book 1 - Preview

Page 28: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

THIS IS JUST A FREE PREVIEWOF

GAME MAKER BOOK – 1

THE FULL BOOK IS A MASSIVE

180 PAGES

BUY THE FULL VERSIONPRINTED AND SENT BY POST

AT

WWW.GAMEMAKERBOOK.COM

Game Maker Book 1 - Preview

Page 29: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Ball

Event / Interaction What To Do

Create Event Start Moving Up at Some Angle

Collision With Left, Right or Top Wall

Bounce Off at an Angle. Play a Bouncing Sound

Collision With Bottom Wall Play Life Lost Sound. Reduce Players Lives by one. Restart Ball.

Ball (continued)

Event / Interaction What To Do

Collision With Players Bat Bounce Off at an Angle. Play a Different Bouncing Sound. Increase score by 1.

Collision With Brick Bounce Off at an Angle. Reduce Others Health by 1. Play another Sound. Increase Score By 10.

Collision With Bonus Brick Bounce Off at an Angle. Reduce Others Health by 1. Play another Sound. Increase Score By 10. Create Instance of Object Bonus, Moving Towards Bottom of the Screen.

Collision With Bonus Do Nothing

Game Maker Book 1 - Preview

Page 30: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Chapter 2 - Variables

What is a variable?

In simple terms a variable is a value held in the computer's memory.

In GM there are two types: Strings and Real Numbers

Some examples of strings:“hello”“big”“What is your name?”

Some examples of real numbers:173.145921999999

Strings are sets of ASCII characters that may be of very large lengths. However, because GM prefixes string sizes to the strings as a 4-byte integer, strings may not be longer than 4,294,967,296 characters. If a string exceeds this limit, 4,294,967,296 characters are cut from the beginning until the string is under the limit. However, most situations will use far shorter strings, so this limitation is rarely encountered.

Real values are signed floating point numbers. Since version 6.1, GM has also allowed hexadecimal representation of real values in code (preceded by "$").

Game Maker Book 1 - Preview

Page 31: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

The GML for this is:money=money+10;which can also be written as:money +=10;

You can also subtract values:

The above would take 10 off the current value of money

The GML for this is:money=money-10;which can also be written as:money -=10;

Game Maker Book 1 - Preview

Page 32: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Chapter 4 - Sounds

GM can play an assortment of different files. You can the program your game to play when certain conditionals are met. You can also make sounds play continuously, like for background

Using the Main 1 tab you can start, stop or test if a sound is playing. It's good to name your sounds descriptively like: snd_bounce_1, snd_voice_game_over.

At the time of writing of writing there isn't a built in sound editor included in GM. There are plenty of free ones available, I recommend Audicity, which is free and it's quite easy to use it's basic functions.

The D&D for sounds is pretty easy to understand:

Starts a sound.

Stops a sound (good idea to check if playing before trying to stop it).

Checks if a sound is playing

Game Maker Book 1 - Preview

Page 33: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Use the middle mouse button to zoom in/out or keys CTRL+0 and CTRL+-. Make it so the sprite is nice and big, this makes it easier to work with.

Use the draw rectangle function and draw line function and

The click the green tick button, then click the green tick again. Give the sprite a name like 'spr_wall_tlr' (refers to sprite top left right).

Repeat the process above, but make a square with a red border and red cross and perhaps add a few extra lines so you can tell these to apart. Call this spr_wall_bottom.

Game Maker Book 1 - Preview

Page 34: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Now lets program what the ball does when it hits a wall.So open the ball object up and click 'Add Event'. Select

'Collision' and then choose obj_wall_tlr. In the event add the D&D:

choose collide precisely and then add:

and choose the sound snd_bounce_1You should have something that looks like:

Now create another collision event in the same object, this time with obj_wall_bottom and choose the sound snd_bounce_2 . The actions in this second event are purely for testing and will be removed later.

Game Maker Book 1 - Preview

Page 35: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Then Add:

Inside this add:

and set this to x =80Then also add:

And select this to the middle.

You should end up with:

Game Maker Book 1 - Preview

Page 36: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Now lets make the ball bounce off of the bat.Open up your obj_player_bat and check the 'Solid' check

box and then close it. Open up the obj_ball. Create a new event – collision with obj_player_bat, and add:

And enter the following code:var dir;dir=point_direction(other.x, other.y,x,y);move_bounce_all(true);speed=5;motion_add(dir,5);

Now open obj_ball again, and in the collision event with obj_wall_tlr, add the following code:

if direction=0{direction=direction - 5 + random(10);}

if direction=90{direction=direction - 5 + random(10);}

if direction=180{direction=direction - 5 + random(10);}

if direction=270{direction=direction - 5 + random(10);}

Game Maker Book 1 - Preview

Page 37: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

THIS IS JUST A FREE PREVIEWOF

GAME MAKER BOOK – 1

THE FULL BOOK IS A MASSIVE

180 PAGES

BUY THE FULL VERSIONPRINTED AND SENT BY POST

AT

WWW.GAMEMAKERBOOK.COM

Game Maker Book 1 - Preview

Page 38: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Now lets add a some bricks that the player.You should now know the sequence for adding a sprite and

creating a new object.Firstly lets a sprite, from the resource download. Load a

brick sprite from sprites / Bouncing Balls / Stones / and choose the red sprite – stone_normal_red. Name this sprite spr_stone_red.

Complete the above again, this time loading sprite stone_energy_yellow , name this spr_bonus_stone_1.

Set the sprite origin as center for both of these.Create an object for each, named obj_stone_red and

obj_bonus_stone_1. Your screen should now look like this:

Game Maker Book 1 - Preview

Page 39: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game Maker Book 1 - Preview

Page 40: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

When you play your game, it will look something like:

If you've managed to keep up so far, with only a few errors, you're doing great. You've learned a lot so far an have created your first game.

If you've got a few errors or have had other problems, look at the example GM file (for version 8.1) :

book_1_brick_and_ball_a

in the /examples folder of the free download pack, available at:

www.GameMakerBook.com/download/

You can now start refining your game and make it look and play better.

Game Maker Book 1 - Preview

Page 41: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Chapter 6 - Refining Your Game and More D&D

Once you've got your basic game functioning, you can start refining the look and play of it.

You can do things such as:

• Refine the game

• Set a goal to the game

• Add more objects

• Add music

• Change the appearance of text

• Create Multiple Levels

You'll learn how to do all of these in this chapter.

Before you proceed any further, I suggest you go back and review the introduction and chapters 1 to 5. This chapter will assume that you've understood everything so far, and will contain less explanations and pictures.

Game Maker Book 1 - Preview

Page 42: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Now save and test your game.You'll see that the bat now moves faster. The

global.bat_speed is a global variable, which means it's value can be changed globaly (from another object / script / etc ).

We'll set some conditions that check for a maximum / minimum value of global.bat_speed.

Open up the 'Step Event' and add to it to program the following, you place this under what is already present, so it looks like this:

Game Maker Book 1 - Preview

Page 43: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Set a Goal to the Game

The aim of this game is to get as big as a score as you can before you lose all your lives.

You could of course have other goals such:

• collecting all the bonuses

• getting to the next level

• completing as quickly as possible

• destroy all the bricks on a level

For the purpose of this introduction book, we'll just looking at scores and getting to the next level.

Add more objects

Create two more stone sprites; spr_stone_pink and spr_stone_yellow. Duplicate the existing stone obj_stone_red object and name appropriately, obj_stone_pink and obj_stone_yellow . Remember to add collision event for each new stone in the obj_ball. Remember to set sprite origin to center.

Now edit the room to make it look something like:

Game Maker Book 1 - Preview

Page 44: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game Maker Book 1 - Preview

Page 45: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

It would be good to display the number of stones left on the screen. Add the following to the 'Draw Event' of obj_control:

Set it to draw global.stones_left of 600 , 25.Now create a sound, snd_voice_congratulations and load

the voice sound snd_voice_congratulationsNow program the obj_control by adding the following to the

step event:

Game Maker Book 1 - Preview

Page 46: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Chapter 7 - Publishing Your Game

Once you've created a game that you're happy with, the next is to publish it. Depending what version of GM you have you'll be able to create games for Windows, Mac, HTML5, Android and iOS.

If you're using GM 8.1 you can publish your game through the YoYo Games website by selecting File > Publish Your Game.

You can also create an executable (exe) and upload this to the internet for people to download, you can do this through your own website, a games website, or another upload/file sharing site.

If you've got GM: Studio there are a few more options available, such as creating files for Windows, Mac, HTML5, Android and iOS. You can embed HTML into a web page so people can play online without having to download it. For Android and iOS you'll need to create a developer's account and follow their upload instructions.

With Windows and Mac exports you could also put your files on a CD and give to your friends or sell online or through a shop.

There also exists the possibility to earn revenue from games, such creating a demo and charging for the full version, displaying adverts (in game or on website), and selling on CD.

You can get a great guide to making money from HTML5 games at: http://www.truevalhalla.com/blog/

Game Maker Book 1 - Preview

Page 47: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Appendix A

Drag and DropD&D

NOTE – THIS SECTION IS DRAFTED ONLY. I'LL BE EDITING AND FORMATTING WHEN I GET THE CHANCE

Comments:In GameMaker if you hover your mouse over a D&D icon on

the right of the screen, a small pop up will appear telling you it's name. You can then find that in a relevant section below. This will explain what this D&D is and does and provides the GML. This is a great reference guide; use and refer to it as often as you can. You'll soon writing code without even thinking about it.

As a brief guide, the following are the general rules apply to the shape or colour of the D&D icon:

• Square with Grey Background – Does, Changes or Creates

• Square with Cream Background – Draws (Must be in DRAW EVENT)

• Octagonal with Grey Background – Tests Something

The following gives a guide to the coding equivalent on D&D. It also contains other GML related to that D&D, such as changing size, colour, position, transition, etc. This code may be obsolete in some recent versions of GM. In GM:Studio some GML and D&D has been removed to allow cross-platform compatibility. This is purely a quick reference guide as to what's possible and how it can be achieved. In the event of any errors, start the GM program and press 'F1' and search the help file for the current syntax – this help file is your friend, use it as often as you need to.

Game Maker Book 1 - Preview

Page 48: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Move section

'Move Fixed'

'Move Free'motion_set ( direction,speed );

'Move Towards'move_towards_point ( x,y,speed );

'Speed Horizontal'hspeed = speed ;

'Speed Vertical'vspeed = speed ;

'Set Gravity'gravity_direction = direction ;gravity = amount ;

'Reverse Horizontal'hspeed =- hspeed ; //actual code.

'Reverse Vertical'vspeed =- vspeed ; //actual code.

'Set Friction'friction = amount ;

Game Maker Book 1 - Preview

Page 49: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Jump Section

'Jump to Position'x = value;y = value ;

'Jump to Start'x=xstart ; //actual code.y=ystart ; //actual code.

'Jump to Random'move_random (1,1);

//actual code. The 1 and 1 in the code are the hsnap and vsnap positions.

'Align to grid'move_snap ( hsnap,vsnap );

’ Wrap Screen’

move_wrap ( hort,vert,margin );

// This code should be placed in the outside room event. Set hort (horizontally) and vert (vertically)to either 1 for true or 0 for false. Set margin to how far outside the room the instance must bebefore the action happens

'Move to Contact'move_contact_solid( dir,maxdist ) //for solid objects

move_contact_all ( dir,maxdist )

//for non solid objects, dir=direction, maxdist=maximum distance.

Game Maker Book 1 - Preview

Page 50: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

'Bounce'move_bounce_solid ( advanced);

//for solid objects, advanced=advance bounce(0 or 1).

move_bounce_all ( advanced);

//for all objects, advanced=advance bounce(0 or 1).

Game Maker Book 1 - Preview

Page 51: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Appendix BConstants:

Room Transitions

0 = no effect1 = Create from left2 = Create from right3 = Create from top4 = Create from bottom5 = Create from center6 = Shift from left7 = Shift from right8 = Shift from top9 = Shift from bottom10 = Interlaced from left11 = Interlaced from right12 = Interlaced from top13 = Interlaced from bottom14 = Push from left15 = Push from right16 = Push from top17 = Push from bottom18 = Rotate to the left19 = Rotate to the right20 = Blend the rooms21 = Fade out and in

Game Maker Book 1 - Preview

Page 52: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Cursor Types

cr_defaultcr_nonecr_arrowcr_crosscr_beamcr_size_neswcr_size_nscr_size_nwsecr_size_wecr_uparrowcr_hourglasscr_dragcr_nodropcr_hsplitcr_vsplitcr_multidragcr_sqlwaitcr_nocr_appstartcr_helpcr_handpointcr_size_all

Game Maker Book 1 - Preview

Page 53: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Appendix C

Obsolete FunctionsIf you're using GM:Studio as opposed to GM 8.1, bare in mind the following are not used in GM:Studio. They have been removed because:

• Not conducive to multiple platforms

• Usage requires taking control of device

• Require code to be created dynamically

• Block the execution of the runner

• Horribly slow or poorly implemented

• Not compatible with newer methods of doing things

Registry Functions

•registry_exists

•registry_exists_ext

•registry_read_real

•registry_read_real_ext

•registry_read_string

•registry_read_string_ext

•registry_set_root

•registry_write_real

•registry_write_real_ext

•registry_write_string

•registry_write_string_ext

CD Functions

•cd_close_door

•cd_init

•cd_length

•cd_number

•cd_open_door

•cd_pause

Game Maker Book 1 - Preview

Page 54: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Appendix D

Game Maker Book 1 - Preview

Page 55: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

THIS IS JUST A FREE PREVIEWOF

GAME MAKER BOOK – 1

THE FULL BOOK IS A MASSIVE

180 PAGES

BUY THE FULL VERSIONPRINTED AND SENT BY POST

AT

WWW.GAMEMAKERBOOK.COM

Game Maker Book 1 - Preview

Page 56: Game Maker Book 1 tutorial coding all items and one example also

Game Maker Book – 1 - Preview

Game Maker Book 1 - Preview