Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def menuScreen(surf):
- surf.fill(black)
- options = [Buttons("Start Game", displayWidth/2, 10, 0),
- Buttons("Settings", displayWidth/2, 75, 1),
- Buttons("Quit Game", displayWidth/2, 140, 2)]
- result = choose(options)
- if result == 0:
- main()
- elif result == 1:
- settingsScreen(surf)
- else:
- pygame.quit()
- def settingsScreen(surf):
- surf.fill(black)
- settings = [Buttons("1024 x 768", displayWidth/2, 10, 0), #-----Buttons have the following attributes: "use", (x,y) and the choice number
- Buttons("1280 x 720", displayWidth/2, 75, 1),
- Buttons("1920 x 1080", displayWidth/2, 140, 2),
- Buttons("Go back", displayWidth/2, 215, 3)]
- result = choose(settings) #----------Get the option chosen by the user from the screen
- if result == 0:
- surf = pygame.display.set_mode((1024, 768))
- elif result == 1:
- surf = pygame.display.set_mode((1280, 720))
- elif result == 2:
- surf = pygame.display.set_mode((1920, 1080))
- else:
- menuScreen(surf)
- #-------------Go back to the menu
- settingsScreen(surf) #-----------after a resolution is set refresh the settings screen if anything else should change
- def choose(array):
- selection = True
- counter = 0
- while selection: #----While the user hasn't made a choice yet
- for i in range(len(array)): #----Write every item in the given array to the screen
- 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
- for e in pygame.event.get():
- if e.type == pygame.QUIT:
- sys.exit()
- if e.type == pygame.KEYDOWN:
- if e.key == pygame.K_w:
- if counter > 0:
- counter -=1
- if e.key == pygame.K_s:
- if counter < len(array) - 1: #-----For functions that have less options, eg menu and settings, limit the user
- counter += 1 #-----to only the choices available
- if e.key == pygame.K_RETURN: #------If the user makes their choice return the number of the option they chose
- return counter
- selection = False
- pygame.display.update()
- array[i].changeColour(counter) #-----Change the colour of the text depending on which line it is
- def drawText(surf, text, size, colour, x, y):
- font = pygame.font.Font(font_name, size) #---Set the font used to write text
- text_surface = font.render(text, True, colour)
- text_rect = text_surface.get_rect() #---Get the rectangle of the text box
- text_rect.midtop = (x, y)
- surf.blit(text_surface, text_rect) #---Add text on screen
- class Buttons:
- def __init__(self, text, x, y, number):
- self.text = text
- self.x = x
- self.y = y
- self.number = number
- self.colour = white
- def changeColour(self, counter):
- if self.number == counter: #--- If the counter is the same as the option number, make the option a different colour
- self.colour = orange
- else:
- self.colour = white
- def waveCreator():
- for monsters in range(listForWaves[0]):
- monsters = Enemy(random.randint(0, 1), random.sample(["skeleton", "zombie"], 1))
- mobs.add(monsters)
- game_sprites.add(monsters)
- listForWaves.pop(0)
- class Platforms(pygame.sprite.Sprite):
- def __init__(self, width, height, x, bottom):
- pygame.sprite.Sprite.__init__(self)
- self.image = pygame.Surface((width, height))
- self.image.fill(brown)
- self.rect = self.image.get_rect()
- self.rect.x = x
- self.rect.bottom = bottom
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement