title: Draw Tank in Certain Place
body: <p>Currently, I am trying to make my tank to draw in the designated place that I have written in my code. </p>
  
  <p>Code: </p>
  
  <pre><code>import pygame, assetloader
  from pygame.locals import *
  import random, time, math
  import pygame
  
  GRAD = math.pi/180
  blue = (0, 0, 255)
  
  wallRects = []
  
  maze = [[] for i in range(25)] 
  
  assetloader.set_asset_path("assets/")
  
  def generateMaze():
      global grid
      width  = 12
      height = 12
      seed   = time.time()
  
      random.seed(seed)
  
      grid = [[0 for j in range(width)] for i in range(height)]
  
      N, S, E, W = 1, 2, 4, 8
      DX         = { E: 1, W: -1, N: 0, S: 0 }
      DY         = { E: 0, W:  0, N: -1, S: 1 }
      OPPOSITE   = { E: W, W:  E, N: S, S: N }
  
      def carve_passages_from(cx, cy, grid):
          directions = random.sample([N, S, E, W], 4)
  
          for direction in directions:
              nx, ny = cx + DX[direction], cy + DY[direction]
  
              if (ny &gt;= 0 and ny &lt;= len(grid) - 1) and (nx &gt;= 0 and nx &lt;= len(grid[0]) - 1) and grid[ny][nx] == 0:
                  grid[cy][cx] += direction
                  grid[ny][nx] += OPPOSITE[direction]
                  carve_passages_from(nx, ny, grid)
  
      carve_passages_from(0, 0, grid)
  
      global maze
      maze[0] = [2 for i in range(25)]
      mrow = 1
  
      # 0 = path
      # 1 = vertical wall
      # 2 = horizontal wall
      for y in range(height):
          row1 = maze[mrow]
          row2 = maze[mrow+1]
          row1.append(1)
          row2.append(1)
          for x in range(width):
              if grid[y][x] &amp; S != 0:
                  row1.append(0)
                  row2.append(0)
              else:
                  row1.append(0)
                  row2.append(2)
              if grid[y][x] &amp; E != 0:
                  if (grid[y][x] | grid[y][x+1]) &amp; S != 0:
                      row1.append(0)
                      row2.append(0)
                  else:
                      row1.append(0)
                      row2.append(2)
              else:
                  row1.append(1)
                  if y &lt; height - 1:
                      row2.append(1)
                  else:
                      row2.append(2)
          mrow += 2
  
  def printMaze():
      for row in range(len(maze)):
          for col in range(len(maze[row])):
              print maze[row][col],
          print
  
  def CreateWallRects():
      for row in range(len(maze)):
          for col in range(len(maze[row])):
              if maze[row][col] == 1 and row &lt; 23:
                  x = (start_x + col * gsize) + (0.5 * gsize) - 1
                  y = (start_y + (row - 1) * gsize) + (0.5 * gsize)
                  wallRects.append(pygame.Rect(x, y, 3, gsize)) 
              elif maze[row][col] == 1 and row == 23:
                  x = (start_x + col * gsize) + (0.5 * gsize) - 1
                  y = (start_y + (row - 1) * gsize) + (0.5 * gsize)
                  wallRects.append(pygame.Rect(x, y, 3, gsize * 2))
              elif maze[row][col] == 2:
                  x = (start_x + (col-1) * gsize) + (0.5 * gsize) 
                  y = (start_y + row * gsize) + (0.5 * gsize) - 1
                  wallRects.append(pygame.Rect(x, y, gsize * 2, 3))
  
  def drawMaze():
  
      lineColor = 255, 255, 255
  
      for x in range(0, width, gsize):
          pygame.draw.line(screen, lineColor, (x, 0), (x, height), 3)    #line(Surface, color, start_pos, end_pos, width=1)
  
      for y in range(0, height, gsize):
          pygame.draw.line(screen, lineColor, (0, y), (width, y), 3)
  
      wallColor = 0, 0, 0
      for wr in wallRects:
          pygame.draw.rect(screen, wallColor, wr)    
  
  class Player(pygame.sprite.Sprite):
      def __init__(self, x, y, pos):
          pygame.sprite.Sprite.__init__(self)
  
          self.image, self.rect = assetloader.load_image("Tank.png", -1)
          self.rect.x = x
          self.rect.y = y
          self.rect.clamp_ip(screen.get_rect())
          self.dir = 0
          self.vel_y = 0
          self.vel_x = 0
          self.rows = pos[0]
          self.cols = pos[1]
          self.x = self.cols * gsize
          self.y = self.rows * gsize
   #       self.orig_image, self.orig_rect = assetloader.load_image(img_name, -1) 
          self.orig_rect.x = self.x
          self.orig_rect.y = self.y
          self.orig_gun_pos = self.orig_rect.midtop
          self.ammo = 5
          self.vel = [0, 0]
          self.dead = False
  
      def draw(self, screen):
          image = pygame.transform.rotate(self.image, self.dir)
          screen.blit(image, self.rect)
  
      def update(self):
          oldCenter = self.rect.center
  
          self.rect = self.image.get_rect()
          self.rect.center = oldCenter
          screen_rect = screen.get_rect()
          keys = pygame.key.get_pressed()
  
          if keys[K_UP]:
              if (0 &lt; self.dir and self.dir &lt; 90) or (-360 &lt; self.dir and self.dir &lt; -270):
                 self.vel_x = -1
  
                 self.vel_y = -1
              elif (270 &lt; self.dir and self.dir &lt; 360) or (-90 &lt; self.dir and self.dir &lt; 0):
                  self.vel_x = 1
                  self.vel_y = -1
              if (90 &lt; self.dir and self.dir &lt; 180) or (-270 &lt; self.dir and self.dir &lt; -180):
                  self.vel_x = -1
                  self.vel_y = 1
  
              elif (180 &lt; self.dir and self.dir &lt; 270) or (-180 &lt; self.dir and self.dir &lt; -90):
                  self.vel_x = 1
                  self.vel_y = 1
  
              if self.dir == 0 :
                  self.vel_x = 0
                  self.vel_y = -1
              if self.dir == 90 :
                  self.vel_x = -1
                  self.vel_y = 0
              if self.dir == 180:
                  self.vel_x = 0
                  self.vel_y = 1
              if self.dir == 270:
                  self.vel_x = 1
                  self.vel_y = 0
  
              self.rect.move_ip(self.vel_x, self.vel_y)
  
          elif keys[K_DOWN]:
  
              if (0 &lt; self.dir and self.dir &lt; 90) or (-360 &lt; self.dir and self.dir &lt; -270):
                 self.vel_x = 1
  
                 self.vel_y = 1
              elif (270 &lt; self.dir and self.dir &lt; 360) or (-90 &lt; self.dir and self.dir &lt; 0):
                  self.vel_x = -1
                  self.vel_y = 1
              if (90 &lt; self.dir and self.dir &lt; 180) or (-270 &lt; self.dir and self.dir &lt; -180):
                  self.vel_x = 1
                  self.vel_y = -1
  
              elif (180 &lt; self.dir and self.dir &lt; 270) or (-180 &lt; self.dir and self.dir &lt; -90):
                  self.vel_x = -1
                  self.vel_y = -1
  
              if self.dir == 0 :
                  self.vel_x = 0
                  self.vel_y = 1
              if self.dir == 90 :
                  self.vel_x = 1
                  self.vel_y = 0
              if self.dir == 180:
                  self.vel_x = 0
                  self.vel_y = -1
              if self.dir == 270:
                  self.vel_x = -1
                  self.vel_y = 0 
  
              self.rect.move_ip(self.vel_x, self.vel_y)
  
          if keys[K_LEFT]:
              self.dir += 5
              if self.dir &gt; 360:
                  self.dir = 0
          elif keys[K_RIGHT]:
              self.dir -= 5
              if self.dir &lt; -360:
                  self.dir = 0    
  
          if not screen_rect.contains(self.rect):
              self.rect.clamp_ip(screen_rect)
  
  size = width, height = 500, 400
  gsize = 25
  start_x, start_y = 0, 0
  bgColor = 255, 255, 255
  
  pygame.init()
  screen = pygame.display.set_mode(size)#, pygame.FULLSCREEN)
  pygame.display.set_caption("Sample Sprite")
  clock = pygame.time.Clock()
  
  p = Player(width/2, height/4, pos)
  
  coll_font = pygame.font.Font(None, 30)
  
  going = True
  while going:
      clock.tick(60)
      for event in pygame.event.get():
          if event.type == QUIT:
              going = False
          elif event.type == KEYDOWN:
              if event.key == K_ESCAPE:
                  going = False
  
          p.update()
  
          screen.fill(bgColor)
  
          p.draw(screen)
  
          pygame.display.flip()
  
  pygame.quit()
  </code></pre>
  
  <p>I know that the init function that I used for class Player contains four things <code>(self, x, y, pos)</code>, and I have <code>Player(width/2, height/4, pos)</code> to define where it gets placed right now - but it says pos is undefined. So what should I use to substitue or define "pos" somewhere else?</p>
  
  <p>Right now, I am getting :</p>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
    File "tinytanks3.py", line 375, in &lt;module&gt;
      p = Player(width/2, height/4, pos)
  NameError: name 'pos' is not defined
  </code></pre>
  
  <p>Can someone please explain what to put for pos and why?</p>