def update(self, events, world): settings = world.find_component("settings") for event in events: if event.type == EQUIP_QUIT: return SceneManager.new_root(scenes.title.TitleScene()) if event.type == EQUIP_BUY_CLOUD_SLEEVES: self._shop(settings["cloudSleevesCost"], "cloud_sleeves", world) self.teardown(world) self.setup(world) if event.type == EQUIP_BUY_WINGS: self._shop(settings["wingsCost"], "wings", world) self.teardown(world) self.setup(world) if event.type == EQUIP_BUY_JET_BOOTS: self._shop(settings["jetBootsCost"], "jet_boots", world) self.teardown(world) self.setup(world) if event.type == EQUIP_SAVE_AND_START: self._save(settings["save_file"], world) self.teardown(world) return SceneManager.push(GameScene()) world.process_all_systems(events)
def update(self, events, world): for event in events: if event.type == NEW_GAME: return SceneManager.new_root(GameScene()) if event.type == CONTINUE: # we have no data to save right now, so just start a fresh game if we have a save file settings = world.find_component("settings") if path.exists( path.join(user_data_dir(APP_NAME, APP_AUTHOR), settings["save_file"])): with open( path.join(user_data_dir(APP_NAME, APP_AUTHOR), settings["save_file"]), "r", ) as f: loaded_json = json.load(f) player_entity = world.find_entity("player") player_entity.player.currency = loaded_json["currency"] player_entity.player.hasCloudSleeves = loaded_json[ "hasCloudSleeves"] player_entity.player.hasWings = loaded_json["hasWings"] player_entity.player.hasJetBoots = loaded_json[ "hasJetBoots"] self.teardown(world) return SceneManager.push(EquipScene()) if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: return SceneManager.pop() world.process_all_systems(events)
def update(self, dt): if (self.loading == False): self.loading = True return self.scene_handler.register(1, MainMenuScene()) self.scene_handler.register(2, GameScene()) self.config.game_state = 1
def __init__(self): self.screen = pygame.display.set_mode(self.size) self.scenes = [ MenuScene(self), GameScene(self), GameOverScene(self) ] self.game_over = False
def main(): # initializing pygame pygame.init() pygame.mixer.init() pygame.font.init() # setting up the game window resolution = config.get_resolution() win = pygame.display.set_mode(resolution) pygame.display.set_caption("Tudo que entra, também sai") pygame.display.set_icon(load_image(images.TOILET_ICON)) clock = pygame.time.Clock() # scenes dictionary, to ease the access router = { START_SCENE: StartScene(win), GAME_SCENE: None, GAME_OVER_SCENE: GameOverScene(win), HOW_TO_PLAY_SCENE: HowToPlayScene(win), CREDITS_SCENE: CreditsScene(win) } # current scene being rendered current_scene = router[config.get(config.STARTING_SCENE) or START_SCENE] prev_command = None command = None while 1: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: sys.exit() elif config.is_debug() and event.type == pygame.MOUSEBUTTONDOWN: print(pygame.mouse.get_pos()) prev_command = command # renders a scene and receives a command from it if prev_command is not None: command = current_scene.render( events=events, more_args=prev_command.get('more_args')) else: command = current_scene.render(events=events) # when the previous command is not the game scene, it means we're starting a new game scene starting_at_game_scene = prev_command is None and command[ 'goto'] == GAME_SCENE moving_to_game_scene = prev_command is not None and prev_command[ 'goto'] != GAME_SCENE and command['goto'] == GAME_SCENE if starting_at_game_scene or moving_to_game_scene: router[GAME_SCENE] = GameScene(win) # the command contains a goto action indicating the next scene to be rendered current_scene = router[command['goto']] pygame.display.update() clock.tick(40)
def process_input(self, events, pressed_keys): """ Pressing any key starts the game by advancing to the GameScene. :param events: :param pressed_keys: :return: """ for event in events: if event.type == pygame.KEYDOWN or event.type == pygame.JOYBUTTONDOWN: self.switch_to_scene(GameScene(self.resources))
def update(self, events, world): for event in events: if event.type == SCENE_REFOCUS: self._transition_back_to(events, world) if event.type == NEW_GAME: self.teardown(world) return SceneManager.new_root(GameScene()) if event.type == CONTINUE: self.teardown(world) post(Event(LOAD)) return SceneManager.new_root(GameScene()) if event.type == CONTROLS: self._transition_away_from(events, world) return SceneManager.push(ControlsScene()) if event.type == CREDITS: self._transition_away_from(events, world) return SceneManager.push(CreditsScene()) if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: return SceneManager.pop() world.process_all_systems(events)
def on_button_released(self, ev, signal): for i, pin in enumerate(self.pins, 1): d = (pin.position - ev.position).length if d < 0.5: signal(StartScene(GameScene(i)))
def __init__(self): open("high_scores.txt", "w").write("") self.screen = pygame.display.set_mode(self.size) self.scenes = [MenuScene(self), GameScene(self), GameOverScene(self)] self.game_over = False