def menu_loop(): pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096) pygame.mixer.music.load("sound/hearthbeat.wav") pygame.mixer.music.play() menu_screen = pygame.display.set_mode((854, 480)) menu_screen.fill((51, 51, 51)) menu = Menu(['Start', 'Options', 'Quit'], menu_screen) menu.draw() pygame.key.set_repeat(199, 69) # (delay,interval) pygame.display.update() while 1: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: menu.draw(-1) # here is the Menu class function if event.key == pygame.K_DOWN: menu.draw(1) # here is the Menu class function if event.key == pygame.K_RETURN: if menu.get_position() == 2: # here is the Menu class function pygame.quit() sys.exit() elif menu.get_position() == 0: Main(800, 800, 100) pygame.init() menu_loop() if event.key == pygame.K_ESCAPE: pygame.display.quit() sys.exit() pygame.display.update() elif event.type == pygame.QUIT: pygame.display.quit() sys.exit() pygame.time.wait(8)
def getPlayer(self): rtnObject = self.returnObject() # Starting screen text title = self.titleFont.render("Chocotaco Othello",True,DULLYELLOW) self.display.blit(title,(int(self.boardWidth/4),50)) info = [pygame.Surface]*4 info[0] = self.font.render("Select playing option using the UP & DOWN arrow keys.", True, WHITE) info[1] = self.font.render("Set computer timeout using the LEFT & RIGHT arrow keys",True, WHITE) info[2] = self.font.render("Make a selection using the ENTER key", True,WHITE) info[3] = self.font.render("Press SPACE to set layout for configuration", True, WHITE) for n, blurb in enumerate(info): self.display.blit(blurb, (75, self.boardWidth/4+32*n)) #Time out information timeOut = 5 timeOutLabel = self.font.render("Timeout", True, WHITE) self.display.blit(timeOutLabel,(int(3*self.windowSize/4)+16, int(self.boardWidth/2)+32)) self.showTimeout(timeOut) #Actual Menu menu = Menu() menu.init(['Go First (Black)', 'Go Second (White)','Comp V Comp','Quit'], self.display) menu.draw() pygame.key.set_repeat(199,69) pygame.display.update() while 1: for event in pygame.event.get(): if event.type == KEYDOWN: if event.key == K_LEFT: if timeOut >2: timeOut -= 1 self.showTimeout(timeOut) elif event.key == K_RIGHT: if timeOut < 15: timeOut += 1 self.showTimeout(timeOut) elif event.key == K_UP: menu.draw(-1) #here is the Menu class function elif event.key == K_DOWN: menu.draw(1) #here is the Menu class function elif event.key == K_RETURN or event.key == K_SPACE: if menu.get_position() == 0: # rtnObject.players = ["h", "c"] return ["h", "c"], timeOut, (event.key == K_SPACE) elif menu.get_position() == 1: # rtnObject.players =["c", "h"] return ["c", "h"], timeOut, (event.key == K_SPACE) elif menu.get_position() == 2: # rtnObject.players =["c", "c"] return ["c", "c"], timeOut, (event.key == K_SPACE) elif menu.get_position() == 4: pygame.display.quit() sys.exit() if event.key == K_ESCAPE: pygame.display.quit() sys.exit() pygame.display.update() elif event.type == QUIT: pygame.display.quit() sys.exit()
def menu_game(): #Функция, извеждаща менюто pygame.mixer.init(44100, -16,2,2048) #Инициализация на миксера #Промяна на иконата на прозореца icon = pygame.image.load("files/Skins/Martincho.png") icon = pygame.transform.scale(icon, (32, 32)) pygame.display.set_icon(icon) pygame.mouse.set_visible(0) #В заглавната лента се извежда името на играта pygame.display.set_caption("RBP_V1.2") #Избор на размер на прозореца screen = pygame.display.set_mode(DISPLAY, pygame.FULLSCREEN) #Зареждане на фон на менюто background = pygame.image.load("files/Martinchovcite_menu1.png") background = pygame.transform.scale(background, (1450,805)) screen.blit(background, (-40, -60)) #Пояснителен текст над менюто font=pygame.font.Font('files/Fonts/Adventure Subtitles.ttf',30) menutext=font.render("MENU", 1,(145,183,220)) screen.blit(menutext, (720, 270)) menu = Menu() #Инициализация на менюто #Задаване на цветовете на фона, маркера и текста на менюто menu.set_colors((145,183,220),(36,36,168),(59,60,189)) #Задаване на размер на менюто menu.set_fontsize(30) #Задаване на позиция, където менюто ще бъде изведено menu.move_menu(85, 37) #Задаване на съдържанието menu.init(['Start','Help','About','Quit'], screen) #Изчертаване на менюто menu.draw() pygame.key.set_repeat(199,69) pygame.display.update() sound = pygame.mixer.Sound('files/Sounds/menu.wav') #Задаване на музика sound.set_volume(0.05) #Задаване на сила на звука while 1: sound.play() #Изпълнение на музиката for event in pygame.event.get(): #Проверка коя от опциите е избрана и изпълнение на съответната функция if event.type == KEYDOWN: if event.key == K_UP: menu.draw(-1) if event.key == K_DOWN: menu.draw(1) if event.key == K_RETURN: if menu.get_position() == 0: sound.stop() game('Level_1', 3) if menu.get_position() == 1: sound.stop() help() if menu.get_position() == 2: sound.stop() about() if menu.get_position() == 3: pygame.display.quit() sys.exit() if event.key == K_ESCAPE: pygame.display.quit() sys.exit() pygame.display.update() elif event.type == QUIT: pygame.display.quit() sys.exit() pygame.time.wait(8)