0

class monkey(object):

def init(self, x, y, width, height):

 self.walkRight = [ list of images]

 self.walkLeft = [list of images]

 self.walkDown = [list of images]

 self.walkUp = [list of images]

#get rect for each image using list comprehension. I do this 4 times for each arrow key

 self.rect_Right = [img.get_rect() for img in 
 self.walkRight] #repeat for other arrows

class enemy(object):

(basically the same thing as player with enemy images)

 def move_towards_player(self, monkey):
 dirvect = pygame.math.Vector2(monkey.rect.x - self.rect.x, 
 monkey.rect.y - self.rect.y)

 dirvect.normalize()

 dirvect.scale_to_length(self.speed)

 self.rect.move_ip(dirvect)

I am running into 2 problems. 1st, since I am uploading multiple images into a list, I don't know whether I am using the get_rect() correctly. I am currently using a list comprehension. How do I get the rect.x and rect. y positions? How do I get the center position?

2nd, I don't know how to get the move_towards_player to get working. I passed the player class into the function, but I don't think it can read the rects.

0 Answers0