title: Pygame - getting a sprite to cycle through images in a class, and assign a hitbox
body: <p>TLDR; Code is below</p>
  
  <p>I'm so done with pygame I'm just so confused, 
  like I guess I am learning more about classes, and loops and everything but, I think we bit off more than we can chew in this school project for just a few days of working on together (in-person). Going to school for Full Stacks Dev, and this is the first project they have us doing and I learn a lot from you on stackoverflow, but you give complex answers and we get them working but I guess i'm learning a lot about debugging. </p>
  
  <p>Anyways, reason for so many pygame related questions for sure don't wanna be a pygame expert...</p>
  
  <p>Zombie Code:</p>
  
  <pre><code>import pygame
  import random
  import math
  # import fighting_game
  
  # Player = player()
  
  
  
  
  class ZombieEnemy(pygame.sprite.Sprite):
  # zwalkRight = [pygame.image.load('images/zombiestandright1.png'), pygame.image.load('images/ztep.png'), pygame.image.load('imageszombiestandright1.png'), pygame.image.load('images/zombiestandright1.png')]
  
  # zwalkLeft = [(pygame.image.load('images/zombiestandleft.png'), pygame.image.load('images/ztepleft.png'), pygame.image.load('images/zombiestandleft.png'), pygame.image.load('images/ztep2.png')]
      def __init__(self, x=300, y=360):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.image.load('images/zombie.png')
          self.rect = self.image.get_rect()
          self.rect.center = (x, y)
          self.speedy = random.randrange(1, 8)
      def move_towards_player(self, player):
          # Find direction vector (dx, dy) between enemy and player.
          dx, dy = player.rect.x - self.rect.x, player.rect.y - self.rect.y
          dist = math.hypot (dx, dy)
          dx, dy = dx / dist, dy / dist # Normalize
          # Move along this normalized vector towards the player
          self.rect.x += dx * 10
          self.rect.y += dy * 0
  </code></pre>
  
  <p>Main Code: </p>
  
  <pre><code>import pygame
  import math
  import random
  from Zombie import *
  # from pygame.locals import *
  pygame.init()
  
  win = pygame.display.set_mode((900,567))
  
  pygame.display.set_caption("Power Rangers ZOMBIES")
  
  walkRight = [pygame.image.load('images/walk1.png'), pygame.image.load('images/walk2.png'), pygame.image.load('images/walk3.png'), pygame.image.load('images/walk4.png'), pygame.image.load('images/walk5.png'), pygame.image.load('images/walk6.png')]
  walkLeft = [pygame.image.load('images/leftwalk2.png'), pygame.image.load('images/leftwalk3.png'), pygame.image.load('images/leftwalk4.png'), pygame.image.load('images/leftwalk5.png'), pygame.image.load('images/leftwalk6.png'), pygame.image.load('images/leftwalk7.png')]
  bg = pygame.image.load('images/background.png')
  char = pygame.image.load('images/standingstill.png')
  clock = pygame.time.Clock()
  
  class Player(pygame.sprite.Sprite):
      def __init__(self,x,y,width,height):
          self.image = pygame.Surface((144,200))
          self.rect = self.image.get_rect()
          self.x = x
          self.y = y
          self.width = width
          self.height = height
          self.vel = 0
          self.isJump = False
          self.left = False
          self.right = False
          self.walkCount = 0
          self.jumpCount = 10
          self.rect.x = x
          self.rect.y = y
  
      def draw(self, win):
          if self.walkCount + 1 &gt;= 18:
              self.walkCount = 0
  
          if self.left:
              win.blit(walkLeft[self.walkCount//3], (self.x,self.y))
              self.walkCount += 1
          elif self.right:
              win.blit(walkRight[self.walkCount//3], (self.x,self.y))
              self.walkCount +=1
          else:
              win.blit(char, (self.x,self.y))
  
  class Background(pygame.sprite.Sprite):
      def __init__(self, image_file, location):
          pygame.sprite.Sprite.__init__(self)  #call Sprite initializer
          self.image = pygame.image.load('images/background.png')
          self.rect = self.image.get_rect()
          self.rect.left, self.rect.top = location
  
  BackGround = Background('images/background.png', [0,0])
  
  # def redrawGameWindow():
  #     win.blit(bg, (0,0))
  #     man.draw(win)
  
  #     pygame.display.update()
  all_zombies = pygame.sprite.Group()
  
  
  
  
  
  #mainloop
  man = Player(100, 340, 40, 60)
  run = True
  for i in range( 50 ):
      new_x = random.randrange( 0, 10000)       # random x-position
      # new_y = random.randrange( 0, )      # random y-position
      z = ZombieEnemy(new_x)
      all_zombies.add(z)         # create, and add to group
      z.move_towards_player(man)
  
      #####
  while run:
      clock.tick(27)
  
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
  
      keys = pygame.key.get_pressed()
  
      if keys[pygame.K_LEFT] and man.x &gt; man.vel:
          BackGround.rect.left = BackGround.rect.left + int(10)
          man.x -= man.vel
          man.left = True
          man.right = False
      elif keys[pygame.K_RIGHT]: #and man.x &lt; 500 - man.width - man.vel:
          BackGround.rect.left = BackGround.rect.left - int(10)
          man.x += man.vel
          man.right = True
          man.left = False
      else:
          man.right = False
          man.left = False
          man.walkCount = 0
  
      if not(man.isJump):
          if keys[pygame.K_SPACE]:
              man.isJump = True
              man.right = False
              man.left = False
              man.walkCount = 0
      else:
          if man.jumpCount &gt;= -10:
              neg = 1
              if man.jumpCount &lt; 0:
                  neg = -1
              man.y -= (man.jumpCount ** 2) * 0.5 * neg
              man.jumpCount -= 1
          else:
              man.isJump = False
              man.jumpCount = 10
  
      # redrawGameWindow()
      for zombie in all_zombies:
          zombie.move_towards_player(man)
  
      win.blit(BackGround.image, BackGround.rect)
      all_zombies.update()
      man.draw(win)
      all_zombies.draw(win)
      pygame.display.flip()
  
  
  pygame.quit()
  </code></pre>