title: Pygame: Drawing Ellipse or Rectangle based on Constructor Argument
body: <p>I don't know if this is the correct website, but you guys have been so helpful before, I wanted to get your advice on a problem I'm having with Python and Pygame.</p>
  
  <p>I am making a simple game, and only recently begun learning Python (loving it so far) and at the moment, I having a sprite constructor which I am using.  This constructor will manage my objects, but I want it to draw either an ellipse or a rectangle based on an argument passed to it.</p>
  
  <pre><code>#My code
  class Block(pygame.sprite.Sprite):
      #Variables!
      speed = 2
      indestructible = True
      #Constructor
      def __init__(self, color, width, height, name, shapeType):
          pygame.sprite.Sprite.__init__(self)
          self.image = pygame.Surface([width,height])
          self.image.fill(color)
          #Choose what to draw
          if shapeType == "Ellipse":
              pygame.draw.ellipse(self.image,color,[0,0,width,height])
          elif shapeType == "Rect":
              pygame.draw.rect(self.image,color,[0,0,width,height])
          elif shapeType == "":
              print("Shape type for ",name," not defined.")
              pygame.draw.rect(self.image,color,[0,0,width,height])
          #Init the Rect class for sprites
          self.rect = self.image.get_rect()
  </code></pre>
  
  <p>The coding I am using for drawing a square is below:</p>
  
  <pre><code>#Add 'white star' to the list
  for i in range(random.randrange(100,200)):
      whiteStar = Block(white, 1, 1, "White Star", "Rect")
      whiteStar.rect.x = random.randrange(size[0])
      whiteStar.rect.y = random.randrange(size[1])
      whiteStar.speed = 2
      block_list.add(whiteStar)
      all_sprites_list.add(whiteStar)
  </code></pre>
  
  <p>This works wonderfully.  It draws a perfect little white square for me. But <em>this</em> doesn't work:</p>
  
  <pre><code>#Create Planet
  planet = Block(green, 15,15, "Planet", "Ellipse")
  planet.rect.x = random.randrange(size[0])
  planet.rect.y = 30
  planet.speed = 1
  block_list.add(planet)
  all_sprites_list.add(planet)
  </code></pre>
  
  <p>The 'planet' spawns correctly, but it does so as a square.  Why is this happening? And how can I fix it?  Should I use a bitmap to correct this?  Or is my coding wrong?</p>
  
  <p>Just to clarify, I know for a fact that <code>self.rect = self.image.get_rect()</code> <em>does</em> work to draw an ellipse, because the coding below works.</p>
  
  <pre><code>#Not the code I'm using, but this works and proves self.rect = self.image.get_rect() is not the cause
  # Call the parent class (Sprite) constructor
      pygame.sprite.Sprite.__init__(self) 
  
      # Create an image of the block, and fill it with a color.
      # This could also be an image loaded from the disk.
      self.image = pygame.Surface([width, height])
      self.image.fill(white)
      self.image.set_colorkey(white)
      pygame.draw.ellipse(self.image,color,[0,0,width,height])
  
      # Fetch the rectangle object that has the dimensions of the image
      # image.
      # Update the position of this object by setting the values 
      # of rect.x and rect.y
      self.rect = self.image.get_rect()
  </code></pre>
  
  <p>Thankyou for your help. :-)</p>