[SOLVED] - One variable to represent Characters

Started by TheJBurger, Tue 14/09/2004 22:57:48

Previous topic - Next topic

TheJBurger

So here's my situation.

I'm currently experimenting with an AI system where you control 1 Knight and other Evil Knights try to attack you.Ã,  (Currently 5 evil knights)
The 1 Knight you control must defend a castle in which the Evil Knights charge at and try to destroy. The Evil Knights appear randomly and then charge straight at the castle.

So here's what my problem is.
When your 1 Knight approaches the Evil knights at a certain distance, I want the Evil Knights to charge at him instead of continue heading at the castle.
The Evil Knights are characters BADONE, BADTWO, BADTHREE, BADFOUR, and BADFIVE.
I did this by using the character[].x and character[].y variables, but then realized I would have to code the entire section five whole times for five different characters.

So, I wanted one variable to represent all the different evil Knight characters.
Instead of making a bunch of different codes that say:
-----------------------------------------------------------------------
// Example code
if (character[EGO].x < character[BADONE].x + 15) {
Ã,  // Blah blah blah
Ã,  // Charge at EGO instead of castle
Ã,  }

if (character[EGO].x < character[BADTWO].x + 15) {
Ã,  // Blah blah blah
Ã,  // Charge at EGO instead of castle
Ã,  }
-----------------------------------------------------------------------

Instead of that I want one variable in the character[].x to represent all the Bad Characters, for example:

if (character[EGO].x < character[ALLBADGUYS].x + 15) { // Where all bad guys represent characters BADONE, BADTWO, etc.
Ã,  Ã, // Blah blah blah
Ã,  // Charge at EGO instead of castle
Ã,  }
Is there any way to do this?

Thanks for any help.

Janik

#1
How about defining:

function DoACharge(int CharNumber)
{
if (character[EGO].x < character[CharNumber].x + 15) {
Ã,  // Blah blah blah
Ã, // Charge at EGO instead of castle
Ã, }
}

and

DoACharge(BADONE);
DoACharge(BADTWO);
etc.


If it comes up in more than one room you could put it in Global Script, or just in the Room script if that's for a single room.
Play pen and paper D&D? Then try DM Genie - software for Dungeons and Dragons!


SMF spam blocked by CleanTalk