Beispiel #1
0
    def update(self, dt):
        # Add time to schedulers.
        SchedulerManager.update(self, dt)

        # Get buffered input from clients and process it.
        while not self.server.input.empty():
            (client, packet) = self.server.input.get_nowait()
            self.process_packet(client, packet)

        # Update the game state world.
        self.world.update(dt)

        # Send necessary ObjectUpdate packets.
        for object in self.world.objects:
            if object.type == "player":
                self._send_update(object)

        # Send necessary ObjectStatusUpdate packets.
        for object in self.status_updates:
            update = packets.ObjectStatusUpdate()
            update.object_id = object.object_id
            update.health, update.power = object.health, object.power
            self.server.output_broadcast.put_nowait((update, None))
        self.status_updates.clear()

        # Send buffered output to clients.
        reactor.callFromThread(self.server.send)

        # Sleep some if we're updating too fast.
        extra = 0.01 - dt
        if extra >= 0.001:
            time.sleep(extra)
Beispiel #2
0
    def __init__(self, sceneManager, address, port, player_name):
        # Initialize the various listener classes we are a subclass from
        ogre.FrameListener.__init__(self)
        ogre.WindowEventListener.__init__(self)
        SchedulerManager.__init__(self)
        
        self.address = address
        self.port = port
        self.player_name = player_name
        self.is_round_active = False
        
        self.renderWindow = ogre.Root.getSingleton().getAutoCreatedWindow()
        self.sceneManager = sceneManager
        self.camera = self.sceneManager.getCamera("PrimaryCamera")
        self.cameraNode = self.sceneManager.getSceneNode("PrimaryCamera")
        
        self.viewport = self.camera.getViewport()
        
        self.player = None
        self.last_update = None
        self.scores = { }
        self.scores_changed = Event()
        self.game_nodes = { }
        self.players = { }
        
        # Come up with a non-static way of doing this.
        self.nodes = []
        nodes.Node.node_created += self.on_node_created
        nodes.Node.node_destroyed += self.on_node_destroyed
        
        # Set up the scene.
        self.setupScene()
        
        # Load sounds.
        self.loadSceneSounds()
        
        # Set up the GUI.
        self.gui = PlaySceneGUI(self)
        self.gui.element_selected += self.on_gui_element_selected
        
        # Show a welcome message.
        self.gui.message.notice("Tides of the Elements")
        
        # Load scene music
        audio.set_background_music("media/sounds/Dispatches+Of+Humanity.wav")
        
        # Set up the input devices.
        self.setupInput()

        # Set up initial window size.
        self.windowResized(self.renderWindow)

        # Set this to True when we get an event to exit the application
        self.quit = False

        # Listen for any events directed to the window manager's close button
        ogre.WindowEventUtilities.addWindowEventListener(self.renderWindow, self)
        
        # Begin scene music
        audio.play_background_music()
Beispiel #3
0
    def update(self, dt):
        # Add time to schedulers.
        SchedulerManager.update(self, dt)

        # Get buffered input from clients and process it.
        while not self.server.input.empty():
            (client, packet) = self.server.input.get_nowait()
            self.process_packet(client, packet)

        # Update the game state world.
        self.world.update(dt)

        # Send necessary ObjectUpdate packets.
        for object in self.world.objects:
            if object.type == "player":
                self._send_update(object)

        # Send necessary ObjectStatusUpdate packets.
        for object in self.status_updates:
            update = packets.ObjectStatusUpdate()
            update.object_id = object.object_id
            update.health, update.power = object.health, object.power
            self.server.output_broadcast.put_nowait((update, None))
        self.status_updates.clear()

        # Send buffered output to clients.
        reactor.callFromThread(self.server.send)

        # Sleep some if we're updating too fast.
        extra = 0.01 - dt
        if extra >= 0.001:
            time.sleep(extra)
Beispiel #4
0
    def frameStarted(self, event):
        """ 
        Called before a frame is displayed, handles events
        (also those via callback functions, as you need to call capture()
        on the input objects)

        Returning False here exits the application (render loop stops)
        """
        
        dt = event.timeSinceLastFrame
        
        # Get buffered input from server and process it.
        while not self.client.input.empty():
            packet = self.client.input.get_nowait()
            self.process_packet(packet)
        
        # Add time to schedulers.
        SchedulerManager.update(self, dt)
        
        # Capture any buffered events (and fire any callbacks).
        self.inputHandler.capture()
        
        # Update our UI Elements
        self.gui.update(dt)
        
        # Update the game state world.
        self.world.update(dt)
        
        # Update the audio module so it can throw its events
        audio.update(dt)
        
        # Send an PlayerUpdate packet to the server if appropriate.
        self._send_update()
        
        # Send buffered output to server.
        reactor.callFromThread(self.client.send)
        
        # Add time to animations.
        for node in self.nodes:
            node.update(dt)

        # Neatly close our FrameListener if our renderWindow has been shut down
        # or we are quitting.
        if self.renderWindow.isClosed() or self.quit:
            return False
        
        return True
Beispiel #5
0
 def __init__(self, port=8981):
     SchedulerManager.__init__(self)
     self.port = port
     self.is_round_active = False
Beispiel #6
0
 def __init__(self, port=8981):
     SchedulerManager.__init__(self)
     self.port = port
     self.is_round_active = False