Okay, Im using Python 2.6, and the latest version of pygame. In my game, I have circles moving away from you, you have to catch them, and if you catch them, they disappear. The amount of circles can vary, and that is the issue I am having. As of now, I have the program create a bunch of circles in EasyAI().active, then in the loop, check if your circle is close to the AI circle, if so, then pop it from the EasyAI().active, then move the AI. Here's an excerpt of my code:
class EasyAI():
active = []
def _create(self, xpos, ypos, color, dif):
self.active.append([xpos, ypos, color, dif])
def _check(self, player, ai):
for x in range(-8, 9):
for y in range(-8, 9):
if (player[0] == (ai[0] - x)):
if (player[1] == (ai[1] - y)):
self.active.remove(ai)
def _run(self, xpos, ypos, color, dif, playerx, playery):
self.circle = circle = pygame.draw.circle(window, color, (xpos, ypos), ray_circle)
self.active.remove([xpos, ypos, color, dif])
# If the circle is in the same position as the player:
if (xpos != playerx) or (ypos != playery):
# Sometimes, we don't want it just going in a straight line. It has a 2/3 chance of going straight, 1/3 random, 1/100 nowhere
#### REALLY GOOD MEDIUM SETTING:
# 0, 60; 60, 99
a = random.randint(0, 100)
# Straight
if a in range(0, 60):
nopx = (xpos - playerx)
nopy = (ypos - playery)
if nopx > 0:
xpos += random.choice(dif)
if nopx <= 0:
xpos -= random.choice(dif)
if nopy > 0: …