• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Adding a "Fire Rate" to A Platformer.

W

wozzlewuzzle

Guest
Hello,
So I've been working on a platforming game for a school project and I'm fairly new to game maker. The problem is that although I have the ability to shoot a bullet from my player, the player is able to shoot as much as they want. For example they could hold down the shoot button and there would be an endless stream of bullets. I want to add a fire rate or just a way to stop the player from endlessly shooting. The only way I know how to do this is by having game maker ignore part of some code and then reactivate that code.
Is there any other way I could do this?
Thanks
 
D

Dylaniza

Guest
, this video shows how to make a cooldown, see if that helps. :)
 
D

DKR_87

Guest
Good YouTube resources for this exact topic :
HeartBeast
Shaun Spalding
Making Games 101
SlashXGAMES
 

TheouAegis

Member
Some codes I wrote up. I think they work, but haven't tested them. I know the first one does because, well, it's standard. :p


Standard turbo fire:
Code:
/// CREATE EVENT ///
can_shoot = true;

/// STEP EVENT ///
if attack_key && can_shoot
{
    with instance_create(x,y, obj_bullet) 
    {
        image_xscale = other.image_xscale;
        //whatever else you need here
    }
    can_shoot = false;
    alarm[0] = 15;  //change this to control rate of fire
}

/// ALARM 0 EVENT ///
can_shoot = true;

Three-shot Burst mode (e.g. Mega Man's pew-pew-pew)
Code:
/// CREATE EVENT ///
can_shoot = 1;

/// STEP EVENT ///
if attack_key && can_shot & 1
{
    with instance_create(x,y,obj_bullet)
    {
        image_xscale = other.image_xscale;
        //whatever else you need here
    }
    can_shoot = ++can_shoot & 7;  
    if can_shoot 
        alarm[0] = 15; //change this to control rate of fire between bullets
    else
        alarm[0] = 31; //change this to control rate of fire between rounds
}

/// ALARM 0 EVENT ///
can_shoot++;
Variable Burst Fire mode
Code:
/// CREATE EVENT ///
can_shoot = true;
rounds = 0;

/// STEP EVENT ///
if attack_key && can_shoot
{
    with instance_create(x,y,obj_bullet)
    {
        image_xscale = other.image_xscale;
        //whatever else you need here
    }
    can_shoot = false;
    rounds++;
    if rounds == choose(3,4,5) 
        rounds = 0;
    if rounds
        alarm[0] = 15; //change this to control rate of fire between bullets
    else
        alarm[0] = 31; //change this to control rate of fire between rounds
}

/// ALARM 0 EVENT ///
can_shoot = true;
Burst with Bullet Limit mode (e.g., BIonic Commando)
Code:
/// CREATE EVENT ///
can_shoot = true;

/// STEP EVENT ///
var i = 0;
with obj_bullet
    i++;
if i == 3 //change this to limit how many bullets can be on the screen
    can_shoot = false;
if attack_key && can_shoot
{
    with instance_create(x,y,obj_bullet)
    {
        image_xscale = other.image_xscale;
        //whatever else you need here
    }
    can_shoot = false;
    alarm[0] = 15; //change this to control rate of fire between bullets
}

/// ALARM 0 EVENT ///
can_shoot = true;
 
Top