class ClientChannel(Channel, pygame.sprite.Sprite): """ Cette classe gère un client, qui se connecte au serveur, et lui attribue un bar. """ def __init__(self, *args, **kwargs): Channel.__init__(self, *args, **kwargs) pygame.sprite.Sprite.__init__(self) self.bar = Bar() self.tirCompteurTmp = outils.FREQUENCE_TIR self.shotAllowed = True self.tir_sprites = Tirs() self.joueur = outils.J1 def Close(self): self._server.del_client(self) def Network(self, data): pass def Network_keys(self, data): """ Cette fonction permet de récupérer les mouvements du client, et de les traiter. :param data: Les données reçues du client. """ touches = data['keys'] if touches[K_RIGHT] or touches[K_d]: self.bar.right() if touches[K_LEFT] or touches[K_q]: self.bar.left() if touches[K_SPACE]: if self.shotAllowed: tir = Tir(self.bar) self.tir_sprites.add(tir) self.shotAllowed = False self.tirCompteurTmp = outils.FREQUENCE_TIR self.send_info("sound", "shot.wav") else: if self.tirCompteurTmp >= 0: self.tirCompteurTmp -= 1 else: self.shotAllowed = True def update_bar(self): self.bar.update() self.tir_sprites.update(self.joueur) def send_info(self, action, message): print action + " - " + message self.Send({"action": action, "message": message}) def get_bar(self): return self.bar
def __init__(self, *args, **kwargs): Channel.__init__(self, *args, **kwargs) pygame.sprite.Sprite.__init__(self) self.bar = Bar() self.tirCompteurTmp = outils.FREQUENCE_TIR self.shotAllowed = True self.tir_sprites = Tirs() self.joueur = outils.J1