def __init__(self, jug, direction, hcriat, hit_callback, die_callback): self.bala = Bala(jug.uid, jug.x, jug.y, direction, jug.get_team()) self.hit_callback = hit_callback self.die_callback = die_callback self.hcriat = hcriat self.mapa = self.hcriat.get_map() self.jug = jug self.jug.block_shot() reactor.callLater(self.bala.DELAY, self.loop)
class BulletHandler(object): def __init__(self, jug, direction, hcriat, hit_callback, die_callback): self.bala = Bala(jug.uid, jug.x, jug.y, direction, jug.get_team()) self.hit_callback = hit_callback self.die_callback = die_callback self.hcriat = hcriat self.mapa = self.hcriat.get_map() self.jug = jug self.jug.block_shot() reactor.callLater(self.bala.DELAY, self.loop) def loop(self): if self.update(): reactor.callLater(self.bala.DELAY, self.loop) def update(self): # proximo movimiento x = self.bala.x + self.bala.dx y = self.bala.y + self.bala.dy # recuperamos el id de lo que haya en la proxima posicion mid = self.mapa.get_id_by_pos(x, y) # mid = map id # hit nothing or its owner if mid in (0, self.bala.get_uid()): self.bala.mover() return True # hit a block if mid == 1: return False else: # hit a creature c = self.hcriat.get_creature_by_uid(mid) # same team if self.bala.is_team(c.get_team()): self.bala.mover() return True # enemy else: if c.is_live(): if c.hit(self.bala.DMG): self.die_callback(mid) else: self.hit_callback(mid, self.bala.DMG) return False