title: Newb: best way to reference a calling class
body: <p>Full game code here: <a href="http://pastebin.com/v9UvDYWy" rel="nofollow">http://pastebin.com/v9UvDYWy</a></p>
  
  <p>I feel like I'm doing this wrong... I have a game class that has a loader method and then a player class. The player class needs to ask the game class's loader method for its image and also when it fires a bullet(using the bullet class) it again needs to ask for the bullets image... this is how I have that now...</p>
  
  <pre><code>class Player(pygame.sprite.Sprite):
      """ This class represents the player. """
  
      mouse = True
  
      def __init__(self, caller):
          pygame.sprite.Sprite.__init__(self)
          self.image = caller.PLAYER_IMAGE
          self.rect = self.image.get_rect()
          self.mask = pygame.mask.from_surface(self.image)
  
      def update(self):
          """ Update the player location. """
          if self.mouse:
              self.rect.center = pygame.mouse.get_pos()           # center player to mouse
              self.rect.y = SCREEN_HEIGHT-130                     # lock player to bottom of screen
  
  
  class Bullet(pygame.sprite.Sprite):
      speed = 0
  
      """ This Class Represents a Bullet"""
      def __init__(self, caller):
  
          #call the parent class constructor
          pygame.sprite.Sprite.__init__(self)
          self.image = caller.BULLET_IMAGE
          self.rect = self.image.get_rect()
          self.mask = pygame.mask.from_surface(self.image)
          self.speed = 8
  
      def update(self):
          """Move Bullet"""
          self.rect.y -= self.speed
  </code></pre>
  
  <p>Currently my game class has a method "Shoot" but I feel the player class should be the one to have this method... but if I do that then the references between Player class and Bullet class get messy. also the game should be the one that keeps the list of bullets etc so it can check for collisions but if the player is the one that initiates the bullet class then the player object needs a way of referencing the game object in order to create that list there.</p>
  
  <p>here is the bullet collision logic:</p>
  
  <pre><code>for bullet in self.bullet_list:
      # check if the lasers(bullet) hit anything in the block list(enemies)
      bullet_hit_list = pygame.sprite.spritecollide(bullet, self.block_list, True,collided=pygame.sprite.collide_mask)
  
      for block in bullet_hit_list:
          self.bullet_list.remove(bullet)
          self.all_sprites_list.remove(bullet)
          self.score += block.scorevalue
  
      if bullet.rect.y &lt; -10:  # remove bullet if it goes off screen
          self.bullet_list.remove(bullet)
          self.all_sprites_list.remove(bullet)
  </code></pre>
  
  <p>I know my question wasn't super clear but I don't know how to really word it clearer... so I changed the code so the player has method shoot.. notice how the player now needs to temporarily hold the bullet image as the bullet class doesn't know how to find it otherwise.</p>
  
  <pre><code>class Player(pygame.sprite.Sprite):
      """ This class represents the player. """
  
      mouse = True
      bullet_list = None
  
      def __init__(self, caller):
          pygame.sprite.Sprite.__init__(self)
          self.bullet_list = pygame.sprite.Group()
          self.image = caller.PLAYER_IMAGE
          self.BULLET_IMAGE = caller.BULLET_IMAGE
          self.rect = self.image.get_rect()
          self.mask = pygame.mask.from_surface(self.image)
  
      def shoot(self,caller):
          if len(self.bullet_list) &lt; 3:
              bullet = Bullet(self)
              # Set the bullet so it is where the player is(and centered)
              bullet.rect.center = self.rect.center
              # Add the bullet to the lists
              #pygame.Surface.fill(self.bullet.image,RED)
              caller.all_sprites_list.add(bullet)
              self.bullet_list.add(bullet)
              #Play Bullet sound
              caller.sound_bullet_fire.play()
  
      def update(self):
          """ Update the player location. """
          if self.mouse:
              self.rect.center = pygame.mouse.get_pos()           # center player to mouse
              self.rect.y = SCREEN_HEIGHT-130                     # lock player to bottom of screen
  
  
  class Bullet(pygame.sprite.Sprite):
      speed = 0
  
      """ This Class Represents a Bullet"""
      def __init__(self, caller):
  
          #call the parent class constructor
          pygame.sprite.Sprite.__init__(self)
          self.image = caller.BULLET_IMAGE
          self.rect = self.image.get_rect()
          self.mask = pygame.mask.from_surface(self.image)
          self.speed = 8
  
      def update(self):
          """Move Bullet"""
          self.rect.y -= self.speed
  </code></pre>