1. import pygame
  2.  
  3. # Import the android module. If we can't import it, set it to None - this
  4. # lets us test it, and check to see if we want android-specific behavior.
  5. try:
  6.     import android
  7. except ImportError:
  8.     android = None
  9.  
  10. def main():
  11.     pygame.init()
  12.  
  13.     # Set the screen size.
  14.     screen = pygame.display.set_mode((480, 800))
  15.  
  16.     # Map the back button to the escape key.
  17.     if android:
  18.         android.init()
  19.         android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
  20.        
  21.     if android:
  22.         yum = android.mixer.Sound("yum.wav")
  23.         yum.play
  24.     else:
  25.         pygame.mixer.init()
  26.         yum = pygame.mixer.Sound("yum.wav")
  27.         yum.play
  28.        
  29.     while True:
  30.         ev = pygame.event.wait()
  31.  
  32.         # Android-specific:
  33.         if android:
  34.             droid = android.Android()
  35.             if android.check_pause():
  36.                 android.wait_for_resume()
  37.  
  38.         # When the user hits back, ESCAPE is sent. Handle it and end
  39.         # the game.
  40.         elif ev.type == pygame.KEYDOWN and ev.key == pygame.K_ESCAPE:
  41.             break
  42.  
  43. # This isn't run on Android.
  44. if __name__ == "__main__":
  45.     main()
  46.