def update(self,wMap, cellTypes, enemies, player): if self.hp > 0: if not self.attack: self.wander(wMap,cellTypes,player) elif self.attack and getDistanceOf(self.x,self.y,player.x,player.y)<2: attack = self.getAttack() if attack > 0: toast("%s attacked the player for %d damage." % (self.name, attack)) else: toast("%s misses his attack." % (self.name)) player.hp-=attack player.fighting = 5
def attackEnemy(self,enemy): if getDistanceOf(self.x,self.y,enemy.x,enemy.y)<self.getAttackDistance(): maxAttack = self.getAttack() attack = random.randint(maxAttack/2,maxAttack) enemy.hp -= attack if attack > 0: toast("You attack the %s for %d damage"%(enemy.name,attack)) else: toast("Your attack missed.") else: toast("Your attack from too far away.") enemy.attack = True self.moved = True