It would help if you showed the definition of the alienship class. What you are showing isn't enough.
I would suggest making the myalienship array a static member of alienship and call the AI function, without any parameters, and use the static myalienship within the function?
You can create a static method in alienship that does the loop:
// in the .h class definition
class alienship {
public:
// static attributes (global to class)
static alienship *myalienship[10];
private:
// non-static attributes
...
public:
// non-static methods
alienship();
~alienship();
void AI();
...
public:
// static
static void process_AI();
};
----------------------
// in the .cpp file
alianship* alienship::myalienship[10];
...
void alianship::process_AI()
{
int b;
for (b=0; b < 10; b++) myalienship[b]->AI();
}
void alienship::AI()
{
float spriteX = agk::GetSpriteX(isprite);
float spriteY = agk::GetSpriteY(isprite);
float spriteW = agk::GetSpriteWidth(isprite)/2.0f;
float spriteH = agk::GetSpriteHeight(isprite)/2.0f;
int al_myid, al_isprite1;
float al_spriteX,al_spriteY,al_spriteW,al_spriteH,angle;
int b;
for (b=0; b < 10; b++) {
al_myid = alienship::myalianship[b]->myid;
if (myid!=hh) {
al_isprite = alienship::myalianship[b]->isprite;
al_spriteX = agk::GetSpriteX(al_isprite);
al_spriteY = agk::GetSpriteY(al_isprite);
al_spriteW = agk::GetSpriteWidth(al_isprite)/2.0f;
al_spriteH = agk::GetSpriteHeight(al_isprite)/2.0f;
if ((((spriteX + spriteW) - 200) < al_spriteX) &&
(((spriteX + spriteW) + 200) > al_spriteX) &&
(((spriteY + spriteH) - 200) < al_spriteY) &&
(((spriteY + spriteH) + 200) > al_spriteY)) {
angle = agk::ATanFull(al_spriteX + al_spriteW - spriteX + spriteW, al_spriteY+ al_spriteH - spriteY + spriteH);
agk::SetSpriteAngle ( isprite, angle );
}
}
}
}
I moved the definitions outside of the for loops because it is a style I prefer (some languages, like JavaScript, really complain about defining variables as part of the for statement).
Also notice the parenthesis I added to the innermost if statement. it lets the compiler do a better job of optimizing it and makes sure the comparison is the correct one
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master