def in_menu(self): '''Вся работа класса с меню. Отрисовывает меню, получает нажатые кнопки, некоторые кнопки обратавыет.''' self.menu.draw(self.window) # Проверка результата нажатий на кнопки меню result = self.menu.run(*self.mouse_pos, pygame.mouse.get_pressed()[0]) if result: if result[0] == 'loadl': # Загружает уровень self.level_go = True with open(script_dir + 'settings.txt') as file: self.key_list = [ int(i) for i in file.read().split('\n') ] # список горячих клавишь self.complexity = self.key_list.pop(7) # Сложность if int(result[1]) == 10: self.load_boss_music() else: self.load_level_music() self.level_now = levels.Level(result[-1], self.complexity) self.window = pygame.display.set_mode( self.level_now.level_size) elif result[0] == 'main_menu': # закрытие уровня, длл кнопки на уровне (если переход не с уровня, ничего не произайдет) self.close_level() self.load_menu_music() elif result[0] == 'music': self.music_on = not self.music_on # Для кнопки выключения музыки в настройках if self.music_on: pygame.mixer.music.unpause() else: pygame.mixer.music.pause()
def maketree(self): base = levels.Level() for i, val in enumerate(self.p): n = node.Node(val) n.symbol = self.s[i] base.levels.append(n) base.sort_level() self.tree.append(base) while (len(self.tree[-1].levels) != 1): babies = self.tree[-1].levels[-self.d:] parent = self.make_parent(babies) level = levels.Level() level.levels.append(parent) for val in self.tree[-1].levels[:-self.d]: level.levels.append(val) level.sort_level() self.tree.append(level)
def update(self): self.handle_events() if self.state == MENU: self.state = self.menu.update(self.mousedown) if self.state == LEVEL_RAND or self.state == LEVEL_1 or self.state == LEVEL_2 \ or self.state == LEVEL_3 or self.state == LEVEL_4 or self.state == LEVEL_5: self.level = levels.Level(self.state) elif self.state == EXIT: pygame.quit() sys.exit() elif self.state == INSTR: pass else: self.level.update(self.mousedown)
def __init__(self): super(Gameplay, self).__init__() self.levels = levels.Level(levels.levelList) self.next_state = "GAMEOVER"
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()
"""Method for testing the level. Opens the main game in testing mode.""" self.saveLevel(True) os.system("main.py -t -d") if __name__ == "__main__": try: width = int(sys.argv[1]) height = int(sys.argv[2]) if width > 15 or height > 15: print("Width and height can be max 15 tiles.") sys.exit() level = levels.Level([], width, height) editor = LevelEditor(level) except (IndexError, TypeError): print("Not a valid input.") print("Usage: levelEditor.py <width> <height>") sys.exit() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: print("Exiting..") sys.exit() editor.mouseManager(event)
def main(): """ Main Program """ pygame.init() FPS = 60 # Used to manage how fast the screen updates clock = pygame.time.Clock() # Set the height and width of the screen screen = pygame.display.set_mode(config.SIZE, pygame.DOUBLEBUF, 32) pygame.display.set_caption("Super Mario Bros!") # Create the player player = Mario() # Set the current level current_level_no = 1 current_level = levels.Level(player) load_level(current_level) active_sprite_list = pygame.sprite.Group() player.level = current_level player.rect.x = 120 #Player always starts in the same point player.rect.y = config.SCREEN_HEIGHT - player.rect.height - 64 active_sprite_list.add(player) #Loop until the user clicks the close button. done = False # -------- Main Program Loop ----------- while not done: #Set Level Physics milliseconds = clock.tick(FPS) seconds = milliseconds / 1000.0 # seconds passed since last frame (float) playtime = current_level.physics_info['play_time'] + seconds current_level.physics_info['current_time'] = milliseconds current_level.physics_info['seconds'] = seconds current_level.physics_info['play_time'] = playtime for event in pygame.event.get(): # User did something if event.type == pygame.QUIT: # If user clicked close done = True # Flag that we are done so we exit this loop if event.type == pygame.KEYDOWN: if event.key == pygame.K_s: player.is_running = True if event.key == pygame.K_a and player.state != config.MARIO_STATE_JUMPING: player.jump() if event.type == pygame.KEYUP: if event.key == pygame.K_s: player.is_running = False if event.key == pygame.K_a: player.fight_gravity = False keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: player.go_left() if keys[pygame.K_RIGHT]: player.go_right() if not keys[pygame.K_LEFT] and not keys[pygame.K_RIGHT]: player.stop() # Update the player. active_sprite_list.update() # Update items in the level current_level.update() # If the player gets near the right side, shift the world left (-x) LIMIT = config.SCREEN_WIDTH - config.SCREEN_PLAYER_OFFSET if player.rect.x >= LIMIT: diff = player.rect.x - LIMIT player.rect.x = LIMIT current_level.shift_world(-diff) # If the player gets to the end of the level, go to the next level current_position = player.rect.x + current_level.world_shift # ALL CODE TO DRAW SHOULD GO BELOW THIS COMMENT current_level.draw(screen) active_sprite_list.draw(screen) #print(current_level.physics_info) """ pygame.display.set_caption("Millis({})/Seconds({})/PlayTime({}) limit FPS to {} (now: {:.2f})".format( milliseconds, seconds, playtime, FPS,clock.get_fps())) """ # Go ahead and update the screen with what we've drawn. pygame.display.flip() # Be IDLE friendly. If you forget this line, the program will 'hang' # on exit. pygame.quit()
def start_game(number_of_players, settings, screen, profiles, user_interface): upper_left = (settings.screen_width / 4, settings.screen_height / 4) upper_right = (3 * (settings.screen_width / 4), settings.screen_height / 4) lower_left = (settings.screen_width / 4, 3 * (settings.screen_height / 4)) lower_right = (3 * (settings.screen_width / 4), 3 * (settings.screen_height / 4)) ship_spawns = [] if number_of_players == 1: ship_spawns.append( (settings.screen_width / 2, settings.screen_height / 2)) elif number_of_players == 2: ship_spawns.append(upper_left) ship_spawns.append(lower_right) elif number_of_players == 3: ship_spawns.append(upper_left) ship_spawns.append(lower_right) ship_spawns.append(upper_right) elif number_of_players == 4: ship_spawns.append(upper_left) ship_spawns.append(lower_right) ship_spawns.append(upper_right) ship_spawns.append(lower_left) hud_size = (156, 70) # TODO these are measured values from the actual game, find a way to adjust these to screen size? hud_positions = [(0, 0), (settings.screen_width - hud_size[0], settings.screen_height - hud_size[1]), (settings.screen_width - hud_size[0], 0), (0, settings.screen_height - hud_size[1])] ships_group = pygame.sprite.Group() level = levels.Level(screen, settings.difficulty, ships_group) ships = [] controls = [] huds = [] for i in list(range(0, number_of_players)): s = ship.Ship(ship_spawns[i], screen, (31, 31), profiles[i].ship_props, i + 1, level) # I start counting players from 1 ships.append(s) ships_group.add(s) s.spawn() # TODO move this somewhere else? controls.append(profiles[i].control_scheme) huds.append(hud.Hud(screen, hud_positions[i], s)) for s in ships: s.enable_friendly_fire(ships_group) gf = game_functions.GameFunctions(ships, controls, huds, screen, level) clock = pygame.time.Clock() # Starting the main game loop while True: # makes the loop wait a certain amount of time to achieve 60 ticks per s clock.tick(60) gf.game_loop() if gf.game_has_ended: user_interface.chosen_number_of_players = -1 break pygame.display.flip( ) # makes the most recently drawn frame/screen visible
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 installer(installType, dialog="folder"): if installType == modes.GameMode: typeDict = modes.gamemodes typeModule = modes elif installType == items.ItemPack: typeDict = items.itempacks typeModule = items elif installType == levels.Level: typeDict = levels.levels typeModule = levels else: return False if dialog.lower() == "folder": installPath = easygui.diropenbox(title="Select expansion pack folder") elif dialog.lower() == "file": installPath = easygui.fileopenbox( title="Select expansion pack .zip file") else: return False if installPath == "" or installPath == None: return False installPathList = installPath.split("\\") if installPath.lower().endswith(".zip"): newExtensionName = installPathList[-1][:-4] isZip = True else: newExtensionName = installPathList[-1] isZip = False if newExtensionName in list(typeDict.keys()): message.showMessage(newExtensionName + " is already installed!") logger.addLog(newExtensionName + " is already installed!", logger.loglevel["info"]) return False else: message.showMessage("Installing " + installType.modeType + newExtensionName) try: if os.path.isdir(installPath): shutil.copytree( installPath, os.getcwd() + typeModule.folder + newExtensionName) # DEBUG: while os.path.getsize(os.getcwd() + typeModule.folder + newExtensionName) < os.path.getsize( os.getcwd() + typeModule.folder + newExtensionName): print("copying") else: if isZip: with zipfile.ZipFile(installPath, "r") as zip_ref: zip_ref.extractall(os.getcwd() + typeModule.folder + newExtensionName) else: message.showMessage( "The chosen extension is not a folder or zip file.") logger.addLog( newExtensionName + " is not a valid folder or .zip file, cannot be installed!", logger.loglevel["warning"]) return False try: if installType == modes.GameMode: module = importlib.import_module("modes." + newExtensionName) modes.gamemodes[newExtensionName] = modes.GameMode( module, newExtensionName) elif installType == items.ItemPack: items.itempacks[newExtensionName] = items.ItemPack( typeModule.folder[2:] + newExtensionName, newExtensionName) elif installType == levels.Level: levels.levels[newExtensionName] = levels.Level( typeModule.folder[2:] + newExtensionName, newExtensionName) corrupt = False except modes.PlatformerControllerNotFound: message.showMessage("Game Mode " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog( "PlatformerController does not exist in game mode " + newExtensionName + ", game mode will not be loaded!", logger.loglevel["warning"]) corrupt = True except ModuleNotFoundError: message.showMessage("Game Mode " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog( "Game mode " + newExtensionName + " is not properly structured, game mode will not be loaded!", logger.loglevel["warning"]) corrupt = True except items.ItemPackCorrupt as e: message.showMessage("Item Pack " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog(e.message, logger.loglevel["warning"]) corrupt = True except items.DependencyNotFound as e: message.showMessage("Item Pack " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog(e.message, logger.loglevel["warning"]) corrupt = True except levels.LevelCorrupt as e: message.showMessage("Level " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog(e.message, logger.loglevel["warning"]) corrupt = True except levels.DependencyNotFound as e: message.showMessage("Level " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog(e.message, logger.loglevel["warning"]) corrupt = True except levels.LevelDataCorrupt as e: message.showMessage("Level " + newExtensionName + " is corrupt, and has not been installed.") logger.addLog(e.message + "\n" + e.origEx, logger.loglevel["warning"]) corrupt = True finally: if corrupt: shutil.rmtree(os.getcwd() + typeModule.folder + newExtensionName) return False message.showMessage( "Installed " + installType.modeType + " " + newExtensionName + ". Please restart the game to use the new content.") logger.addLog( installType.modeType + " " + newExtensionName + " installed!", logger.loglevel["debug"]) return True except Exception as e: message.showMessage("An error occured installing " + installType.modeType + " " + newExtensionName) logger.addLog( "An error occured installing " + installType.modeType + " " + newExtensionName, logger.loglevel["warning"]) logger.addLog( "Error installing " + installType.modeType + " " + newExtensionName + "\nException:\n" + str(e), logger.loglevel["debug"]) return False
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()