title: Is there an better way to create a tilemap in pygame?
body: <p>When i try to blit my tiles it says "list index out of range". I have no idea what to do since im new to this. </p>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>window.blit(tilemap.textures[tilemap.tilemap[row][column]], (column<em>tilemap.tilesize, row</em>tilemap.tilesize))
    IndexError: list index out of range</p>
  </blockquote>
  
  <p>I tried to change the values of <code>mapwidth</code> and <code>mapheight</code> but that did not do the trick. I have 2 scripts. Main and tilemaping. There is maybe an error because of that. Note (I have initalized pygame in the full code so that is not the problem)</p>
  
  <p><em>main.py</em></p>
  
  <pre><code>import pygame as pg
  
  # Importing files
  import constants
  import classes
  import tilemap
  
  # Functions
  def draw_game():
      """ This function draws everything on the screen """
  
      global window, clock
  
      # The background
      window.blit(constants.img_background, (0, 0))
  
      # Tiles
      for row in range(tilemap.mapheight):
  
          for column in range(tilemap.mapwidth):
  
              window.blit(tilemap.textures[tilemap.tilemap[row][column]], (column*tilemap.tilesize, row*tilemap.tilesize))
  
  
  
  
      # Updating
      clock.tick(60)
      pg.display.update()
  </code></pre>
  
  <p><em>tilemap.py</em></p>
  
  <pre><code>import pygame as pg
  import constants
  
  GRASS = 0
  WATER = 1
  
  
  
  
  textures = {
      GRASS : pg.image.load("image\\grass.png"),
      WATER : pg.image.load("image\\water.png")
  
      }
  
  
  tilemap = [
      [GRASS, GRASS, GRASS, WATER],
      [GRASS, GRASS, WATER, GRASS],
      [GRASS, WATER, GRASS, GRASS],
      [WATER, GRASS, GRASS, GRASS]    
      ]
  
  
  
  tilesize = 40
  mapwidth = 2
  mapheight = 5
  </code></pre>