def attack(self, weapon): log.info('ATTACKING') components = [] if Team in self.entity.components: components.append(Team( self.entity.component(Team).name)) display = None for klass, kwargs in weapon.components: log.info(klass) log.info(kwargs) if klass == Display: c = klass(**kwargs) display = c elif klass == Spatial: c = klass(sprite=display.sprite, **kwargs) else: c = klass(**kwargs) components.append(c) e = Entity(*components) e.component(Spatial).center = self.entity.component(Spatial).center self.manager.add_entities(e) weapon.fire(e)
def get_edges(self, start, player, refresh=False): """ Get edges for given start using given player's max jump attributes. Checks for collisions between the two nodes to make sure there's a clear path. Return a set() of path nodes. """ log.info('getting edges from: %s, for player: %s', start, player) all_nodes = self.nodes m = player.component(Movement) max_jump_x = m.max_jump_x max_jump_y = m.max_jump_y if (start in all_nodes and (max_jump_x, max_jump_y) in all_nodes[start] and not refresh): # Return the previously existing nodes return _edges(start, player) reachable = set() for n in all_nodes: if n == start: continue if abs(n[0]-start[0]) > max_jump_x: continue if n[1]-start[1] > max_jump_y: continue reachable.add(n) edges = set() for r in reachable: testity = Entity( Spatial(width=abs(r[0]-start[0]), height=abs(r[1]-start[1])), Collisions(no_handlers=True)) s = testity.component(Spatial) log.info('width: %s, height: %s', s.width, s.height) tcol = testity.component(Collisions) if r[0] > start[0]: # Edge is right of start s.left = start[0] elif r[0] < start[0]: # Edge is left of start s.left = r[0] else: # vertical line, what do? s.left = start[0] if r[1] > start[1]: # Edge is above start s.bottom = start[1] elif r[1] < start[1]: # Edge is below start s.bottom = r[1] else: # Edge is level with start s.bottom = start[1] blocked = False for cop in self.collidables.objs_colliding(testity): if r[0] > start[0] and 'left' in cop.solid_edges: blocked = True break if r[0] < start[0] and 'right' in cop.solid_edges: blocked = True break if r[1] > start[1] and 'bottom' in cop.solid_edges: blocked = True break if r[1] < start[1] and 'top' in cop.solid_edges: blocked = True break if blocked: continue else: edges.add(r) return edges