Many many Bullets

Discussion in 'Programming' started by Wild_West, Sep 1, 2017.

  1. Wild_West

    Wild_West Member

    Joined:
    Jun 25, 2016
    Posts:
    911
    Has anyone here ever played the game Furi?
    I'm trying to replicate a bullet hell style of shooting like the one in that game but I can't seem to figure out how to work with all the instances I create because I just get errors that the ones with names I give don't exist.
    I know I need to use a loop to make x amount of bullet instances and id them all with a variable name new_bullet_0 new_bullet_1 ect but I don't know how without just like, tagging the last one made.
    Any help with looping would be appreciated, so I can actually understand what I need to do.
     
  2. Simon Gust

    Simon Gust Member

    Joined:
    Nov 15, 2016
    Posts:
    3,174
    Aren't loop patterns enough, why do you need to name instances?
     
  3. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,014
    I'm not quite sure what you're asking here. I did look up a video of Furi. It seems like you just want enemies that can shoot a lot of bullets in a single frame? Maybe have those bullets know who shot them?

    Code:
    
    ///whatever creates bullets, probably step or alarm
    if (instance_exists(target)) {
        var angle = point_direction(x, y, target.x, target.y) - 25;
        repeat (10) {           
            var xx = lengthdir_x(5, angle);
            var yy = lengthdir_y(5, angle);                                     
            with (instance_create(x + xx, y + yy, obj_bullet)) {
                parent = other.id;
            }
            angle += 5;
        }
    }
    
    
    Again, this is only one example. You could accomplish the same thing with a for loop or a while loop for example. And I just made up one bullet pattern and saved the shooter object's id to the bullet object.
     
    Last edited: Sep 1, 2017
  4. Wild_West

    Wild_West Member

    Joined:
    Jun 25, 2016
    Posts:
    911
    Actually yeah I don't know why I was thinking that, I got it working like I want now.
     
  5. Wild_West

    Wild_West Member

    Joined:
    Jun 25, 2016
    Posts:
    911
    I didn't even think to use the lengthdir functions :p
    But I will now. Question though, why the other.id assign for parent? unless this is a collision event I don't think other even works does it?
     
  6. elementbound

    elementbound Member

    Joined:
    Jun 30, 2016
    Posts:
    114
    In a with loop, you can use other to access the instance you started off with. So for example if you have object A and object B, and this code in one of object A's event:
    Code:
    // id here is an instance of A
    with(B) {
        // id here is an instance of B
        // other.id here is the above instance of A
    }
     
  7. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,211
    Btw, if you want to iterate through a list of items and give them all an id, you should use a for loop and an array:
    Code:
    for (var i=0;i<num_instances;i++) {
       instance_array[i] = instance_create(x,y,object);
    }
    
    Then you can just use instance_array[0], instance_array[1], etc to identify the individual instances.
     
  8. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,014
    You can use other in a with statement. So other.id is the id of the object instance using the with statement. You may not need to do this here, but I use it a lot to save which object created the new object. Say for some reason another object needs to know which instance shot that particular bullet.
     
  9. Wild_West

    Wild_West Member

    Joined:
    Jun 25, 2016
    Posts:
    911
    I'm still not sure I get it, I'd probably have to see it used in a specific code for something.
    I mean I use with statements all the time just not in that way
     

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