Gw Temp

Menu

Tutorial - 'Basic Movement with Shooting in GML' by Relic

An item about Gamemaker posted on

Blurb

A tutorial explaining some basic movement and shooting in GML.

Body

I didn't think I've seen a tutorial that shows how to do movement/shooting with straight GML, so I thought I'd make one..
Okay, here it is:

This goes in the CREATE event of your main character:
global.bulletready = 0;

This is in the STEP event of your main char:

{ if(global.bulletready > 0) { global.bulletready -= 1 }}
//Checks to see if the variable "global.bulletready" is greater, than 0...and if it is, it keeps subracting 1 until it's equal to 0.

{
if keyboard_check(vk_up)=true {
y = y-N* }
//Checks to see if the up key is pressed, if it is, it subtracts N from it's Y coordinate.
if keyboard_check(vk_down)=true {
y = y+N* }
//Nearly the same as above, i'm sure you can figure it out.
if keyboard_check(vk_left)=true {
x = x-N* }
//blah..
if keyboard_check(vk_right)=true {
x = x+N* }
//blah blah and blah..
else {
speed=0; }}
//If no keys are pressed, it's speed is set to 0.

*N is the speed your character will be moving.

{
if keyboard_check(vk_space)=true {
//Checks so see if the space bar is being pressed.
{
if(global.bulletready==0) {
instance_create(x,y,'Name Of Bullet Object')
global.bulletready = 20 }
//Checks to see if global.bulletready is 0, and if it is, it creates the bullet object at the same place as your character, and sets the variable to 20.. 20 can be changed to a lower number if you want to be able to shoot faster..
}}

Now....The bullet really won't do anything unless you add something into it's create event...:

direction = 'name of character here'.direction;
speed = 20;
//This sets the bullet off in the same direction your character is going...so basically, whichever key you're holding in... at the speed of 20...

Ehh, and I think that's it. Hope I didn't forget anything... If I screwed anything up, let me know know. And tell me what ya think, I might make some more advanced ones.

Email: failingdestiny@aol.com ... Ya ya, i know...ECK! Aol! Heh..