Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.88 KB | None | 0 0
  1.  
  2. def menuScreen(surf):
  3.     surf.fill(black)
  4.     options = [Buttons("Start Game", displayWidth/2, 10, 0),
  5.             Buttons("Settings", displayWidth/2, 75, 1),
  6.             Buttons("Quit Game", displayWidth/2, 140, 2)]
  7.     result = choose(options)
  8.     if result == 0:
  9.         main()
  10.     elif result == 1:
  11.         settingsScreen(surf)
  12.     else:
  13.         pygame.quit()
  14.  
  15.  
  16. def settingsScreen(surf):
  17.     surf.fill(black)
  18.     settings = [Buttons("1024 x 768", displayWidth/2, 10, 0), #-----Buttons have the following attributes: "use", (x,y) and the choice number
  19.                 Buttons("1280 x 720", displayWidth/2, 75, 1),
  20.                 Buttons("1920 x 1080", displayWidth/2, 140, 2),
  21.                 Buttons("Go back", displayWidth/2, 215, 3)]
  22.     result = choose(settings) #----------Get the option chosen by the user from the screen
  23.  
  24.     if result == 0:
  25.         surf = pygame.display.set_mode((1024, 768))
  26.     elif result == 1:
  27.         surf = pygame.display.set_mode((1280, 720))
  28.     elif result == 2:
  29.         surf = pygame.display.set_mode((1920, 1080))
  30.     else:
  31.         menuScreen(surf)
  32.         #-------------Go back to the menu
  33.     settingsScreen(surf) #-----------after a resolution is set refresh the settings screen if anything else should change
  34.  
  35.  
  36. def choose(array):
  37.     selection = True
  38.     counter = 0
  39.     while selection: #----While the user hasn't made a choice yet
  40.         for i in range(len(array)): #----Write every item in the given array to the screen
  41.             drawText(screen, array[i].text, 42, array[i].colour, array[i].x, array[i].y) #-----Write text to the screen by using the items in the provided list
  42.             for e in pygame.event.get():
  43.                 if e.type == pygame.QUIT:
  44.                     sys.exit()
  45.                 if e.type == pygame.KEYDOWN:
  46.                     if e.key == pygame.K_w:
  47.                         if counter > 0:
  48.                             counter -=1
  49.  
  50.                     if e.key == pygame.K_s:
  51.                         if counter < len(array) - 1: #-----For functions that have less options, eg menu and settings, limit the user
  52.                             counter += 1             #-----to only the choices available
  53.  
  54.                     if e.key == pygame.K_RETURN: #------If the user makes their choice return the number of the option they chose
  55.                         return counter
  56.                         selection = False
  57.             pygame.display.update()
  58.             array[i].changeColour(counter) #-----Change the colour of the text depending on which line it is
  59.  
  60.  
  61. def drawText(surf, text, size, colour, x, y):
  62.     font = pygame.font.Font(font_name, size) #---Set the font used to write text
  63.     text_surface = font.render(text, True, colour)
  64.     text_rect = text_surface.get_rect() #---Get the rectangle of the text box
  65.     text_rect.midtop = (x, y)
  66.     surf.blit(text_surface, text_rect) #---Add text on screen
  67.  
  68.  
  69. class Buttons:
  70.     def __init__(self, text, x, y, number):
  71.         self.text = text
  72.         self.x = x
  73.         self.y = y
  74.         self.number = number
  75.         self.colour = white
  76.  
  77.     def changeColour(self, counter):
  78.         if self.number == counter: #--- If the counter is the same as the option number, make the option a different colour
  79.             self.colour = orange
  80.         else:
  81.             self.colour = white
  82. def waveCreator():
  83.     for monsters in range(listForWaves[0]):
  84.         monsters = Enemy(random.randint(0, 1), random.sample(["skeleton", "zombie"], 1))
  85.         mobs.add(monsters)
  86.         game_sprites.add(monsters)
  87.     listForWaves.pop(0)
  88.  
  89.  
  90. class Platforms(pygame.sprite.Sprite):
  91.     def __init__(self, width, height, x, bottom):
  92.         pygame.sprite.Sprite.__init__(self)
  93.         self.image = pygame.Surface((width, height))
  94.         self.image.fill(brown)    
  95.         self.rect = self.image.get_rect()
  96.         self.rect.x = x
  97.         self.rect.bottom = bottom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement