Welcome, Guest. Please Login or Register.  • Help
SMF Underground
+ SHMUP-DEV » SHMUP DEV FORUMS » Assistance » Tutorials
|-+ Efficient Enemy Sequencing

Pages: [1]   Go Down
0 Members and 1 Guest are viewing this topic. Topic Tools  
Read August 14, 2008, 06:38:16 PM #0
jakman4242

Efficient Enemy Sequencing

To go along with the normal format of these tutorials, hi, I'm Jack. I'm not sure if this is just a concept not explained enough, or if it's just something everyone knows and doesn't need any help whatsoever on. But I want to explore enemy sequencing. This is the sequence things(usually enemies, but obstacles work just as well in this case.) enter the screen, and usually eventually exit. One way or another. I'll be showing this code in GML, the Game Maker Language. GML is very similar to C++, except there are a few differences:
-You do not have to declare variable types
-There are only two variable types in GML, floating point numbers, and strings.
-You cannot declare your own variable types(with, say enumeration.)
-You can freely switch a variable between types, there are no restrictions.

That's it though. With the only other differences being functions are prepared differently, and constants not being freely definable.(There's a little form where you pre-enter constants in.)

Now, first. This code can easily be transformed into C++, but I'll let you do that, since I'll probably mess it up if I try.

The first thing we need to do to set up sequencing is set up a time standard. Let's do that by making a function to convert seconds to steps. This will give us a better time standard, and will be much easier to understand when things are going to happen:
Code:
return room_speed*argument[0];

That's it. If you're using C++ it'd be more like
Code:
int sc(int x) {
 return get_framerate_function()*x;
}

So that's that. From now on I won't be converting my code to C++ standards, just so you know. But that's just to give you the idea. Next we should define some constants for our enemies. I'll let you do that, since I don't know what enemies you plan on having. Then you should make either:
A. One script to create any enemies for you
Code:
//Enemy_Create(Enemy, arg, arg, arg, etc.)

var E, ic;
E = argument[0];

if (E == DRONECONSTANT) {
 ic = instance_create(objDrone,argument[1],argument[2]);
 ic.Arg3 = argument[3];
} else
if (E == OTHERENEMYCONSTANT) {
 ic = instance_create(objEnemy,argument[1],-25);
 ic.ToY = argument[2];
}

You could do it like that. I wouldn't try this in C++ though, since in GML 16 arguments are always defined, they're just defined as 0 if not specified differently. I recommend doing this if you're doing this in Game Maker. If you're doing this in C++, I recommend creating separate functions for each of your enemy objects. For instance:
Code:
//DroneCreate(x,y,Arg3)

var ic, xx, yy, a3;
xx = argument[0];
yy = argument[1];
a3 = argument[2];
ic = instance_create(xx,yy,objDrone);
ic.Arg3 = a3;

And you could just do that when creating an enemy in your sequence instead of the more easily modified script stated above. Either way will work, it's just a matter of preference.

Finally, there are two ways to do your actual sequence. One way is with a series of if statements, the other is with a switch statement. It's good practice to also keep your separate enemy sequences in separate functions. Have a code for StageSequence1(), StageSequence2(), StageSequence3(), and so on.

Here is an example for the if method:
Code:
Step += 1;//Assuming you declared the step variable already in some way, depending on your language.
if (Step == s(5)) {Enemy_Create(DRONECONSTANT,50,150,8);}//s() is the converter script mentioned way back.
if (Step == s(7)) {DroneCreate(50,150,8);}

That's one way to do it. Not so bad, eh? Then there's the switch statement method. It's a bit cleaner, but we need to replace the s() function code to make it work properly.
Code:
return argument[0]/room_speed;

So, now, the same code said above converted to the switch method:
Code:
Step += 1;

switch s(Step) {
 case 5: Enemy_Create(DRONECONSTANT,50,150,8); break;//'5' is for five seconds.
 case 7: DroneCreate(50,150,8); break;
}

So that concludes my little tutorial on efficient enemy sequencing. I hope it's helped you in some way, or will help you in the future. If not, well. Sorry to hear that. I really hope I didn't just write a tutorial on something everyone knows, but oh well. Hopefully it will help someone down the line.

G'day and G'night,
-Jack


My game design blog -- A bit outdated, but you might like to take a read anyway~
Or read my new blog!~ (which I do update)
My blog.
Offline  
Read August 14, 2008, 07:22:32 PM #1
motorherp

Re: Efficient Enemy Sequencing

Nice contribution, many thanks.  Karma++.


Offline  
Read August 05, 2009, 06:01:55 AM #2
AceGarcia

Re: Efficient Enemy Sequencing

           I am actually confusing of using this codes.





_________________
Thermostat

Offline  
Read August 10, 2009, 04:30:14 PM #3
jakman4242

Re: Efficient Enemy Sequencing

Would you like to elaborate, so someone can help you?  Tongue


My game design blog -- A bit outdated, but you might like to take a read anyway~
Or read my new blog!~ (which I do update)
My blog.
Offline  
Read April 07, 2010, 12:22:31 AM #4
OMNICYPHER

Re: Efficient Enemy Sequencing

 i think its good to sequence thier spawns based on game time passed, but you should also sequence thier AI based on thier personal time passed. when you create a new enemy, give it a personal timer, and use that to determine what they do and when. if the AI loops, like most boss battles do, you could always reset thier timer to repeat. throwing in some logic based on its health or the players coordinates helps too, making them seem smarter. based on these 3 easily available attributes, they could express a full range of different behaviors, like predetorial, territorial, defensive, reproductive, ect... i might be wondering off topic into AI, but its tied into event sequencing, so i thought i would throw in my 2 cents.


Good gameplay is when Pace is inversely proportional to mental effort
Offline  
Pages: [1]   Go Up
Jump to:  

Page created in 0.15 seconds with 19 queries.