title: AttributeError: 'Game' object has no attribute 'all_sprites'
body: <p>Here is the error I am getting:</p>
  <blockquote>
  <pre><code>Traceback (most recent call last):
   File &quot;C:\RPG Game\main.py&quot;, line 67, in &lt;module&gt;
     g.new()
   File &quot;C:\RPG Game\main.py&quot;, line 23, in new
     self.createTilemap()
   File &quot;C:\RPG Game\main.py&quot;, line 17, in createTilemap
     Block(self, j, i)
   File &quot;C:\RPG Game\sprites.py&quot;, line 60, in __init__
     self.groups = self.game.all_sprites, self.game.blocks
  AttributeError: 'Game' object has no attribute 'all_sprites' 
  </code></pre>
  </blockquote>
  <p>I believe <code>self.game.all_sprites</code> is being called before it's defined or haven't passed the game object into the <code>Player</code> object. How do I fix it? Here is my code:</p>
  <pre><code>from sprites import *
  from config import *
  import sys
  
  class Game:
      def __init__(self):
          pygame.init()
          self.screen = pygame.display.set_mode((WIN_WIDTH, WIN_HEIGHT))
          self.clock = pygame.time.Clock()
          self.running = True
  
      def createTilemap(self):
          for i, row in enumerate(tilemap):
              for j, column in enumerate(row):
                  if column == &quot;B&quot;:
                      Block(self, j, i)
                  if column == &quot;P&quot;:
                      Player(self, j, i)
  
  
      def new(self):
          self.createTilemap()
          # a new game starts
          self.playing = True
  
          self.all_sprites = pygame.sprite.LayeredUpdates()
          self.blocks = pygame.sprite.LayeredUpdates()
          self.enemies = pygame.sprite.LayeredUpdates()
          self.attacks = pygame.sprite.LayeredUpdates()
  
          self.createTilemap()
  
      def events(self):
          #game loop events
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  self.playing = False
                  self.running == False
  
      def update(self):
          # game loop updates
          self.all_sprites.update()
  
      def draw(self):
          self.screen.fill(BLACK)
          self.all_sprites.draw(self.screen)
          self.clock.tick(FPS)
          pygame.display.update()
  
      def main(self):
          # game loop
          while self.playing:
              self.events()
              self.update()
              self.draw()
          self.running = False
  
      def game_over(self):
          pass
  
      def intro_screen(self):
          pass
  
  g = Game()
  g.intro_screen()
  g.new()
  while g.running:
      g.main()
      g.game_over()
  
  pygame.quit()
  sys.exit()
  </code></pre>