title: Pygame keeps crashing when I open it
body: <p>I've have this dodging aliens game and it's not working. I can get the front begin screen to open but then when I hit enter to start it crashes and freezes. I've tried running it from python.exe instead of just IDLE but in that case it just pops up then closes right down. A few errors popped up the first few times I tried to run it but now there are no errors indicating what might be wrong. It just stops responding. What am I doing wrong here?</p>
  
  <pre><code>import pygame, random, sys
  from pygame.locals import *
  
  
  def startGame():
      if event.type == K_ENTER:
          if event.key == K_ESCAPE:
              sys.exit()
          return
  
  def playerCollision():
      for a in aliens:
          if playerRect.colliderect(b['rect']):
              return True
      return False
  
  pygame.init()
  
  screen = pygame.display.set_mode((750,750))
  clock = pygame.time.Clock()
  pygame.display.set_caption('Dodge the Aliens')
  
  font = pygame.font.SysFont(None, 55)
  
  playerImage = pygame.image.load('')
  playerRect = playerImage.get_rect()
  alienImage = pygame.image.load('')
  
  drawText('Dodge the Aliens!', font, screen, (750 / 3), (750 / 3))
  drawText('Press ENTER to start.', font, screen, (750 / 3) - 45, (750 / 3) +    65)
  pygame.display.update()
  
  topScore = 0
  while True:
      aliens = []
      score = 0
      playerRect.topleft = (750 /2, 750 - 50)
      alienAdd = 0
      while True:
          score += 1
          pressed = pygame.key.get_pressed()
          if pressed[pygame.K_LEFT]: x -=3
          if pressed[pygame.K_RIGHT]: x += 3
          if pressed[pygame.K_ESCAPE]: sys.exit()
      alienAdd += 1
  
      if alienAdd == addedaliens:
          aliendAdd = 0
          alienSize = random.randint(10, 40)
          newAlien = {'rect': pygame.Rect(random.randint(0, 750 - alienSize), 0 -alienSize, alienSize, alienSize), 'speed': random.randint(1, 8), 'surface':pygame.transform.scale(alienImage, (alienSize, alienSize)), }
          aliens.append(newAlien)
      for a in aliens[:]:
          if a['rect'].top &gt; 750:
              aliens.remove(a)
      screen.fill(0,0,0)
      drawText('Score %s' % (score), font, screen, 10, 0)
      screen.blit(playerImage, playerRect)
      for a in aliens:
          screen.blit(b['surface'], b['rect'])
      pygame.display.update()
  
  
      if playerCollision(playerRect, aliens):
          if score &gt; topScore:
              topScore = score
          break
  
      clock.tick(60)
  
      drawText('Game Over!', font, screen, (750 / 3), ( 750 / 3))
      drawText('Press ENTER To Play Again.', font, screen, ( 750 / 3) - 80, (750 / 3) + 50)
      pygame.display.update()
      startGame()
  </code></pre>
  
  <p>Here's my new code after modifying it some
      import pygame, random, sys
      from pygame.locals import*
      alienimg = pygame.image.load('C:\Python27\alien.png')
      playerimg = pygame.image.load('C:\Python27\spaceship.png')</p>
  
  <pre><code>def playerCollision(): # a function for when the player hits an alien
      for a in aliens:
          if playerRect.colliderect(b['rect']):
              return True
      return False
  
  def screenText(text, font, screen, x, y): #text display function
      textobj = font.render(text, 1, (255, 255, 255))
      textrect = textobj.get_rect()
      textrect.topleft = (x,y)
      screen.blit(textobj, textrect)
  
  def main(): #this is the main function that starts the game
  
      pygame.init()
      screen = pygame.display.set_mode((750,750))
      clock = pygame.time.Clock()
  
      pygame.display.set_caption('Dodge the Aliens') 
      font = pygame.font.SysFont("monospace", 55)
  
  
      pressed = pygame.key.get_pressed()
  
      aliens = []
      score = 0
      alienAdd = 0
      addedaliens = 0
  
      while True: #our while loop that actually runs the game
  
  
  
          for event in pygame.event.get(): #key controls
              if event.type == KEYDOWN and event.key == pygame.K_ESCAPE: 
                  sys.exit()
              elif event.type == KEYDOWN and event.key == pygame.K_LEFT: 
                  playerRect.x -= 3
  
              elif event.type == KEYDOWN and event.key == pygame.K_RIGHT:
                  playerRect.x += 3
  
  
            playerImage = pygame.image.load('C:\\Python27\\spaceship.png').convert() # the player images
          playerRect = playerImage.get_rect()
          playerRect.topleft = (750 /2, 750 - 50)
          alienImage = pygame.image.load('C:\\Python27\\alien.png').convert() #alien images   
  
          alienAdd += 1
  
          pygame.display.update()
  
          if alienAdd == addedaliens: # randomly adding aliens of different sizes and speeds
              aliendAdd = 0
              alienSize = random.randint(10, 40)
              newAlien = {'rect': pygame.Rect(random.randint(0, 750 - alienSize), 0 -alienSize, alienSize, alienSize), 'speed': random.randint(1, 8), 'surface':pygame.transform.scale(alienImage, (alienSize, alienSize)), }
              aliens.append(newAlien)
          for a in aliens[:]:
              if a['rect'].top &gt; 750:
                  aliens.remove(a) #removes the aliens when they get to the bottom of the screen
  
          screen.blit(screen, (0,0))
          screenText('Score %s' % (score), font, screen, 10, 0)
          screen.blit(playerImage, playerRect)
          for a in aliens:
              screen.blit(b['surface'], b['rect'])
          pygame.display.flip()
  
  
          if playerCollision(playerRect, aliens):
              if score &gt; topScore:
                  topScore = score
              break
  
  
          clock.tick(60)
  
          screenText('Game Over!', font, screen, (750 / 6), ( 750 / 6))
          screenText('Press ENTER To Play Again.', font, screen, ( 750 / 6) - 80, (750 / 6) + 50)
          pygame.display.update()
  
  main()
  </code></pre>