Exemplo n.º 1
0
 def __init__(self, client, receive_ip, receive_port, client_id=0):
     from threading import Thread
     from zombie.common import udp_socket
     
     self.client = client
     
     self.socket = udp_socket()
     
     if isinstance(receive_ip, str):
         receive_ip = receive_ip.encode('ascii')
     self.receive_ip = receive_ip
     self.receive_port = receive_port
     
     self.client_id = client_id
Exemplo n.º 2
0
 def __init__(self, map_name, *args, **kwargs):
     from zombie.common import map_file_path, udp_socket
     from zombie.constants import CLIENT_CODES
     
     from blosc import compress
     
     super(Server, self).__init__(*args, **kwargs)
     
     self.map_name = map_name
     
     self.map_file_path = map_file_path(map_name)
     self.map_data = compress(open(self.map_file_path, 'rb').read(), 8)
     #self.map_data_send = bytes((len(self.map_data),)) + self.map_data
     
     self.client_socket = udp_socket()
     
     self.clients = {}
     self.client_id_counter = 1
     
     self.objects = {}
     self.object_id_counter = 0
     
     self.map_objects = {}
     
     self.zombies = {}
     self.zombie_id_counter = 0
     
     self.client_code_actions = {
         CLIENT_CODES['start_move_forwards']: self.start_move_forwards,
         CLIENT_CODES['end_move_forwards']: self.end_move,
         CLIENT_CODES['start_move_backwards']: self.start_move_backwards,
         CLIENT_CODES['end_move_backwards']: self.end_move,
         CLIENT_CODES['start_strafe_left']: self.start_strafe_left,
         CLIENT_CODES['end_strafe_left']: self.end_strafe,
         CLIENT_CODES['start_strafe_right']: self.start_strafe_right,
         CLIENT_CODES['end_strafe_right']: self.end_strafe,
         CLIENT_CODES['start_attack']: self.start_attack,
         CLIENT_CODES['end_attack']: self.end_attack,
         CLIENT_CODES['start_use']: self.start_use,
         CLIENT_CODES['end_use']: self.end_use,
         CLIENT_CODES['throw_equipped_item']: self.throw_equipped_item,
         CLIENT_CODES['drop_equipped_item']: self.drop_equipped_item,
         CLIENT_CODES['cursor_motion']: self.cursor_motion,
     }
     
     self.setup_physics()
Exemplo n.º 3
0
 def __init__(self, zombie_client, receive_ip, receive_port, server_ip, server_port, client_id=0):
     from threading import Thread
     from zombie.common import udp_socket
     
     self.zombie_client = zombie_client
     
     self.socket = udp_socket()
     
     self.receive_ip = receive_ip
     self.receive_port = receive_port
     self.server_ip = server_ip
     self.server_port = server_port
     
     self.client_id = client_id
     
     self.client_receiver = NetworkReceiver(self, (receive_ip, receive_port), NetworkHandler)
     receiver_thread = Thread(target=self.client_receiver.serve_forever)
     receiver_thread.start()
Exemplo n.º 4
0
 def __init__(self, config, client_ip, client_port):
     from threading import Thread
     from cocos.director import director
     from zombie.common import udp_socket
     
     super(Client, self).__init__()
     
     self.socket = udp_socket()
     
     self.key_lookup = self.load_key_config(config['input']['key'])
     self.mouse_lookup = self.load_mouse_config(config['input']['mouse'])
     
     width, height = director.window.get_size()
     
     self.x_divide = width / 255
     self.y_divide = height / 255
     
     self.player_x = 0
     self.player_y = 0
     self.cursor_changed = 0
     
     self.schedule_interval(self.cursor_update, 0.1)
     
     self.sender = ClientSender(self, client_ip, client_port)
     self.send = self.sender.send
     
     # TODO
     receive_ip = 'localhost'
     receive_port = 9998
     
     self.receiver = ClientReceiver(self, (receive_ip, receive_port), ClientHandler)
     receiver_thread = Thread(target=self.receiver.serve_forever)
     receiver_thread.start()
     
     self.config = config
     
     #from cocos.layer.util_layers import ColorLayer
     player = Player(255, 200, 200, *self.config['player']['color'])
     player.position = width / 2, height / 2
     self.add(player)
     from cocos.actions import RotateBy
     player.do(RotateBy(360, duration=10))
Exemplo n.º 5
0
 def __init__(self, config, client_ip, client_port, server_ip, server_port):
     from zombie.common import udp_socket
     
     super(ZombieClient, self).__init__()
     
     self.socket = udp_socket()
     
     self.key_lookup = self.load_key_config(config['input']['key'])
     self.mouse_lookup = self.load_mouse_config(config['input']['mouse'])
     
     self.width = 640
     self.height = 480
     
     self.x_divide = 640 / 255
     self.y_divide = 480 / 255
     
     self.x = 0
     self.y = 0
     self.cursor_changed = 0
     
     self.schedule_interval(self.cursor_update, 0.1)
     
     self.client = NetworkClient(self, client_ip, client_port, server_ip, server_port)
     self.client.connect()