def menu(): while True: #!son.play() screen.blit(background, (0, 0)) text('menu', font, (255, 255, 255), screen, 20, 20) mx, my = pygame.mouse.get_pos() button_1 = pygame.Rect(490, 300, 300, 75) button_2 = pygame.Rect(490, 400, 300, 75) button_3 = pygame.Rect(490, 500, 300, 75) button_4 = pygame.Rect(490, 600, 300, 75) if button_1.collidepoint((mx, my)): if click: modedejeu() if button_2.collidepoint((mx, my)): if click: instructions() if button_3.collidepoint((mx, my)): if click: options() if button_4.collidepoint((mx, my)): if click: credits() pygame.draw.rect(screen, (0, 0, 0), button_1) pygame.draw.rect(screen, (0, 0, 0), button_2) pygame.draw.rect(screen, (0, 0, 0), button_3) pygame.draw.rect(screen, (0, 0, 0), button_4) text('JOUER', font, (255, 255, 255), screen, 575, 320) text('INSTRUCTIONS', font, (255, 255, 255), screen, 505, 420) text('OPTIONS', font, (255, 255, 255), screen, 555, 520) text('CREDITS', font, (255, 255, 255), screen, 555, 620) click = False for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE: pygame.quit() sys.exit() if event.type == MOUSEBUTTONDOWN: if event.button == 1: click = True pygame.display.update() mainClock.tick(60)
def _process_input(self, input): """ Process a keypress from the user. """ # Check that input is a single character and convert it to upper-case. if input > 255: return char = chr(input).upper() # If the input is not available from the current menu (and isn't X, # which exits the menu), ignore it. if char not in ([item.trigger for item in self._current_menu.menu_items] + ["X", "A"]): return # If the user pressed "X", drop out of this menu (or the CLI). if char == "X": # Move to the parent menu of this one. If there is no parent, # exit the CLI. if self._current_menu.parent is not None: self._current_menu = self._current_menu.parent else: raise Cli.ExitCli elif char == "A": # Invoke the credit sequence. credits(self._main_win) else: # The user must have pressed a key associated with one of the # menu items. Trigger the associated action. selected_item = None for item in self._current_menu.menu_items: if char == item.trigger: selected_item = item if selected_item is None: # Invalid input. This should be impossible. Assert. raise AssertionError, "Input invalid for this menu." self._print_to_win("Processing command: " + selected_item.text, self._event_win, curses.color_pair(2)) if selected_item.action is not None: # Put the action on the queue. No actions currently have # associated parameters. act = Action(selected_item.action, None) self._action_queue.put(act) # Move to the menu specified by the item. self._current_menu = selected_item.next_menu return
def start(DISPLAY_SURF): background = pygame.image.load('Images/simphy.jpg') btn_start = pygame.image.load('Images/buttons/playbutton.png') btn_credits = pygame.image.load('Images/buttons/creditsbutton.png') btn_manual = pygame.image.load('Images/buttons/manualbutton.png') clock = pygame.time.Clock() # background=pygame.image.load('Images/simphy.jpg') run = True DISPLAY_SURF = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT), 0, 32) # create the animation objects ('filename of image', duration_in_seconds) boltAnim = pyganim.PygAnimation([ ('Images/simphyimages/s.jpg', 0.2), ('Images/simphyimages/m.jpg', 0.2), ('Images/simphyimages/p.jpg', 0.2), ('Images/simphyimages/h.jpg', 0.2), ('Images/simphyimages/y.jpg', 0.2), ('Images/simphyimages/notzoom.jpg', 0.2), ('Images/simphyimages/allzoom.jpg', 0.2), ]) boltAnim.play() while run: DISPLAY_SURF.blit(background, SCREEN_TOPLEFT) mouse = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pygame.quit() sys.exit(0) elif event.type == pygame.MOUSEBUTTONDOWN: if rect_start.collidepoint(mouse): demo.startGame(DISPLAY_SURF) elif rect_credits.collidepoint(mouse): credits.credits(DISPLAY_SURF) elif rect_manual.collidepoint(mouse): manual.manual(DISPLAY_SURF) #elif btn.obj.collidepoint(mouse): # manual.manual(DISPLAY_SURF) boltAnim.blit(DISPLAY_SURF, (0, 0)) rect_start = DISPLAY_SURF.blit(btn_start, (210, 185)) rect_credits = DISPLAY_SURF.blit(btn_credits, (210, 250)) rect_manual = DISPLAY_SURF.blit(btn_manual, (210, 315)) pygame.display.update() clock.tick(60)
def start(DISPLAY_SURF): background = pygame.image.load('Images/simphy.jpg') btn_start = pygame.image.load('Images/buttons/playbutton.png') btn_credits = pygame.image.load('Images/buttons/creditsbutton.png') btn_manual = pygame.image.load('Images/buttons/manualbutton.png') clock = pygame.time.Clock() # background=pygame.image.load('Images/simphy.jpg') run = True DISPLAY_SURF = pygame.display.set_mode((SCREEN_WIDTH,SCREEN_HEIGHT), 0, 32) # create the animation objects ('filename of image', duration_in_seconds) boltAnim = pyganim.PygAnimation([('Images/simphyimages/s.jpg', 0.2),('Images/simphyimages/m.jpg', 0.2),('Images/simphyimages/p.jpg', 0.2),('Images/simphyimages/h.jpg', 0.2),('Images/simphyimages/y.jpg', 0.2),('Images/simphyimages/notzoom.jpg',0.2),('Images/simphyimages/allzoom.jpg', 0.2),]) boltAnim.play(); while run: DISPLAY_SURF.blit(background,SCREEN_TOPLEFT) mouse = pygame.mouse.get_pos() for event in pygame.event.get(): if event.type == pygame.QUIT: run = False pygame.quit() sys.exit(0) elif event.type == pygame.MOUSEBUTTONDOWN: if rect_start.collidepoint(mouse): demo.startGame(DISPLAY_SURF) elif rect_credits.collidepoint(mouse): credits.credits(DISPLAY_SURF) elif rect_manual.collidepoint(mouse): manual.manual(DISPLAY_SURF) #elif btn.obj.collidepoint(mouse): # manual.manual(DISPLAY_SURF) boltAnim.blit(DISPLAY_SURF, (0, 0)) rect_start = DISPLAY_SURF.blit(btn_start,(210,185)) rect_credits = DISPLAY_SURF.blit(btn_credits,(210,250)) rect_manual = DISPLAY_SURF.blit(btn_manual,(210,315)) pygame.display.update() clock.tick(60)
def _credits(self): """ Invoke the credits. """ credits(self._main_win)
run = True while run: if(game_state == 0): # setting up the cursor for mainmenu if(pygame.mouse.get_cursor() != pygame.cursors.arrow): pygame.mouse.set_cursor(*pygame.cursors.arrow) # main menu game_state = mainmenu.mainmenu(score) elif(game_state == 1): # setting the cursor for mainloop if(pygame.mouse.get_cursor() != pygame.cursors.diamond): pygame.mouse.set_cursor(*pygame.cursors.diamond) # main game logic game_state, score = mainlogic.mainloop() elif(game_state == 2): # how to play menu game_state = howtoplay.howtoplay() elif(game_state == 3): # credits menu game_state = credits.credits() # updating the display pygame.display.update() # using the FPS CLOCK.tick(FPS)
def credit(self, event): self.creditsWindow = credits() self.creditsWindow.exec_()