コード例 #1
0
 def __setstate__(self, dd):
     # Update the object's dict
     self.__dict__.update(dd)
     # Then, re-initialize the method handle and the object's execution thread
     from src.controller import ScriptEngine
     self.callback = ScriptEngine.get(self.methodname)
     self.map = None
     self._conclude()
コード例 #2
0
 def __init__(self, name, rect, callback, m, _1=0, _2=0):
     # Init attributes
     self.name = name
     self.rect = rect
     self.methodname = callback
     self.map = m
     # Get the actual method handle from the string name
     from src.controller import ScriptEngine
     self.callback = ScriptEngine.get(callback)
     # Init the execution thread
     self._conclude()
コード例 #3
0
 def handle(self, event):
     # TickEvent: Update player sprites, handle collision detection,
     # check for player-script collision, process other logic...
     if isinstance(event, TickEvent):
         # Update entities
         self.gh.player.update()
         self.gh.shadow.update(event.object)
         if self.gh.player.moving:
             if (self.gh.currentmap is not None):
                 # Player-Map collision detection
                 coll_result = self.gh.currentmap.isWalkable(self.gh.player, self.gh.player.facing)
                 self.gh.player.move(coll_result, event.object)
                 # Player-Script collision detection
                 script_result = self.gh.currentmap.checkForScriptToggle(self.gh.player)
                 if script_result is not None:
                     ScriptEngine.run(script_result)
     # FullscreenToggleRequestEvent
     elif isinstance(event, FullscreenToggleRequestEvent):
         # Order the Game menu to check if that's possible
         self.gh.fullscreenToggleRequest()
     # QuitEvent: Shutdown the Engine objects (killing running interaction threads)
     elif isinstance(event, QuitEvent):
         # Shutdown the engine objects
         ScriptEngine.shutdown()
         ObjectEngine.shutdown()
     # MouseMotionEvent: Order the map to check if the moved mouse has highlighted a clickable object
     elif isinstance(event, MouseMotionEvent):
         # Check for enabled highlighting
         if get_property(MOUSE_HIGHLIGHT_ENABLED):
             # Check for object highlighting
             obj = self.gh.currentmap.checkForObjectHighlight(event.object)
             self.gh.evManager.post(ObjectHighlightedEvent(obj))
     # MovementRequestEvent: Order the player to start moving and point him in the desired direction
     elif isinstance(event, MovementRequestEvent):
         if get_property(PLAYER_MOVEMENT_ENABLED):
             # Player has started moving
             self.gh.player.startMoving()
             self.gh.player.setDirection(event.object)
     # MovementDoneEvent: Order the player to stop moving
     elif isinstance(event, MovementDoneEvent):
         self.gh.player.stopMoving()
     # ObjectInteractionEvent: Order the Object Engine to interact with the event's object
     elif isinstance(event, ObjectInteractionEvent):
         ObjectEngine.interact(event.object)
     # InventoryToggleEvent: Order the opening of the inventory dialog
     elif isinstance(event, InventoryToggleEvent):
         # Open inventory if no script or object execution is running right now
         if get_property(INVENTORY_OPEN_ENABLED):
             # Stop the player
             self.gh.player.stopMoving()
             # Play a sound for inventory toggling
             GlobalServices.getAudioDevice().play(SOUND, "journal_open", VOLUME_SOUND)
             # Change game state
             self.gh.state = STATE_GAME_INVENTORY
             self.gh.evManager.post(GameStateChangedEvent(self.gh.state))
     elif isinstance(event, GameMenuToggleEvent):
         if get_property(GAME_MENU_OPEN_ENABLED):
             # Open game menu! First, stop the player
             self.gh.player.stopMoving()
             # Change game state
             self.gh.state = STATE_GAME_MENU
             self.gh.evManager.post(GameStateChangedEvent(self.gh.state))
     # SaveEvent: Initialize the save process
     elif isinstance(event, SaveEvent):
         if get_property(SAVE_ENABLED):
             # Save the state (the True parameter orders the TextRenderer to display a message as well)
             self.gh.save(True)
     # MapChangeRequestEvent: When the user has triggered a teleport to another map,
     # the ScriptEngine posts this event to the EventManager
     elif isinstance(event, MapChangeRequestEvent):
         # Stop moving the player
         self.gh.player.stopMoving()
         # Unpack event information
         map_object = event.object[0]
         destination = event.object[1]
         # Init loading with the map and save the dest position
         self.gh.teleport_destination = destination
         self.gh.initMapLoading(map_object)
     # MainMenuSwitchRequestEvent: After the game is finished
     elif isinstance(event, MainMenuSwitchRequestEvent):
         self.gh.switchToMainMenu()
コード例 #4
0
 def fullscreenToggleRequest(self):
     if not (ScriptEngine.isRunning() and ObjectEngine.isRunning()):
         self.evManager.post(FullscreenToggleEvent())