def show_controls(): #Sets the title text for this UI page help_text = "Help" help_text_render = c.menu_font.render(help_text, 1, c.red, 150) #Sets the help text controls_text = "Controls:\nMenus:\nEsc --- Return\n1/2/3/4 --- Menu Buttons\nEnter --- Submit Name\n\nIn-Game:\nClassic:\nEsc --- Pause\nR --- Restart\nW/Up --- Charge Jump\nA/Left --- Move Left\nS/Down --- Move Down Faster\nD/Right --- Move Right\n\nPractice:\nPage Up --- Increase Score\nPage Down --- Decrease Score\n\nVersus:\nWASD --- BLUE player\nArrow Keys --- RED player" gamemodes_text = "Gamemodes:\n\nClassic: As per the title, the original experience of Skybound, charge your jumps and aim for that top spot on the leaderboard.\n\nPractice: The testing grounds for Skybound, feel free to set your score to whatever you want to see how well you can do with a fast camera.\n\nVersus: The local multiplayer gamemode to go head to head against your friends, see who can survive the longest." global on_controls while on_controls: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: c.screen.fill(c.black) on_controls = False if event.type == pygame.display.quit: main_menu.quit_game() c.screen.fill(c.black) help_text_rect = help_text_render.get_rect() help_text_rect.center = (c.screen_width/2, 50) c.screen.blit(help_text_render, help_text_rect) c.blit_multiline_text(c.screen, controls_text, (30, 50), c.all_help_font) c.blit_multiline_text(c.screen, gamemodes_text, (400, c.screen_height/6), c.all_help_font) main_menu.button("Return", 0, c.screen_height-75, 200, 80, c.blue, c.darker_blue, "return") pygame.display.update() c.screen.fill(c.black)
def paused_vs(): paused_text = "Paused" paused_text_render = c.menu_font.render(paused_text, 1, c.white, 150) pygame.display.set_caption("Skybound") global is_paused while is_paused: for event in pygame.event.get(): if event.type == pygame.display.quit: main_menu.quit_game() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: is_paused = False if event.key == pygame.K_1: is_paused = False elif event.key == pygame.K_2: is_paused = False c.screen.fill(c.black) time.sleep(0.05) main_menu.menu() paused_text_rect = paused_text_render.get_rect() paused_text_rect.center = ((c.screen_width/2, (c.screen_height/3)/2)) c.screen.blit(paused_text_render, paused_text_rect) main_menu.button("Resume", c.screen_width/2-155, c.screen_height/2.6, 310, 100, c.blue, c.darker_blue, "resume") main_menu.button("Exit to Main Menu", c.screen_width/2-155, c.screen_height/1.625, 310, 100, c.blue, c.darker_blue, "return_from_game") pygame.display.update() c.screen.fill(c.black)
def leaderboard(): global show_leaderboard leaderboard = open("..\\res\\leaderboard.txt", "r+") while show_leaderboard: pygame.display.set_caption("Skybound") c.screen.fill(c.black) for event in pygame.event.get(): if event.type == pygame.QUIT: main_menu.quit_game() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: c.screen.fill(c.black) show_leaderboard = False leaderboard_text = "Leaderboard" leaderboard_text_render = c.menu_font.render(leaderboard_text, 1, c.red, 150) leaderboard_text_rect = leaderboard_text_render.get_rect() leaderboard_text_rect.center = (c.screen_width/2, 50) c.screen.blit(leaderboard_text_render, leaderboard_text_rect) lines = [line.rstrip('\n') for line in open('..\\res\\leaderboard.txt')] lines.sort(key=lambda x: int(x.split("-----")[-1]), reverse=True) score_y = 0 scores = 0 for name_and_score in lines: if scores < 10: name = name_and_score.split(" ----- ") name = name[0] score = name_and_score.split("----- ") score = score[1] name_text_render = c.leaderboard_font.render(name, 1, c.white, 150) name_text_rect = name_text_render.get_rect() name_text_width = name_text_render.get_width() name_text_height = name_text_render.get_height() name_text_rect.x = c.screen_width/2-150-name_text_width name_text_rect.y = 97.5 + score_y c.screen.blit(name_text_render, name_text_rect) score_text_render = c.score_font.render(score, 1, c.white, 150) score_text_rect = score_text_render.get_rect() score_text_rect.center = (c.screen_width/2+200, (120 + score_y)) c.screen.blit(score_text_render, score_text_rect) pygame.draw.line(c.screen, c.white, [c.screen_width/2-125, 122 + score_y], [c.screen_width/2+125, 122 + score_y], 5) score_y += 50 scores += 1 main_menu.button("Return", 0, c.screen_height-75, 200, 80, c.blue, c.darker_blue, "return") pygame.display.update()
def gamemode(): gamemode_text = "Gamemode" gamemode_text_render = c.menu_font.render(gamemode_text, 1, c.red, 150) global show_gamemode show_gamemode = True pygame.display.set_caption("Skybound") while show_gamemode: for event in pygame.event.get(): if event.type == pygame.QUIT: main_menu.quit_game() if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: main_menu.show_menu = True main_menu.menu() if event.key == pygame.K_1: main_menu.start_solo() elif event.key == pygame.K_2: main_menu.start_practice() elif event.key == pygame.K_3: main_menu.start_vs() c.screen.fill(c.black) c.clock.tick(c.fps) gamemode_text_rect = gamemode_text_render.get_rect() gamemode_text_rect.center = (c.screen_width / 2, 50) c.screen.blit(gamemode_text_render, gamemode_text_rect) main_menu.button("Classic", (c.screen_width / 2) - 125, c.screen_height / 4.33, main_menu.box_w, main_menu.box_h, c.blue, c.darker_blue, "solo") main_menu.button("Practice", (c.screen_width / 2) - 125, c.screen_height / 2.36, main_menu.box_w, main_menu.box_h, c.blue, c.darker_blue, "practice") main_menu.button("Versus", (c.screen_width / 2) - 125, c.screen_height / 1.625, main_menu.box_w, main_menu.box_h, c.blue, c.darker_blue, "vs") main_menu.button("Return", 0, c.screen_height - 75, 200, 80, c.blue, c.darker_blue, "return") pygame.display.update() c.screen.fill(c.black)
def solo(): all_platforms = [l.platforms_1, l.platforms_2] c.playing_solo = True #Main program loop to display framerate and handle exiting while c.playing_solo: #Sets frames per second for the game milliseconds = c.clock.tick(c.fps) #Screen reset to avoid multiple blits overlaying c.screen.fill(c.black) #When first ran, the player object is set using the Player class if c.second_timer == 0: main_menu.player_obj = player.Player() #If the player is below the bottom of the screen, they lose and the game over function is ran if main_menu.player_obj.rect.top - c.cameraY > c.screen_height: gamemode.show_gamemode = False game_over.over = True c.playing_solo = False game_over.game_over(False) #Applies gravity to the player by adding a set value to their y velocity each frame main_menu.player_obj.movey += c.gravity #Draws and updates the player main_menu.player_obj.draw(c.red) main_menu.player_obj.update() #Draws the floor for the player to start on (Player can only land and jump on platforms) l.floor.draw() #Generates sets of platforms from the all_platforms list with increasing offset to allow the player to jump up/higher if c.level_timer % c.max_level_timer == 0 and c.generate_platforms == True: c.levels.append( l.Level(random.choice(all_platforms), 650 * c.level_timer / c.max_level_timer, "y")) #Only allows generation of platforms within a set window of the player so that the game does not generate infinite platforms and slow down if len(c.levels) > 0: if (main_menu.player_obj.y) + 1000 < c.levels[0].offset: c.levels.pop(0) elif (main_menu.player_obj.y) - 1000 > c.levels[-1].offset: c.generate_platforms = False else: c.generate_platforms = True c.level_timer += 1 #Draws the generated platforms from the levels list onto the screen for level in c.levels: level.draw() #Continually moves the camera upwards after the player moves off the ground c.cameraY -= c.camera_movement c.camera_movement = c.score / 500 if main_menu.player_obj.y - 150 < c.cameraY: c.cameraY = main_menu.player_obj.y - 150 """Calculate and display the score for the player, the score is calculated by using the player's y co-ordinate and turning it into relative magnitude number""" if c.score < ((-main_menu.player_obj.y) + 570) / 10: c.score = ((-main_menu.player_obj.y) + 570) / 10 score_text = "Score:{0:.0f}".format(c.score) scoretext = c.score_font.render(score_text, 1, c.white, 150) c.screen.blit(scoretext, (5, 0)) #Increases how fast the player charges their jump to make the game possible once the camera movement becomes faster main_menu.player_obj.jump_charge_increase = c.score / 1000 #Primary loop for input handling. for event in pygame.event.get(): if event.type == pygame.display.quit: main_menu.quit_game() #Handles the pressing of a key if event.type == pygame.KEYDOWN: if event.key == c.space or event.key == c.up or event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.player_speed = 3 main_menu.player_obj.charging = True main_menu.player_obj.draw(c.red) main_menu.player_obj.update() if event.key == pygame.K_ESCAPE: pause.is_paused = True pause.paused("solo") if event.key == c.left or event.key == pygame.K_LEFT: main_menu.player_obj.control_x(-1) if event.key == c.right or event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(1) if event.key == c.down or event.key == pygame.K_DOWN: main_menu.player_obj.control_y(10) if event.key == ord("r"): main_menu.start_solo() #Handles the releasing of a key if event.type == pygame.KEYUP: if event.key == c.space or event.key == c.up or event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.update() main_menu.player_obj.control_y( -15 * main_menu.player_obj.jump_charge - main_menu.player_obj.jump_charge_increase * 8) main_menu.player_obj.player_speed = 10 main_menu.player_obj.jump_charge = 0 main_menu.player_obj.charging = False main_menu.player_obj.on_platform = False if event.key == c.left or event.key == pygame.K_LEFT: main_menu.player_obj.control_x(0) if event.key == c.right or event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(0) if event.key == c.down or event.key == pygame.K_DOWN: main_menu.player_obj.control_y(0) #Sets screen boundaries and whether the player is on the floor or on a wall if main_menu.player_obj.x >= c.screen_width - main_menu.player_obj.player_width: main_menu.player_obj.x = c.screen_width - main_menu.player_obj.player_width if main_menu.player_obj.x <= 0: main_menu.player_obj.x = 0 #Print framerate in the window caption pygame.display.set_caption("Skybound FPS: {0:.0f}".format( c.clock.get_fps())) #Updates the display and increments the timers accordingly pygame.display.update() c.second_timer += 1 pygame.display.quit()
def practice(): practice_timer = 1 all_platforms = [l.platforms_1, l.platforms_2] c.playing_practice = True adding_score = False removing_score = False #Main program loop to display framerate and handle exiting while c.playing_practice: if c.second_timer == 0: main_menu.player_obj = player.Player() #Screen reset to avoid multiple blits overlaying c.screen.fill(c.black) #Applies gravity to the player main_menu.player_obj.movey += c.gravity #Draws and updates the player main_menu.player_obj.draw(c.red) main_menu.player_obj.update() l.floor.draw() #Generates sets of platforms from the all_platforms list with increasing c.offset to allow the player to jump up/higher if c.level_timer % practice_timer == 0 and c.generate_platforms == True: c.levels.append(l.Level(random.choice(all_platforms), 650 * c.level_timer/practice_timer, "y")) #Only allows generation of platforms within a set window of the player so that the game does not generate infinite platforms and slow down if len(c.levels) > 0: #if (main_menu.player_obj.y)+15000 < c.levels[0].offset: #c.levels.pop(0) if (main_menu.player_obj.y)-20000 > c.levels[-1].offset: c.generate_platforms = False else: c.generate_platforms = True c.level_timer += 1 #Draws the generated platforms from the levels list onto the screen for level in c.levels: level.draw() #Continually moves the camera upwards after the player moves off the ground c.cameraY -= c.camera_movement c.camera_movement = c.score/500 if main_menu.player_obj.y-150 < c.cameraY: c.cameraY = main_menu.player_obj.y-150 if main_menu.player_obj.y-400 > c.cameraY: c.cameraY = main_menu.player_obj.y-400 """Calculate and display the score for the player, the score is calculated by using the player's y co-ordinate and turning it into relative magnitude number""" if c.score < ((-main_menu.player_obj.y)+570)/10: c.score = ((-main_menu.player_obj.y)+570)/10 score_text = "Score:{0:.0f}".format(c.score) scoretext = c.score_font.render(score_text, 1, c.white, 150) c.screen.blit(scoretext, (5, 0)) main_menu.player_obj.jump_charge_increase = c.score/1000 #Sets frames per second for the game milliseconds = c.clock.tick(c.fps) #Primary loop for input handling for event in pygame.event.get(): if event.type == pygame.display.quit: main_menu.quit_game() #Handles the pressing of a key if event.type == pygame.KEYDOWN: if event.key == c.space or event.key == c.up or event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.player_speed = 3 main_menu.player_obj.charging = True main_menu.player_obj.draw(c.red) main_menu.player_obj.update() if event.key == pygame.K_ESCAPE: pause.is_paused = True pause.paused("practice") if event.key == c.left or event.key == pygame.K_LEFT: main_menu.player_obj.control_x(-1) if event.key == c.right or event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(1) if event.key == c.down or event.key == pygame.K_DOWN: main_menu.player_obj.control_y(10) if event.key == ord("r"): main_menu.start_practice() if event.key == pygame.K_PAGEUP: adding_score = True c.score += 1 if event.key == pygame.K_PAGEDOWN: removing_score = True #Handles the releasing of a key if event.type == pygame.KEYUP: if event.key == c.space or event.key == c.up or event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.update() main_menu.player_obj.control_y(-15*main_menu.player_obj.jump_charge - main_menu.player_obj.jump_charge_increase*8) main_menu.player_obj.player_speed = 10 main_menu.player_obj.jump_charge = 0 main_menu.player_obj.charging = False main_menu.player_obj.on_platform = False if event.key == c.left or event.key == pygame.K_LEFT: main_menu.player_obj.control_x(0) if event.key == c.right or event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(0) if event.key == c.down or event.key == pygame.K_DOWN: main_menu.player_obj.control_y(0) if event.key == pygame.K_PAGEUP: adding_score = False if event.key == pygame.K_PAGEDOWN: removing_score = False if adding_score == True: c.score += 5 if removing_score == True: if c.score >= 5: c.score -= 5 #Sets screen boundaries and whether the player is on the floor or on a wall if main_menu.player_obj.x >= c.screen_width-main_menu.player_obj.player_width: main_menu.player_obj.x = c.screen_width - main_menu.player_obj.player_width if main_menu.player_obj.x <= 0: main_menu.player_obj.x = 0 #Print framerate in window caption pygame.display.set_caption("Skybound FPS: {0:.0f}".format(c.clock.get_fps())) #Updates the display and increments the timers accordingly pygame.display.update() c.second_timer += 1 pygame.display.quit()
def game_over(submitted): pygame.display.set_caption("Skybound") global over removing_timer = 1 removing_timer_max = 60 removing = False while over: c.clock.tick(60) c.screen.fill(c.black) for event in pygame.event.get(): if event.type == pygame.QUIT: main_menu.quit_game() if event.type == pygame.KEYDOWN: #If the user presses enter and hasn't submitted their name to the leaderboard yet, that happens if event.key == pygame.K_RETURN and submitted == False: main_menu.submit_to_leaderboard(c.score) game_over(True) #Backspace to remove characters from the name if event.key == pygame.K_BACKSPACE: removing_timer = removing_timer_max removing = True if len(c.name) < 15 and submitted == False: c.name += event.unicode if event.key == pygame.K_ESCAPE: over = False c.screen.fill(c.black) time.sleep(0.1) main_menu.menu() if event.key == pygame.K_2: if submitted: over = False c.screen.fill(c.black) time.sleep(0.1) main_menu.menu() if event.key == pygame.K_1 or event.key == pygame.K_r: if submitted: main_menu.start_solo() if event.type == pygame.KEYUP: if event.key == pygame.K_BACKSPACE: removing = False if removing and removing_timer % removing_timer_max == 0: c.name = c.name[:-1] over_text = "Game Over" over_text_render = c.menu_font.render(over_text, 1, c.red, 150) over_text_rect = over_text_render.get_rect() over_text_rect.center = ((c.screen_width / 2, 50)) c.screen.blit(over_text_render, over_text_rect) score_text = "Final Score:{0:.0f}".format(c.score) scoretext_render = c.final_score_font.render(score_text, 1, c.white, 150) scoretext_rect = scoretext_render.get_rect() scoretext_rect.center = c.screen_width / 2, c.screen_height / 2 - 200 c.screen.blit(scoretext_render, scoretext_rect) name_text = ("Name: " + c.name) name_text_render = c.controls_font.render(name_text, 1, c.white, 150) name_text_rect = name_text_render.get_rect() name_text_rect.center = ((c.screen_width / 2, c.screen_height / 2 - 100)) c.screen.blit(name_text_render, name_text_rect) if submitted: submitted_text_render = c.boxfont.render( "Name and Score Submitted to Leaderboard", 1, c.white, 150) submitted_text_rect = submitted_text_render.get_rect() submitted_text_rect.center = (c.screen_width / 2, (c.screen_height / 2) - 25) c.screen.blit(submitted_text_render, submitted_text_rect) else: main_menu.button("Submit", c.screen_width / 2 - 90, c.screen_height / 2 - 50, 180, 100, c.blue, c.darker_blue, "submit_name") main_menu.button("Play Again", c.screen_width / 2 - 150, c.screen_height / 2 + 80, 300, 100, c.blue, c.darker_blue, "restart") main_menu.button("Exit to Main Menu", c.screen_width / 2 - 150, c.screen_height / 2 + 200, 300, 100, c.blue, c.darker_blue, "return_from_over") pygame.display.update() removing_timer += 1
def vs_over(colour_of_winner, submitted): pygame.display.set_caption("Skybound") over = True removing_timer = 1 removing_timer_max = 60 removing = False while over: c.clock.tick(60) c.screen.fill(c.black) for event in pygame.event.get(): if event.type == pygame.QUIT: main_menu.quit_game() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN and submitted == False: main_menu.submit_to_leaderboard(c.winner_score) vs_over(c.colour_of_winner, True) if event.key == pygame.K_BACKSPACE: removing_timer = removing_timer_max removing = True if len(c.name) < 15 and submitted == False: c.name += event.unicode if event.key == pygame.K_ESCAPE or event.key == pygame.K_2: game_over.over = False c.screen.fill(c.black) time.sleep(0.1) main_menu.menu() if event.key == pygame.K_1 or event.key == pygame.K_r: if submitted: main_menu.start_vs() if event.type == pygame.KEYUP: if event.key == pygame.K_BACKSPACE: removing = False if removing and removing_timer % removing_timer_max == 0: c.name = c.name[:-1] c.colour_of_winner = colour_of_winner if colour_of_winner == "Red": winner_text_colour = c.red loser_text_colour = c.blue c.winner_score = c.score loser_score = c.score2 colour_of_loser = "Blue" elif colour_of_winner == "Blue": winner_text_colour = c.blue loser_text_colour = c.red c.winner_score = c.score2 loser_score = c.score colour_of_loser = "Red" else: winner_text_colour = c.red c.winner_score = 10 loser_score = 5 colour_of_loser = "Green" score_text = "{}'s Score:{}".format(colour_of_winner, round(c.winner_score)) scoretext_render = c.score_font.render(score_text, 1, winner_text_colour, 150) scoretext_rect = scoretext_render.get_rect() scoretext_rect.center = 625, c.screen_height / 2 - 220 c.screen.blit(scoretext_render, scoretext_rect) score_text2 = "{}'s Score:{}".format(colour_of_loser, round(loser_score)) scoretext_render2 = c.score_font.render(score_text2, 1, loser_text_colour, 150) scoretext_rect2 = scoretext_render2.get_rect() scoretext_rect2.center = 625, c.screen_height / 2 - 170 c.screen.blit(scoretext_render2, scoretext_rect2) over_text = "{} Player Wins".format(colour_of_winner) over_text_render = c.menu_font.render(over_text, 1, winner_text_colour, 150) over_text_rect = over_text_render.get_rect() over_text_rect.center = ((c.screen_width / 2, (c.screen_height / 3) - 180)) c.screen.blit(over_text_render, over_text_rect) name_text = ("Name: " + c.name) name_text_render = c.controls_font.render(name_text, 1, c.white, 150) name_text_rect = name_text_render.get_rect() name_text_rect.center = ((c.screen_width / 2, c.screen_height / 2 - 100)) c.screen.blit(name_text_render, name_text_rect) if submitted: submitted_text_render = c.boxfont.render( "Name and Score Submitted to Leaderboard", 1, c.white, 150) submitted_text_rect = submitted_text_render.get_rect() submitted_text_rect.center = (c.screen_width / 2, (c.screen_height / 2)) c.screen.blit(submitted_text_render, submitted_text_rect) else: main_menu.button("Submit", c.screen_width / 2 - 90, c.screen_height / 2 - 50, 180, 100, c.blue, c.darker_blue, "submit_name_vs") main_menu.button("Play Again", c.screen_width / 2 - 150, 400, 300, 100, c.blue, c.darker_blue, "restart_vs") main_menu.button("Exit to Main Menu", c.screen_width / 2 - 150, 525, 300, 100, c.blue, c.darker_blue, "return_from_over") pygame.display.update() removing_timer += 1
def vs(): c.playing_vs = True all_platforms = [l.platforms_1, l.platforms_2] c.score2 = 0 #Main program loop to display framerate and handle exiting while c.playing_vs: if c.second_timer == 0: main_menu.player_obj = player.Player() main_menu.player_obj2 = player.Player() main_menu.player_obj.x = c.screen_width-main_menu.player_obj.player_width #Screen reset to avoid multiple blits overlaying c.screen.fill(c.black) if main_menu.player_obj.rect.top - c.cameraY > c.screen_height: game_over.vs_over("Blue", False) elif main_menu.player_obj2.rect.top - c.cameraY > c.screen_height: game_over.vs_over("Red", False) if c.score < ((-main_menu.player_obj.y)+570)/10: c.score = ((-main_menu.player_obj.y)+570)/10 if c.score2 < ((-main_menu.player_obj2.y)+570)/10: c.score2 = ((-main_menu.player_obj2.y)+570)/10 score_text = "Score:{0:.0f}".format(c.score) scoretext = c.score_font.render(score_text, 1, c.red, 150) c.screen.blit(scoretext, (5, 0)) score_text2 = "Score:{0:.0f}".format(c.score2) scoretext = c.score_font.render(score_text2, 1, c.blue, 150) c.screen.blit(scoretext, (5, 40)) #Applies gravity to the players main_menu.player_obj.movey += c.gravity main_menu.player_obj2.movey += c.gravity #Draws and updates the players main_menu.player_obj.draw(c.red) main_menu.player_obj.update() main_menu.player_obj2.draw(c.blue) main_menu.player_obj2.update() l.floor.draw() #Generates sets of platforms from the all_platforms list with increasing c.offset to allow the players to jump up/higher if c.level_timer % c.max_level_timer == 0 and c.generate_platforms == True: c.levels.append(l.Level(random.choice(all_platforms), 650 * c.level_timer/c.max_level_timer, "y")) #Only allows generation of platforms within a set window of the players so that the game does not generate infinite platforms and slow down if len(c.levels) > 0: if (main_menu.player_obj2.y)+1000 < c.levels[0].offset: c.levels.pop(0) elif (main_menu.player_obj.y)+1000 < c.levels[0].offset: c.levels.pop(0) elif (main_menu.player_obj2.y)-1000 > c.levels[-1].offset: c.generate_platforms = False elif (main_menu.player_obj.y)-1000 > c.levels[-1].offset: c.generate_platforms = False else: c.generate_platforms = True c.level_timer += 1 #Draws the generated platforms from the levels list onto the screen for level in c.levels: level.draw() #Continually moves the camera upwards once a set amount of time has passed c.cameraY -= c.camera_movement c.camera_movement = max(c.score/500, c.score2/500) if main_menu.player_obj.y-80 < c.cameraY: c.cameraY = main_menu.player_obj.y-80 if main_menu.player_obj2.y-80 < c.cameraY: c.cameraY = main_menu.player_obj2.y-80 main_menu.player_obj.jump_charge_increase = min(1, c.score/1000) main_menu.player_obj2.jump_charge_increase = min(1, c.score/1000) #Sets frames per second for the game milliseconds = c.clock.tick(c.fps) #Primary loop for input handling for event in pygame.event.get(): if event.type == pygame.display.quit: main_menu.quit_game() #Handles the pressing of a key if event.type == pygame.KEYDOWN: #PLAYER 2 CONTROLS if event.key == c.up: if main_menu.player_obj2.on_platform == True: main_menu.player_obj2.player_speed = 3 main_menu.player_obj2.charging = True main_menu.player_obj2.draw(c.blue) main_menu.player_obj2.update() if event.key == pygame.K_ESCAPE: pause.is_paused = True pause.paused_vs() if event.key == c.left: main_menu.player_obj2.control_x(-1) if event.key == c.right: main_menu.player_obj2.control_x(1) if event.key == c.down: main_menu.player_obj2.control_y(10) #PLAYER 1 CONTROLS if event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.player_speed = 3 main_menu.player_obj.charging = True main_menu.player_obj.draw(c.red) main_menu.player_obj.update() if event.key == pygame.K_LEFT: main_menu.player_obj.control_x(-1) if event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(1) if event.key == pygame.K_DOWN: main_menu.player_obj.control_y(10) #Handles the releasing of a key if event.type == pygame.KEYUP: if event.key == c.up: if main_menu.player_obj2.on_platform == True: main_menu.player_obj2.update() main_menu.player_obj2.control_y(-15*main_menu.player_obj2.jump_charge - main_menu.player_obj2.jump_charge_increase*8) main_menu.player_obj2.player_speed = 10 main_menu.player_obj2.jump_charge = 0 main_menu.player_obj2.charging = False main_menu.player_obj2.on_platform = False if event.key == c.left: main_menu.player_obj2.control_x(0) if event.key == c.right: main_menu.player_obj2.control_x(0) if event.key == c.down: main_menu.player_obj2.control_y(0) if event.key == c.up2: if main_menu.player_obj.on_platform == True: main_menu.player_obj.update() main_menu.player_obj.control_y(-15*main_menu.player_obj.jump_charge - main_menu.player_obj.jump_charge_increase*8) main_menu.player_obj.player_speed = 10 main_menu.player_obj.jump_charge = 0 main_menu.player_obj.charging = False main_menu.player_obj.on_platform = False if event.key == pygame.K_LEFT: main_menu.player_obj.control_x(0) if event.key == pygame.K_RIGHT: main_menu.player_obj.control_x(0) if event.key == pygame.K_DOWN: main_menu.player_obj.control_y(0) #Sets screen boundaries and whether either player is on the floor or on a wall if main_menu.player_obj.x >= c.screen_width-main_menu.player_obj.player_width: main_menu.player_obj.x = c.screen_width - main_menu.player_obj.player_width if main_menu.player_obj.x <= 0: main_menu.player_obj.x = 0 if main_menu.player_obj2.x >= c.screen_width-main_menu.player_obj2.player_width: main_menu.player_obj2.x = c.screen_width - main_menu.player_obj2.player_width if main_menu.player_obj2.x <= 0: main_menu.player_obj2.x = 0 #Print framerate in window caption pygame.display.set_caption("Skybound FPS: {0:.0f}".format(c.clock.get_fps())) #Updates the display and increments the timers accordingly pygame.display.update() c.second_timer += 1 pygame.display.quit()