def player_attack(self): self.player.sprite.do_animate() direction = self.player.sprite.direction x = self.player.stats.x y = self.player.stats.y if direction == sprite.LEFT: if self.map.is_entity_blocked_left(self.player): entity = self.map.layers[2].get(x-1, y) if entity: self.attackSound.play() entity.stats.hp -= 25 if entity.stats.hp <= 0: self.score_kill(entity) self.f.transport.sendLine(pickle.dumps(entity.getUpdate(),2)) elif direction == sprite.RIGHT: if self.map.is_entity_blocked_right(self.player): entity = self.map.layers[2].get(x+1, y) if entity: self.attackSound.play() entity.stats.hp -= 25 if entity.stats.hp <= 0: self.score_kill(entity) self.f.transport.sendLine(pickle.dumps(entity.getUpdate(),2)) elif direction == sprite.UP: if self.map.is_entity_blocked_up(self.player): entity = self.map.layers[2].get(x, y-1) if entity: self.attackSound.play() entity.stats.hp -= 25 if entity.stats.hp <= 0: self.score_kill(entity) self.f.transport.sendLine(pickle.dumps(entity.getUpdate(),2)) elif direction == sprite.DOWN: if self.map.is_entity_blocked_down(self.player): entity = self.map.layers[2].get(x, y+1) if entity: self.attackSound.play() entity.stats.hp -= 25 if entity.stats.hp <= 0: self.score_kill(entity) self.f.transport.sendLine(pickle.dumps(entity.getUpdate(),2))
def move_enemy(): if not glob.map.layers: return for entity in glob.map.layers[2].entities: moves = [] if glob.map.is_player_up(entity): moves.append(UP) if glob.map.is_player_down(entity): moves.append(DOWN) if glob.map.is_player_left(entity): moves.append(LEFT) if glob.map.is_player_right(entity): moves.append(RIGHT) if not moves: move = choice([UP, DOWN, LEFT, RIGHT]) else: move = choice(moves) if move == UP: if not glob.map.is_entity_blocked_up(entity): entity.stats.y -= 1 elif move == DOWN: if not glob.map.is_entity_blocked_down(entity): entity.stats.y += 1 elif move == LEFT: if not glob.map.is_entity_blocked_left(entity): entity.stats.x -= 1 else: if not glob.map.is_entity_blocked_right(entity): entity.stats.x += 1 # send updated position information to all other clients for t in factory.transports: t.sendUpdate(entity.getUpdate())