def start_menu(): pygame.init() Start_screen = pygame.display.set_mode(MENU_SIZE) pygame.display.set_caption("Menu") # caption sets title of Window Start_screen.fill(black) # (0,0,0) represents RGB for black results = menu(Start_screen) # start = None, load = 2 #load high score f = open('highscores.txt','r') highscore_archive = f.readlines() highscore_archive_list = convert_score_list(highscore_archive) # load platform option g = open('platform.txt','r') extension = g.readlines() if results is None: # This means user selected start game Start_screen.fill(black) pygame.display.set_caption("Difficulty Level") level = level_menu(Start_screen) return level elif results == 2: # user selected LOAD game with open('saved_state.txt','r') as f: saved_state = f.readlines() # need to pass this into the game to update the state new_game(saved_state,highscore_archive_list,extension = extension) return None # use options to specify operating system elif results == 3: Start_screen.fill(black) pygame.display.set_caption("Platform") platform = pl_menu(Start_screen) if platform != 4: # 4 refers to back with open('platform.txt','w') as f: if platform == 1: f.write(".png") else: f.write(".bmp") return 4 elif results == 4: # user selected high score Start_screen.fill(black) pygame.display.set_caption("HighScore Leaderboard") events = pygame.event.get() event_types = [event.type for event in events] while pygame.MOUSEBUTTONDOWN not in event_types: display_high_score(Start_screen, highscore_archive_list) events = pygame.event.get() event_types = [event.type for event in events] return 4 elif results == 5: # user select to see instructions Start_screen.fill(black) pygame.display.set_caption("Game Instruction") events = pygame.event.get() event_types = [event.type for event in events] while pygame.MOUSEBUTTONDOWN not in event_types: display_instructions(Start_screen) events = pygame.event.get() event_types = [event.type for event in events] return 4
def init_game(): """ Initialize the game with the menu screen. If the player chooses "Play Game", <menu> method returns "None". """ pygame.init() pygame.display.set_caption("Bunny Bounce") if menu(pygame.display.set_mode(WINDOW_SIZE)) is None: new_game()
def __init__(self): """ Set up the components to start a game """ size = (40,40) pygame.init() width = pygame.display.Info().current_w height = pygame.display.Info().current_h screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN, 32) game_choice = menu(screen) pygame.display.set_caption("PySnake") arena = Arena(screen.get_rect().centerx-size[0]*WIDTH/2, screen.get_rect().centery-size[1]*HEIGHT/2, 20, size, game_choice, (0,0)) clock = pygame.time.Clock() self.main_loop(screen, arena, clock) pygame.quit()
def __init__(self): """ Set up the components to start a game """ size = (40, 40) pygame.init() width = pygame.display.Info().current_w height = pygame.display.Info().current_h screen = pygame.display.set_mode((width, height), pygame.FULLSCREEN, 32) game_choice = menu(screen) pygame.display.set_caption("PySnake") arena = Arena(screen.get_rect().centerx - size[0] * WIDTH / 2, screen.get_rect().centery - size[1] * HEIGHT / 2, 20, size, game_choice, (0, 0)) clock = pygame.time.Clock() self.main_loop(screen, arena, clock) pygame.quit()
def new_game(): """ Sets up all necessary components to start a new game. """ pygame.init() # initialize all imported pygame modules window_size = [ NUM_COLS * WIDTH + 200, NUM_ROWS * HEIGHT + 20] # width, height screen = pygame.display.set_mode(window_size) pygame.display.set_caption("Infinite Runner") # caption sets title of Window board = Board() moveCount = 0 clock = pygame.time.Clock() #Menu function result = menu(screen) if result == 0: #THIS MEANS USER SELECTED START GAME main_loop(screen, board, moveCount, clock, False, False) elif result == 1: #USER SELECTED LOAD GAME print "you can't load games -- yet!" elif result == 2: #USER SELETED OPTIONS print "you have no options -- yet!"
Used to run and test Pong ''' import pygame from example_menu import main as menu from board_class import Board pygame.init() window_size = [500, 500] # width, height screen = pygame.display.set_mode(window_size) pygame.display.set_caption('Pong') result = 2 while result == 2: result = menu(screen) if result == 1: #start game print "***START GAME***" num_players = int(raw_input("Number of Players (1 to 4): ")) num_balls = int(raw_input("Number of Balls (1 to 3): ")) ball_speed = int(raw_input("Ball Speed (1 to 10): ")) board = Board(num_players, num_balls, ball_speed) clock = pygame.time.Clock() main_loop(screen, board, num_players, num_balls, ball_speed, clock, False, False) if result == 2: #instructions print "***INSTRUCTIONS***" print print "USER INPUT" print "•Player 1 (right): up/down keys" print "•Player 2 (bottom): C/V keys" print "•Player 3 (left): Q/A keys"