Game Maker Language
Šablona:Infobox Software Game maker language je programovací jazyk, který vytvořil Mark Overmars. K tomuto skriptovací programovacímu jazyku je potřeba vývojové prostředí Game Maker. Toto IDE se stará i překlad do spustitelného souboru. Má syntaxi podobnou C s možností použití i syntaxe Pascalu.
Příklady kódu
Následují příklady kódu.
Hello world zobrazující text ve vyskakovacím okně:
show_message("Hello World!");
Another example that would display the same text in the game window instead. Note that by default, Game Maker redraws the background continuously, so using the default setting, this code would need to be attached to the draw event for drawing to work properly.
draw_text(0, 0, "Hello World!");
Here is a piece of code from a game using GML:
// This is a comment
/* this is a C-Style comment. */
/* temporary variable declaration.
A temporary variable will be released at the end of a script.
Note that this doesn't declare it to be of a specific type! */
var xx, yy, nn;
// A conditional. It can also be shortened to "if (can_shoot)".
if (can_shoot = true) // "=" and "==" can be used interchangeably in conditionals
{ // This begins a block of code. You can also use "begin" as with Pascal.
/* Here we are setting the variable to false. This could also be written as "can_shoot = 0;"
since Game Maker doesn't distinguish between integer and boolean types. */
can_shoot = false;
/* Here you are setting the 0th alarm to five steps. The alarm
variable will automatically count down to 0, and when it hits 0,
the alarm0 event will be triggered. */
alarm[0] = 5;
/* Here the temporary variable xx is defined implicitly as an integer,
and the lengthdir_x function is used. */
xx = x + lengthdir_x(14, direction);
yy = y + lengthdir_y(14, direction);
//This function creates a obj_bullet and then returns its instance id to nn.
nn = instance_create(xx, yy, obj_bullet);
/* The with statement allows you to access the fields of an object directly,
without having to write statements like nn.speed or nn.direction. */
with (nn)
{
speed = obj_tank.speed + 3;
direction = obj_tank.direction;
}
}
GML supports many variations in syntax. As a demonstration, the previous example could also be written like this:
var xx, yy, nn;
if can_shoot = true then begin
can_shoot := false
alarm[0] := 5
xx := x + lengthdir_x(14, direction)
yy := y + lengthdir_y(14, direction)
nn := instance_create(xx, yy, obj_bullet)
with nn begin
speed := obj_tank.speed + 3
direction := obj_tank.direction
end
end
Here is an example of basic keyboard-controller movement. The motion_set function takes two arguments: direction (degrees) and speed (pixels per step). Calling this function will assign an instance with a "speed" and "direction" (both built-in local variables), which Game Maker uses to update the instance's position automatically each step (an instance's position can also be modified directly using the built-in local "x" and "y" variables).
if (keyboard_check(vk_left)) motion_set(180,4);
if (keyboard_check(vk_up)) motion_set(90,4);
if (keyboard_check(vk_right)) motion_set(0,4);
if (keyboard_check(vk_down)) motion_set(270,4);
if (keyboard_check(vk_nokey)) motion_set(0,0);
Here is an example of a more complex script from a platform game. Using this, the player can walk over hills and bumpy terrain.
if (!place_free(x-4,y))
{
if (place_free(x-4,y-4))
{
x-=4;
y-=4;
}
else if (place_free(x-3,y-5))
{
x-=3;
y-=5;
}
else if (place_free(x-2,y-6))
{
x-=2;
y-=6;
}
}
else
x-=4;
Here is a piece of code that draws a simple 3D floor (the function d3d_start()
must be called beforehand).
d3d_draw_floor(0,0,0,500,600,1,background_get_texture(background1),.01,.01);
V tomto článku byl použit překlad textu z článku Game Maker Language na anglické Wikipedii.