so, I've got a very simple AI for a game I'm working on, and it works fine, but I have no clue how to apply it to an indefinite number of followers. Could someone help me?
if event.key == pygame.K_f:
follow = follow * -1
if follow == 1:
if math.fabs(playerx) - math.fabs(friendx) > 10:
friendx = friendx + 10
if math.fabs(playerx) - math.fabs(friendx) < -10:
friendx = friendx - 10
if math.fabs(playery) - math.fabs(friendy) > 10:
friendy = friendy +10
if math.fabs(playery) -math.fabs(friendy) < -10:
friendy = friendy - 10
Dont know much about the python, but you could store all the friend positions in one big arrrrr.... You said indefinite number, didnt you?
Me, I just make larger numbers of storage than I plan on using, so I never run into that problem. Course, means I'm not properly learning how to use objects(the whole point of c++), but alas, the game comes first in my mind.
This is how I would do it....
int friendActive[MAX_FRIENDS];
int friendx[MAX_FRIENDS];
int friendy[MAX_FRIENDS];
for (int i = 0; i < MAX_FRIENDs; i++)
{
if (friendActive == true)
{
if (distanceToPlayer(i) > 10)
friendFollowPlayer(i);
}
}
I'm sure you can figure out what I mean with the functions. Also, I'm presuming arrays work the same in python as they do in c++.
But I should really learn how to use classes...