def teleport(self, source, obj, target, destination): self._go() if self._playerInDistance(source.getPlayer().position, obj.rect): # Play the sound of this TeleportClickable object # (if there is one; could be a door squeaking etc) if hasattr(obj, 'sound'): GlobalServices.getAudioDevice().play(SOUND, obj.sound, 0.8) self.teleport_in_progress = True set_property(PLAYER_MOVEMENT_ENABLED, False) # Save the state of the current map's properties to the persistent shelf # before teleporting to the new map update_persistent_map_properties(source, get_savegame()) dur = 1000 fadeout = OverlayFactory.create_animated_color((0,0,0), dur, 0, True, 0, 255) source.addOverlay(fadeout) self._wait(dur) source.rendering_enabled = False GlobalServices.getEventManager().post(MapChangeRequestEvent((target, destination))) source.removeOverlay(fadeout) source.flushOverlayQueue() set_property(PLAYER_MOVEMENT_ENABLED, True) self.teleport_in_progress = False self._halt()
def save(self, disp=False): # Get the savegame data temp = get_savegame() # Open the "real" shelf (the one the player can load up again)! save = shelve.open(CURRENT_SHELF_FILENAME[0]) # Save persistent data that needs to be stored in order to retrieve the game state. # All data that is used to do that is actually the player's current position, # the current map where this position applies, and the currently playing background # music. # Pre-defined keys for the dict save['player_position'] = self.player.position save['current_map'] = self.currentmap.properties['key_name'] save['player_inventory'] = self.player.inventory save['current_sounds'] = GlobalServices.getAudioDevice().getPlayingSounds() temp['global_overlays'] = get_global_overlays() # Update the persistent map properties for the current map update_persistent_map_properties(self.currentmap, temp) # Copy the rest of the shelf data to the "correct" save file copy_to_shelve(temp, save) # Close the shelves again; that's it! save.close() if disp: # Display the optional success message using the TextRenderer module tr = GlobalServices.getTextRenderer() tr.write("Game saved.", 3)
def teleport(self, source, target, destination): self._go() self.teleport_in_progress = True set_property(PLAYER_MOVEMENT_ENABLED, False) # Save the state of the current map's properties to the persistent shelf # before teleporting to the new map update_persistent_map_properties(source, get_savegame()) dur = 1000 fadeout = OverlayFactory.create_animated_color((0,0,0), dur, 0, True, 0, 255) source.addOverlay(fadeout) self._wait(dur) source.rendering_enabled = False GlobalServices.getEventManager().post(MapChangeRequestEvent((target, destination))) set_property(PLAYER_MOVEMENT_ENABLED, True) source.removeOverlay(fadeout) self.teleport_in_progress = False self._halt()