Ejemplo n.º 1
0
    def __init__(self, config):
        from timer import TimerCollection
        from event import EventQueue
        self.state = STOPPED
        self.config = config
        self._info = None
        self.connections = []
        self.event_queue = EventQueue()
        self.timers = TimerCollection()
        EventSource.__init__(self)
        EventListener.__init__(self)

        # Yes we are a listener to ourselves
        self.addListener(self)

        self.setState(STARTING)
        if self.config.getBindAddress() != None and \
           self.config.getPort() != None:
            log.debug("Initializing server on %s:%d" % 
                    (self.config.getBindAddress(), self.config.getPort()))
            srv_sock = create_server_socket(self.config.getBindAddress(),
                                            self.config.getPort())
            self.addConnection(ServerConnection(srv_sock))
            log.debug("Server initialized")

        else:
            log.debug("Initialized non-server agent")
Ejemplo n.º 2
0
 def __init__(self):
     EventLauncher.__init__(self)
     EventListener.__init__(self)
     # In kbits/s
     self.video_bitrate = vb = 2000 
     # In bits/s
     self.audio_bitrate = ab = 128000
     # In kbits/s
     self.video_width = 320 
     self.video_height = 240
     self.video_framerate = 25
     self.registerEvent("sos")
Ejemplo n.º 3
0
    def __init__(self, width, height, caption="Street Pirates Vs. Ninjas"):
        """
        Constructor.
        @param  self     [Main]     itself  
        @param  width    [Int]      width of the window
        @param  height   [Int]      height of the window
        @param  caption  [String]   caption of the window
        """
        self.width = width
        self.height = height

        # pygame objects initialization
        pygame.init()

        icon = pygame.image.load("assets/Icone.png")
        pygame.display.set_icon(icon)
        self._soundManager = SoundManager()
        self._soundManager.playMenuMusic()

        self._fpsClock = pygame.time.Clock()
        self._window = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)

        pygame.display.set_caption(caption)

        pygame.mouse.set_cursor(*pygame.cursors.tri_left)

        # game objects initialization
        self._scene = Scene([[100, 0, 0], [-100, 0, 0]], self)
        self._listener = EventListener(self._scene, self)
        self._startMenu = StartMenu(self)
        self._startMenu.drawSplashScreen()  # just before loading
        self._screen = Screen(self._window, self._scene, self._startMenu)
        self._startMenu.draw()

        # main object properties initialization
        self.state = GameState.START_MENU
        self.loop = True
Ejemplo n.º 4
0
WINDOW_WIDTH=1000
WINDOW_HEIGHT=480

pygame.init()

fpsClock = pygame.time.Clock()

windowSurfaceObj = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT), pygame.DOUBLEBUF)
pygame.display.set_caption("Street Pirates Vs. Ninja")
fontObj = pygame.font.Font('freesansbold.ttf', 42)
msg = "Hello world!"

scene = Scene([ [2, 2, 0], [1, 0, 0] ])
screen = Screen(windowSurfaceObj, scene)
listener = EventListener(scene)

bluecolor = pygame.Color(0, 0, 255)
msg = "Hello world"

while True:
    listener.listen()
    screen.draw()
    msg = str(scene._players[0].position())
    msg1 = str(scene._players[0].speed())
    # msg += str(scene._players[1].position())
    msgSurfaceObj = fontObj.render(msg, False, bluecolor)
    msgRectObj = msgSurfaceObj.get_rect()
    scene.update()
    msgRectObj.topleft = (10, 20)
    windowSurfaceObj.blit(msgSurfaceObj, msgRectObj)
Ejemplo n.º 5
0
class Main:
    """ Main class for the game. """

    def __init__(self, width, height, caption="Street Pirates Vs. Ninjas"):
        """
        Constructor.
        @param  self     [Main]     itself  
        @param  width    [Int]      width of the window
        @param  height   [Int]      height of the window
        @param  caption  [String]   caption of the window
        """
        self.width = width
        self.height = height

        # pygame objects initialization
        pygame.init()

        icon = pygame.image.load("assets/Icone.png")
        pygame.display.set_icon(icon)
        self._soundManager = SoundManager()
        self._soundManager.playMenuMusic()

        self._fpsClock = pygame.time.Clock()
        self._window = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)

        pygame.display.set_caption(caption)

        pygame.mouse.set_cursor(*pygame.cursors.tri_left)

        # game objects initialization
        self._scene = Scene([[100, 0, 0], [-100, 0, 0]], self)
        self._listener = EventListener(self._scene, self)
        self._startMenu = StartMenu(self)
        self._startMenu.drawSplashScreen()  # just before loading
        self._screen = Screen(self._window, self._scene, self._startMenu)
        self._startMenu.draw()

        # main object properties initialization
        self.state = GameState.START_MENU
        self.loop = True

    def start(self):
        """
        Launches the main loop of the game.
        @param  self     [Main]     itself
        """
        # main loop
        while self.loop:
            if self.state == GameState.START_MENU:
                self._listener.listen()
                self._startMenu.draw()
            elif self.state == GameState.IN_GAME:
                self._listener.listen()
                self._screen.draw()

            self._fpsClock.tick(30)

    def stop(self):
        """
        Definitely stop the main loop.
        @param  self     [Main]     itself
        """
        self.loop = False

    def changeState(self, state):
        self.state = state
        self._soundManager.stop()
        if state == GameState.IN_GAME:
            self._soundManager.playMusic("fightmusic")