Gw Temp

Menu

Tutorial - 'GML (Gamemaker) Code examples' by Jag

An item about Gamemaker posted on

Blurb

This tutorial is going to be a collection of GML code bits that you can use to create various games, enjoy :)

Body

This tutorial is going to be a collection of GML code bits that you can use to create various games, enjoy :)

=========

"Collision Text Event(rpg)"

Making a RPG? Want a character to interact with other people? This code tells the game that for example If Character comes into contact with say a Old Wise man, it will show whatever text you typed. Put this in the Create Event. (where THING is the object you collid with. ex:Old wise man)

if (place_meeting(x,y,THING))
{
speed = 0;
draw_text(screen_width/2,100,'hello everybody!');
screen_refresh();
keyboard_wait();
}

=========

"Outside Wrap"



////////////////////////////////////////////////////////////////
// script name: outside_wrap
// creator: Mark Overmars
// date: May 26, 2001
//
// description: When an instance moves outside the room, this script
// wraps it to the other side of the room.
//
// arguments: None
//
// remarks: Place in the Outside event of the object.
////////////////////////////////////////////////////////////////
{
if (x < 0 && hspeed < 0) x = room_width + sprite_xoffset;
if (x > room_width && hspeed > 0) x = -sprite_width + sprite_xoffset;
if (y < 0 && vspeed < 0) y = room_height + sprite_yoffset;
if (y > room_height && vspeed > 0) y = -sprite_height + sprite_yoffset;
}

==========

"Outside Bounce"

////////////////////////////////////////////////////////////////
// script name: outside_bounce
// creator: Mark Overmars
// date: May 26, 2001
//
// description: When an instance moves outside the room, this script
// bounces it back into the room.
//
// arguments: None
//
// remarks: Place in the Outside or Boundary event of the object.
////////////////////////////////////////////////////////////////
{
if (bbox_left < 0 && hspeed < 0) hspeed = -hspeed;
if (bbox_right > room_width && hspeed > 0) hspeed = -hspeed;
if (bbox_top < 0 && vspeed < 0) vspeed = -vspeed;
if (bbox_bottom > room_height && vspeed > 0) vspeed = -vspeed;
}


==========

"Changes animation speed"
Does what it say's changes animation speed. (I don't have an example, but like, car wheels, mabe the faster you go the faster the animation?) Put in the Step Event

{
image_speed = 0.5
}

=======

"Random Fire A.I."

///////////////////////////////////////////////////////////
// script name: enemy A.I. fire
// date: May 27, 2001
//
//
// description: This causes the enemy to randomly fire 2 or more
// objects.
//
// arguments: None
//
// remarks: Place in the Step event of the object//
///////////////////////////////////////////////////////////
num = round(random(15))
if (num = 0)
{
instance_create(x,y,bullet)
}
//this is for the second object
num = round(random(30))
if (num = 0)
{
instance_create(x,y,bullet2)
}

========


"Keep score in upper left hand corner"

puts the score in the upper-left hand corner, very handy!

{draw_text(view_left[0],view_top[0],''+ string(score));}


========

"Movement coding"

The coding for moving up, down, left, right. Replace 8 with the speed you like.(simple)

UP:
{
direction=90;
speed=8;
}

DOWN:
{
direction=270;
speed=8;
}

LEFT:
{
direction=180;
speed=8;
}

RIGHT:
{
direction=0;
speed=8;
}

now in the "NO KEY EVENT" put this in it.(stops the character)

{
speed=0;
}

======



Expect more in the upcoming weeks... months... years....