def start_render(screen, fps, clock): running = True is_show_account = False background = pygame.image.load("image/background.jpg") last_level = -1 active_button = "" buttons = { "Dungeon time": (34, 28, 532, 86), "Exit": (388, 455, 178, 78), "Play": (34, 455, 249, 78), "New": (34, 330, 248, 81), "": (338, 156, 228, 256) } while running: rating = get_rating() screen.blit(background, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.MOUSEMOTION: active_button = move_to_button_check(screen, event.pos, buttons) if event.type == pygame.MOUSEBUTTONDOWN: if active_button != "": if active_button == "Exit": exit() if active_button == "Play": if last_level != -1: running = False if active_button == "New": form_render(screen, fps, clock) elif (event.pos[0] in range( 338, 567)) and (event.pos[1] in range(156, 412)): x = (event.pos[1] - 156) // 32 if rating[x][0] != None: is_show_account = True if is_show_account: last_level = rating[x][2].index(0) if 0 in rating[x][2] else 8 last_level = 1 if last_level == 0 else last_level show_account(screen, rating[x][0], rating[x][1], last_level) if active_button != "": active_button_mark(screen, buttons[active_button]) for title in buttons: create_button(screen, buttons[title], title, 80, "stone_texture") create_rating_elem(screen, rating) pygame.display.flip() screen.blit(background, (0, 0)) return last_level, x
def win_render(screen, fps, clock, level_n, score): figures = { "": (184, 238, 233, 124), "You won": (206, 251, 189, 24) } buttons = { "Continue": (195, 322, 77, 20), "Again": (330, 322, 77, 20) } active_button = "" running = True star_img = pygame.image.load("image/star.jpg") star_empty_img = pygame.image.load("image/star_empty.jpg") star_img.set_colorkey((255, 255, 255)) star_empty_img.set_colorkey((255, 255, 255)) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.MOUSEMOTION: active_button = move_to_button_check(screen, event.pos, buttons) if event.type == pygame.MOUSEBUTTONDOWN: if active_button != "": running = False if active_button == "Again": result = level_n if active_button == "Continue": result = level_n + 1 for title in figures: create_button(screen, figures[title], title, 60, "stone_texture") if active_button != "": active_button_mark(screen, buttons[active_button]) for title in buttons: create_button(screen, buttons[title], title, 20, "lava_texture") for star in range(3): screen.blit(star_empty_img, (234 + (53 * star), 288)) for star in range(score): screen.blit(star_img, (234 + (53 * star), 288)) pygame.display.flip() clock.tick(fps) return result
def lose_render(screen, fps, clock, level_n): background = pygame.image.load("image/background.jpg") figures = { "": (184, 238, 233, 124), "You lose": (206, 251, 189, 24) } buttons = { "Main": (195, 322, 77, 20), "Again": (330, 322, 77, 20) } active_button = "" running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.MOUSEMOTION: active_button = move_to_button_check(screen, event.pos, buttons) if event.type == pygame.MOUSEBUTTONDOWN: if active_button != "": running = False if active_button == "Again": result = level_n if active_button == "Main": screen.blit(background, (0, 0)) result = 0 for title in figures: create_button(screen, figures[title], title, 60, "stone_texture") if active_button != "": active_button_mark(screen, buttons[active_button]) for title in buttons: create_button(screen, buttons[title], title, 20, "lava_texture") pygame.display.flip() return result
def menu_render(screen, fps, clock): figures = {"": (194, 113, 212, 375), "Pause": (223, 129, 155, 74)} buttons = { "Continue": (222, 238, 155, 39), "Management": (222, 328, 155, 39), "Exit": (222, 417, 155, 39) } active_button = "" running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN: if event.key == 27: running = False if event.type == pygame.MOUSEMOTION: active_button = move_to_button_check(screen, event.pos, buttons) if event.type == pygame.MOUSEBUTTONDOWN: if active_button != "": if active_button == "Exit": exit() if active_button == "Continue": running = False if active_button == "Management": system("management.py") for title in figures: create_button(screen, figures[title], title, 60, "stone_texture") if active_button != "": active_button_mark(screen, buttons[active_button]) for title in buttons: create_button(screen, buttons[title], title, 30, "lava_texture") pygame.display.flip()
def form_render(screen, fps, clock): background = pygame.image.load("image/background.jpg") width = 1 name = "" font = pygame.font.Font("font.ttf", 30) figures = {"": (103, 206, 394, 188), "New account": (158, 231, 285, 39)} buttons = { "Create": (338, 338, 123, 37), "Cancle": (126, 338, 123, 37), "Write zone": (157, 280, 285, 39) } active_button = "" running = True while running: screen.blit(background, (0, 0)) for event in pygame.event.get(): if event.type == pygame.QUIT: exit() if event.type == pygame.KEYDOWN: if event.key == 27: running = False if event.type == pygame.MOUSEMOTION: active_button = move_to_button_check(screen, event.pos, buttons) if event.type == pygame.MOUSEBUTTONDOWN: if active_button != "": if active_button == "Cancle": running = False if active_button == "Create": if len(name) > 0: new_account(name) running = False width = 3 if active_button == "Write zone" else 1 if event.type == pygame.KEYDOWN: if width == 3: if len(name) < 17: name += event.unicode if event.key == 8: name = name[:-1] for title in figures: create_button(screen, figures[title], title, 60, "stone_texture") if not (active_button in ("", "Write zone")): active_button_mark(screen, buttons[active_button]) for title in buttons: create_button(screen, buttons[title], title, 30, "lava_texture") pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(157, 280, 285, 39), width) p_name = font.render(name, True, (179, 179, 179)) screen.blit(p_name, ((157 + (285 - p_name.get_width()) // 2), (280 + (39 - p_name.get_height()) // 2))) pygame.display.flip() screen.blit(background, (0, 0))