1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice
  2. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Making Burst Fire?

Discussion in 'Programming' started by squidsRockets, Oct 11, 2016.

  1. squidsRockets

    squidsRockets Member

    Joined:
    Oct 1, 2016
    Posts:
    12
    I have created the gun and it shoots off of a timer so there isn't a giant spray of bullets.
    But what I want is for the gun to shoot in bursts. It's probably very obvious and i'm just not seeing it, i'm just starting so.
    Here's the guns create code
    Code:
    CanShoot = 0;
    FiringRate = 7; //Bullet per sec
    SetAmmo = 0;
    Damage = 2; //Damage this weapon inflicts
    alarm[0] = FiringRate - CanShoot;
    And here is the alarm used to spread the bullets essentially.
    Code:
    if keyboard_check(vk_numpad1) && place_meeting(x,y,oPlayer) && SetAmmo > 0
    {
        Direction = random_range(-0.5,0.5);
        MyBullet = instance_create(x, y, oMGBullet);
        MyBullet.speed = oPlayer.image_xscale * 2000 / room_speed;
        MyBullet.Scatter = Direction;
        MyBullet.vspeed = MyBullet.Scatter;
        SetAmmo = SetAmmo - 1;
        
        //Lose Ammo
        with (oMGAmmoBar)
        {
            image_xscale = image_xscale * 0.9;
            if image_xscale <= 0
            {
                instance_destroy();
            }
        }
    }
    
    alarm[0] = FiringRate - CanShoot;
    And the guns step event, I don't know if this is relevant.
    Code:
    //Place in our 1st inventory slot
    if (place_meeting(x,y,oPlayer))
    {
        ItemPickUpSlot(0,0);
        //Make object stack on player
        x = oPlayer.x;
        y = oPlayer.y;
    }
    
    //Picking Up Ammo
    if (place_meeting(x,y,oAmmo))
    {
        SetAmmo = SetAmmo + 100;
        //Destroy Ammo Box
        with (oAmmo)
        {
            instance_destroy();
        }
    }
    Thanks in advance, all this really helps as i don't know much yet.
     
  2. Nathan Laing

    Nathan Laing Member

    Joined:
    Jul 31, 2016
    Posts:
    355
    You need to use two alarms; One to control the fire rate when you actually do shoot, and a second alarm to 'detect' when it is time to fire the next burst.
     
  3. squidsRockets

    squidsRockets Member

    Joined:
    Oct 1, 2016
    Posts:
    12
    Could you help me with that? I figured I would need 2 alarms but I still don't really understand how to set one up.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,036
    You don't need an extra alarm. Make a variable called burstCount or something like that and set it to 0 in the create event. In your alarm event when the player fires a bullet, check if burstCount is less than 4 or whatever limit you want. If it is, fire your bullet as normal (basically what your alarm code currently is) and increase burstCount by 1; otherwise, set the alarm to however long you want the burst delay to be and set burstCount back to 0.

    Edit: or set burstCount to 3 and count it down, checking if burstCount to allow shooting.
     
    squidsRockets likes this.
  5. Obj_Neil

    Obj_Neil Member

    Joined:
    Apr 19, 2019
    Posts:
    21
    I couldn't figure out how to get this to work with one alarm, at least not if I want to control rate of fire and how long to pause and not fire at all. But with two alarms, this works really well. Here is how I did it.

    Inside the bullet spawner
    CREATE
    Code:
    alarm[0] = room_speed * .2;
    
    burst_count = 0; 
    Inside bullet spawner alarm[0]
    Code:
    if burst_count < 4
    {
    instance_create_layer(x, y, "Fireball_shoot", o_bullet);
    
    burst_count++;
    
    }
    alarm[0] = room_speed * .2;
    
    if alarm[1] = -1
    {
    alarm[1] = room_speed * 2;
    }
    and inside bullet spawner alarm[1]
    Code:
    burst_count = 0; 

    Change alarm[0] to control the rate of fire, and change burst_count to control how many bullets are fired. Alarm[1] controls how long to wait before firing again.

    I control the direction and speed of the bullet in the bullet object.

    Bullet CREATE
    Code:
    // make xx = player.x  at create so that the bullet moves to where the player was and doesn't chase player.
    xx = o_player.x;
    yy = o_player.y - sprite_height/2;
    
    
    // set the direction of the bullet to move to where the player was, xx and yy.
    direction = point_direction(x, y, xx, yy);
    speed = 6; 
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice