Getting started with Gamemaker

advertisement
Getting started with Gamemaker
A) Your game will need at least one room in which to run. To create a room:
2. Your room appears
here. Right click to
change its name
1. Use this button to
create a room
3. Room settings (colour,
size) can be changed
here.
B) Your game will not do anything without objects. Let’s create an object
2. Give it a name here
1. Use this button to
create an object
3. Give it a sprite here
C) Making objects do things
3. You need to add
events to your object
2. The Create event defines
its variable at the start
1. The Step event is carried
out every 1/30 of a
second
4. Keyboard events happen
when a key is pressed
5. Alarm events happen
when a counter hits zero
D) Assigning code to events
Use the first icon under code in the control tab to pull in the area for
typing in code. For an instance of an object x and y are set aside for its
coordinates on the screen. Other variables are set aside like this too.
Some Game Maker Language (GML) Syntax
Functions
A function is separate piece of code which has already been written and has a specific purpose. In
Game Maker there are many different in-built functions which you can use to do things, for example:
move_towards_point(x,y,sp);
//this moves you towards a point
room_goto_next();
//this makes you go to the next room
draw_text(x,y,string);
//this draws text on the screen
Variables
Variables are an essential part of any programming language, gml is no exception. A variable is like a
reference for storing a value, this reference has to be given a name. The name can be anything you
like as long as it does not clash with any names that already exist. An example:
apples = 4;
In this example the variable is given the name apples, this variable apples is then assigned (given) a
value of 4. In gml the equals sign is always used to assign a value to a variable.
Once you have assigned a variable a value from now on when you call upon this variable at any point
it will be the equivalent to calling that value which you assigned to it. For example if you were to
now use:
fruit = apples;
It will set the variable fruit to 4 as the variable apples has the value 4. Or if you were to have another
variable pears with a value of 2 you could use:
fruit = apples+pears;
fruit would now be set to 6 (as it is 4+2). You could then for example go on further to then use this
fruit variable
Strings
As well as 'number' values (the proper terminology being real values) variables can also be set as
'text' values (the proper terminology being string values). To do this you need to put text inside 2
quotes either " " or ' '. For example you can set a string to a variable like so:
name = "John";
The variable name will then have a value equal to the string "John". You can now do whatever you
wish with this variable just like you could with the apple variable, most commonly you would want
to draw the variable, which you can do using:
draw_text(x,y,name);
This will then draw the text "John" at the instance's x and y position.
If / else statements
If statements are used when wanting things to happen only if a certain condition is met. They take
the form:
if (a condition is met)
{perform actions}
When the condition is met (ie it is true) then all the actions you put inside the braces {} will be
performed. A basic example would be:
if (health == 100)
{lives = 3}
This code would only set lives to 3 when health is equal to 100. Notice the difference that a single =
is used when assigning a value to something, but a double == is used when comparing values
For loops
Most of the time you see a for loop in the form:
for (i = 0; i < 5; i += 1)
{draw_text(10,10+i*8,"hello")
Places to start
Gamemaker tutorials
http://sandbox.yoyogames.com/make/tutorials
The Gamemaker Community
http://gmc.yoyogames.com/
The Complete Beginner’s Guide to Gamemaker (a forum post in the above)
http://gmc.yoyogames.com/?showtopic=424410
The Gamemaker Online Manual
http://docs.yoyogames.com/source/dadiospice/
(also accessible via ‘Help’ in Gamemaker itself)
Gamemaker Game Programming with GML – PACKT Publishing)
Download