Message Board


Message Board > Fenix / Bennu / Gemix / DIV > Tracking an instance

December 23, 2007, 02:50
Hikaru
Beardless
7 posts
Hello all. New here...

So here's my dilemma. I have a process that creates two groups of enemies, each spaced by using structs to place each enemy a certain amount of pixels in X and Y apart from the original. This creates two squadrons of enemies coming in from the left and the right (it's a shmup). Code follows:

Code:
    
// The structs:

struct slnxtpos[5]
    npx;
    npy;
end=0,0,-25,-10,-50,-20,-75,-30,-100,-40;

struct srnxtpos[5]
    npx;
    npy;
end=0,0,25,-10,50,-20,75,-30,100,-40;

// Calling the spawning process for each squad:

case 6:
    if (rand(0,125)<lvl_params[level].en_freq[engrph])
                  spawn_squadl(-50,rand(0,5));
                spawn_squadr(370,rand(0,5));
      end
end

// Create squadrons:

process spawn_squadl(x,y);
private
xx;
begin
for (xx=0;xx<6;xx++);
    spawn(x+slnxtpos[xx].npx,y+slnxtpos[xx].npy,130,6);
   
end
xx=0;
end

process spawn_squadr(x,y);
private
xx;
begin
for (xx=0;xx<6;xx++);
    spawn(x+srnxtpos[xx].npx,y+srnxtpos[xx].npy,67,6);
   
end
xx=0;
end

// TO DO: Combine the two above processes into one!
 


What I need to do is to track the last spawned enemy and set a flag when it leaves the screen so that another squadron can be spawned. This is so multiple squadrons aren't spawned continuously.

I've read something about getting instance IDs, but I don't quite get it. Without doing the work for me (as I like to try and work things out for myself with some minor help), what would be the easiest way to explain instance IDs so I can accomplish what I've set out to do?

It's nice to see that there are others who are fenix fans! I didn't expect to find this site when I did a google search. I'm glad I did :)

I'm using version .84a for the Mac, BTW, but plan on recompiling under the newest version when I get XP installed on my MacBook :)

Thank you for any and all advice.
____________
#
December 23, 2007, 03:13
Sandman
F3n!x0r
1194 posts

Welcome to Booleansoup.

You might want to look at the FenixWiki for more information. When you call a process, an instance of that processtype is created. This instance has a unique ID. You can use this ID in various ways to obtain information about it: get locals, functions, etc.

Code:
Private
    int s;
Begin

    s = Ship(); // create instance of type Ship and save processID in 's'

    say("x: " + s.x); // print x of that Ship in console

    s.x = 3; // assign value to ship's local var x
    s.y = 4; // assign value to ship's local var y

    x = 0; // assign value to this process' local var x 
    y = 0; // assign value to this process' local var y

    say("dist: " + get_dist(s)); // print distance between ship and this process

    Loop
        frame;
    End

End

Process Ship()
Begin

    Loop
        frame;
    End

End


The main program is also a process instance.

Also, I do advise to use version 0.93, as it has many bug fixes and advantages.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
December 23, 2007, 03:41
Hikaru
Beardless
7 posts
Thanks for the link to the wiki. I didn't know it existed :)

I was thinking I could just test to see if the process currently exists, and then set the flag when the last ship is destroyed. But I call all of the ships at once using the for-end loop. Wouldn't that just count all of the ships as one instance, and should I rewrite the spawning code so I could count each ship as a separate instance? This is where I get confused about instances.

For instance (no pun intended), instead of using for-end in the spawning processes themselves, put it in the block where I call the spawning processes and have the spawning processes as just "graph=foo, loop frame end"? I'm kind of thinking out loud here and will give this a try. But as I have it written now, wouldn't it just count as one single instance instead of ten?

I also have the movement of these ships in a different process (called enemy_spawn), as I have eight different enemies, all with different movement patterns, and they are moved based on their graph number.

In any event, it's a bit clearer to me now. Thanks for the help thusfar.

[Edited on December 23, 2007 by Hikaru]
____________
#
December 23, 2007, 04:18
Sandman
F3n!x0r
1194 posts

If spawn() creates a new instance of a processtype, then there will be six instances when you call spawn() six times. You can save the processIDs in an array:
Code:
int s[5];
-------
for(x=0; x<6; x++)
    s[x] = ship();
end


What you could do is:
Code:
for(x=0; x<6; x++)
    s = ship();
end
// <- here s is the processID of the last spawned ship


To know if a process is out of the screen, you can use its x an y values.
____________
BennuWiki
Yes, my avatar has grey borders in IE (so get a decent browser)
ROOFLEZ ROOFLEZ
#
December 23, 2007, 04:24
Hikaru
Beardless
7 posts
That's similar to what I was thinking of doing, although (duh) it never occurred to me to use an array to store the process IDs. That makes it completely clear now.

Once again, thanks for your very helpful advice!
____________
#

Message Board > Fenix / Bennu / Gemix / DIV > Tracking an instance

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!