def main_menu(): """ The menu loop Parameters: None Returns: int: 0 to close the program """ button_start = pygame.Rect(450, 400, 700, 200) done = False x = 0 y = 0 menuimg = pygame.image.load(os.path.join('images', 'menu.png')).convert() menurect = menuimg.get_rect() while not done: # Frame rate clock.tick(60) # Fill the screen screen.fill(WALL) screen.blit(menuimg, menurect) # Update screen pygame.display.flip() # Events if button_start.collidepoint(x, y) and click == True: return 2 click = False for event in pygame.event.get(): if event.type == pygame.QUIT: return 0 elif event.type == pygame.MOUSEBUTTONDOWN: x, y = pygame.mouse.get_pos() if event.button == 1: click = True return 0
def main(): running = True # main loop while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.MOUSEBUTTONDOWN: mouseX, mouseY = pygame.mouse.get_pos() listpos = round((math.floor((mouseY / size)) * rows + math.floor(mouseX / size))) if not Board[listpos]: create_cell(listpos, None) if event.type == pygame.KEYDOWN: if event.key == pygame.K_p: create_cell(int(len(Board) / 2 + columns / 2), testcell) elif event.key == pygame.K_c: Board.clear() for i in range(rows*columns): Board.append(None) if event.type == FOODSPAWN: while None in Foods: listpos = round((math.floor((random.randint(0, height - 1) / size)) * \ (width / size) + math.floor(random.randint(0, width - 1) / size))) if not Foods[listpos]: break if None in Foods: Foods[listpos] = Food(listpos, (0, 255, 0)) screen.fill((0, 0, 0)) board_run() pygame.display.flip()
def main_game() -> int: """ The game loop Parameters: None Returns: int: 0 to close the program """ board.draw_grid(screen) board.maze_prim(1, 1, screen) board.store_maze(screen) board.free_space() for i in range(len(fruit_list)): fruit_list[i].set_position() done = False while not done: # Frame rate clock.tick(60) # Fill the screen screen.fill(STANDARD_COLOR) # Draw and update sprites sprite_list.draw(screen) sprite_list.update() # Draw the maze board.draw_maze(screen) # Update screen pygame.display.flip() # Treats player interaction for event in pygame.event.get(): done = treats_event(event) return 0
def buttons_on_click(x: int, y: int) -> None: """check if the mouse click the button Parameters: x (int): x screen coordinate y (int): y screen coordinate """ for i in range(len(buttons)): if buttons[i].check(x, y): screen.fill(LIGHTBLUE) board.draw_grid(screen) if (buttons[i].color == PRIM_COLOR): board.maze_kruskal(screen)
clock = Clock() background = Background() som = Som() placar = Placar() controle = Controle() enemylist = [Wooden, Steam] paralaxe = 0 running = True stopgame = True # som.play() while running: clock.tick(25) screen.fill((255, 255, 255)) if not stopgame: if tick_enemies == 0: if background.distance % DIFICULT_AVANCE == 0: fator = 1 + int(background.distance / DIFICULT_AVANCE) grupo_enemy.add([ random.choice(enemylist)(int(fator / 2)) for i in range(random.randint(1, fator)) ]) tick_enemies = 100 tick_enemies -= 1 if tick_enemies < 0: tick_enemies = 0 for enemycol in grupo_enemy: