Exemple #1
0
    def __init__(self, serverip, serverport, team, nick, screenMgr):
        super(SpylightGame, self).__init__()
        self.screenMgr = screenMgr

        # Register to the server
        self._ni = NetworkInterface(serverip, serverport)
        init_response = self._ni.connect(MessageFactory.init(team, nick))

        # Parse server init message
        self.team = init_response['team']
        self.playerid = init_response['id']

        # Init environment
        loaded_map = SpyLightMap(init_response['map'])
        Logger.info("SL|SLGame: Map loaded: %s", loaded_map.title)
        Logger.info("SL|SLGame: Map size: %s", loaded_map.size)

        if init_response['map_hash'] != loaded_map.get_hash():
            Logger.error("SL|SLGame: Wrong map hash. Expected %s",
                         loaded_map.get_hash())
            sys.exit()

        self.init_game_view(loaded_map, init_response)

        self.hud = SpylightHUD(self, max_hp=init_response['max_hp'])
        self.add_widget(self.hud)

        # Register input listeners
        kbMgr = KeyboardManager()
        kbMgr.bind(quit=screenMgr.goToPauseScreen)
        self._am = ActionManager(self._ni, kbMgr, self)

        # Game client ready
        self._ni.on_message_recieved = self.update
        self._ni.ready()
Exemple #2
0
    def __init__(self, serverip, serverport, team, nick, screenMgr):
        super(SpylightGame, self).__init__()
        self.screenMgr = screenMgr

        # Register to the server
        self._ni = NetworkInterface(serverip, serverport)
        init_response = self._ni.connect(MessageFactory.init(team, nick))

        # Parse server init message
        self.team = init_response['team']
        self.playerid = init_response['id']

        # Init environment
        loaded_map = SpyLightMap(init_response['map'])
        Logger.info("SL|SLGame: Map loaded: %s", loaded_map.title)
        Logger.info("SL|SLGame: Map size: %s", loaded_map.size)

        if init_response['map_hash'] != loaded_map.get_hash():
            Logger.error("SL|SLGame: Wrong map hash. Expected %s",
                         loaded_map.get_hash())
            sys.exit()

        self.init_game_view(loaded_map, init_response)

        self.hud = SpylightHUD(self, max_hp=init_response['max_hp'])
        self.add_widget(self.hud)

        # Register input listeners
        kbMgr = KeyboardManager()
        kbMgr.bind(quit=screenMgr.goToPauseScreen)
        self._am = ActionManager(self._ni, kbMgr, self)

        # Game client ready
        self._ni.on_message_recieved = self.update
        self._ni.ready()
Exemple #3
0
    def notify_movement_event(self, keyPressed, keyboardState):
        # Angle calculation @TODO: replace with tangent method?
        dir_to_angle = {
            11: 45,
            10: 0,
            9: 315,
            1: 90,
            0: 0,
            -1: 270,
            -9: 135,
            -10: 180,
            -11: 225
        }

        dir_values = [10, 1, -10, -1]
        s = 0
        for i in xrange(len(dir_values)):
            if keyboardState[i]:
                s = s + dir_values[i]

        direction = float(dir_to_angle[s])
        speed = 0.0 if s == 0 else 1.0 if keyboardState[4] else self._WALK_SPEED

        # Send direction, run state
        Logger.debug("SL|Action: direction: %s, speed: %s", direction, speed)
        self._ni.send(MessageFactory.move(direction, speed))
Exemple #4
0
 def notify_orientation(self, *param):
     '''
     The maximum send frequency is the same as the server step frequency
     '''
     delta = datetime.now() - self.last_turn_notification
     if delta.microseconds / 1000000. >= const.STEP_STATE_INTERVAL:
         self._ni.send(MessageFactory.turn(
             self._get_angle_with_char(Window.mouse_pos)))
         self.last_turn_notification = datetime.now()
Exemple #5
0
 def notify_shoot(self, window, mouseevent):
     self.game.mv.draw_shot(Window.mouse_pos)  # TODO: test only, to remove
     self._ni.send(MessageFactory.shoot(
         self._get_angle_with_char(Window.mouse_pos)))
Exemple #6
0
 def notify_action(self, mgr, data):
     if data:
         self._ni.send(MessageFactory.action(True))