def __init__(self, screen): self.screen = screen self.menu = EzMenu( ["New Game", lambda: game.main(self.screen)], ["Quit Game", lambda: credits.main(self.screen)], ["Settings", lambda: game.main(self.screen)], ) self.menu.set_highlight_color((255, 255, 255)) self.menu.set_normal_color((10, 10, 10)) self.menu.center_at(550, 470) self.menu.set_font(pygame.font.Font(filepath("pointy.ttf"), 36)) #start music playing forever pygame.mixer.init() pygame.mixer.music.set_volume(0.8) pygame.mixer.music.load(data.filepath('felix8.xm')) pygame.mixer.music.play(-1) self.main_loop()
def main(screen): running = True clicked = False background = p.Surface(screen.get_size()) background = background.convert() background.fill((250, 250, 250)) startbutton = loadify("Bones-WalkingRight-Rightfoot.png") startbutton = p.transform.scale(startbutton, (100,80)) startbuttonpos = startbutton.get_rect() startbuttonpos.centerx = background.get_rect().centerx startbuttonpos = startbuttonpos.move(0,350) font = p.font.Font(None, 36) text = font.render("CONTROLS", 1, (10, 10, 10)) textpos = text.get_rect() textpos.centerx = background.get_rect().centerx textpos = textpos.move(15,550) back = loadify("startscreen.png") backpos = back.get_rect() back = p.transform.scale(back, (800,600)) background.blit(back, backpos) #background.blit(text, textpos) background.blit(startbutton, startbuttonpos) screen.blit(background, (0, 0)) p.display.flip() cursor = p.transform.scale(loadify("cursor-small-arrow.png").convert_alpha(), (15,15)) while running: #screen.fill([255, 255, 255]) clicked = False for event in p.event.get(): if event.type == p.QUIT: running = False return "quit" elif event.type == p.MOUSEBUTTONUP: clicked = True key = p.key.get_pressed() if key[p.K_ESCAPE]: running = False return "quit" if clicked: if 35 < p.mouse.get_pos()[0] < 250 and 445 < p.mouse.get_pos()[1] < 530: play_sound("Button_Click") running = False elif 550 < p.mouse.get_pos()[0] < 765 and 445 < p.mouse.get_pos()[1] < 530: play_sound("Button_Click") c = credits.main(screen) if c == "quit": running = False return "quit" if c == "back": running = True elif 290 < p.mouse.get_pos()[0] < 505 and 445 < p.mouse.get_pos()[1] < 530: play_sound("Button_Click") o = controls.main(screen) if o == "quit": running = False return "quit" elif o == "back": running = True background.fill((250, 250, 250)) background.blit(back, backpos) #background.blit(text, textpos) background.blit(startbutton, startbuttonpos) p.mouse.set_visible(False) background.blit(cursor, p.mouse.get_pos()) screen.blit(background, (0, 0)) p.display.flip()
def openCredits(menu): del menu credits.main()