def __chase(self, player): if self.walking_timer <= 0: self.__walk(player) self.walking_timer = 2 else: self.walking_timer -= 1 x = player.rect.topleft[0] y = player.rect.topleft[1] my_x = self.rect.topleft[0] my_y = self.rect.topleft[1] if x+2 > self.rect.topleft[0]: self.follow_direction = "right" my_x += 2 if x-2 < self.rect.topleft[0]: self.follow_direction = "left" my_x -= 2 if y+2 > self.rect.topleft[1]: self.follow_direction = "down" my_y += 2 if y-2 < self.rect.topleft[1]: self.follow_direction = "up" my_y -= 2 self.rect.topleft = helpers.checkBoundry((my_x, my_y)) self.position = self.rect.topleft
def getHit(self, direction, damage): helpers.shake(self.screen, 40) self.old_position = self.rect.topleft if self.invul == 0: if direction == "right": self.old_position = self.position[0] + 40, self.position[1] elif direction == "left": self.old_position = self.position[0] - 40, self.position[1] elif direction == "down": self.old_position = self.position[0], self.position[1] +40 elif direction == "up": self.old_position = self.position[0], self.position[1] -40 self.rect.topleft = helpers.checkBoundry(self.old_position) self.health -= damage self.invul = 80 self.position = self.rect.topleft if self.health < 0: self.alive = False
def __chase(self, spot, rocks): #added rocks to avoid them x = spot[0] y = spot[1] my_x = self.rect.topleft[0] my_y = self.rect.topleft[1] """ working right here to make the enemy move out of the straight chase line of chasing player """ if self.id == 3: lazor_sight = Lazor(self.rect.center, spot) self.lazor_group.add(lazor_sight) self.lazor_group.add(Lazor(self.rect.topleft, spot)) self.lazor_group.update() #self.lazor_group.draw(pygame.display.get_surface()) lazor_rock = pygame.sprite.groupcollide(self.lazor_group, rocks, True, False) if lazor_rock: if x < my_x +40 and x > my_x -40: x += 100 if y < my_y +40 and y > my_y -40: y += 100 if x+10 > self.rect.topleft[0] and not self.blocked_direction == "right": self.follow_direction = "right" my_x += 2 if not self.blocked_direction == "nope": my_x += 2 if x-10 < self.rect.topleft[0]and not self.blocked_direction == "left": self.follow_direction = "left" my_x -= 2 if not self.blocked_direction == "nope": my_x -= 2 if y+10 > self.rect.topleft[1]and not self.blocked_direction == "down": self.follow_direction = "down" my_y += 2 if not self.blocked_direction == "nope": my_y += 2 if y-10 < self.rect.topleft[1]and not self.blocked_direction == "up": self.follow_direction = "up" my_y -= 2 if not self.blocked_direction == "nope": my_y -= 2 """ also working right here to make the enemy move out of the straight chase line of chasing player """ self.rect.topleft = helpers.checkBoundry((my_x, my_y)) self.position = self.rect.topleft
def get_hit(self, direction, damage): self.health -= damage self.clock = 15 knocked_position = (0,0) if direction == "right": knocked_position = self.position[0] + 40, self.position[1] elif direction == "left": knocked_position = self.position[0] - 40, self.position[1] elif direction == "down": knocked_position = self.position[0], self.position[1] +40 elif direction == "up": knocked_position = self.position[0], self.position[1] -40 if self.health <= 0: self.kill() self.rect.topleft = helpers.checkBoundry(knocked_position) self.position = self.rect.topleft
def update(self, player, rocks, enemyGroup): if self.invul > 0: self.invul -= 1 if self.health <= 0: self.kill() self.alive = False player.hasFreind = False self.dialogHandle.companionDeath(self.windowSurface, self) old_position = self.rect.topleft if len(enemyGroup) > 0: if self.recall_timer == 0: if self.weapon == 1: if self.defensive == True: self.bowFightD(player, rocks, enemyGroup) else: self.bowFightA(player, rocks, enemyGroup) else: if self.defensive == True: self.swordFightD(player, rocks, enemyGroup) else: self.swordFightA(player, rocks, enemyGroup) else: self.__chase(player.rect.topleft, rocks, player) self.recall_timer -= 1 else: # print helpers.distance(self.rect.topleft, player.rect.topleft) if helpers.distance(self.rect.topleft, player.rect.topleft) > 6 : self.__chase(player.rect.topleft, rocks, player) if self.walking_timer <=0: self.__walk(player) self.walking_timer = 5 else: self.walking_timer -= 1 if not self.__check_collision(rocks, player, old_position): self.blocked_direction = "nope" self.collide = True self.rect.topleft = helpers.checkBoundry(self.rect.topleft) if old_position == self.rect.topleft and self.weapon ==0 and not self.defensive: self.stayed_still +=1 if self.stayed_still > 25: self.stayed_still = 0 self.__chase(player.rect.topleft, rocks, player) self.recall_timer = 60
def getHit(self, direction, damage): helpers.shake(self.windowSurface, 40) self.old_position = self.rect.topleft self.position = self.rect.topleft if self.weapon == 0: self.attack_group.empty() if self.invul == 0: if direction == "right": self.old_position = self.position[0] + 40, self.position[1] elif direction == "left": self.old_position = self.position[0] - 40, self.position[1] elif direction == "down": self.old_position = self.position[0], self.position[1] +40 elif direction == "up": self.old_position = self.position[0], self.position[1] -40 self.rect.topleft = helpers.checkBoundry(self.old_position) self.health -= damage self.invul = 80 self.position = self.rect.topleft
def get_hit(self, direction, damage): self.image = self.bubble_image if self.vulnerable == True: self.gel -= damage if self.wake: self.hit_rock_timer = 0 self.breakRock(self.rocks) self.wake = True self.knocked_position = self.position if len(self.touched_rocks.sprites()) <= 1: if direction == "right": self.knocked_position = self.position[0] + 10, self.position[1] elif direction == "left": self.knocked_position = self.position[0] - 8, self.position[1] elif direction == "down": self.knocked_position = self.position[0], self.position[1] +8 elif direction == "up": self.knocked_position = self.position[0], self.position[1] -8 self.rect.topleft = helpers.checkBoundry(self.knocked_position) self.position = self.rect.topleft
def __chase(self, player): x = player.rect.topleft[0] y = player.rect.topleft[1] my_x = self.rect.topleft[0] my_y = self.rect.topleft[1] if abs(my_x - x) >= abs(my_y- y): if x+2 > self.rect.topleft[0]: self.follow_direction = "right" my_x += 2 if x-2 < self.rect.topleft[0]: self.follow_direction = "left" my_x -= 2 else: if y+2 > self.rect.topleft[1]: self.follow_direction = "down" my_y += 2 if y-2 < self.rect.topleft[1]: self.follow_direction = "up" my_y -= 2 self.rect.topleft = helpers.checkBoundry((my_x, my_y)) self.position = self.rect.topleft
def __move(self, player): if self.walking_timer <= 0: self.__walk() self.walking_timer = 5 else: self.walking_timer -= 1 x = player.rect.topleft[0] y = player.rect.topleft[1] my_x = self.rect.topleft[0] my_y = self.rect.topleft[1] if x+10 > self.rect.topleft[0]: my_x -= 1 if x-10 < self.rect.topleft[0]: my_x += 1 if y+10 > self.rect.topleft[1]: my_y -= 1 if y-10 < self.rect.topleft[1]: my_y += 1 self.rect.topleft = helpers.checkBoundry((my_x, my_y))
def __patrol(self): x = self.rect.topleft[0] y = self.rect.topleft[1] self.pat_counter += 1 if self.pat_counter >= 41: self.pat_index = randint(0,3) self.pat_counter = 0 direction = self.pat_directions[self.pat_index] patrol_position = (0,0) if direction == "right": patrol_position = x + 2, y if self.walking_timer <=0: self.walking_timer = 10 if self.walking == 0: self.image = self.right_walk self.walking = 1 elif self.walking == 2: self.image = self.right_walk2 self.walking = -1 else: self.image = self.right_still self.walking +=1 else: self.walking_timer -= 1 elif direction == "left": patrol_position = x - 2, y if self.walking_timer <=0: self.walking_timer = 10 if self.walking == 0: self.image = self.left_walk self.walking = 1 elif self.walking == 2: self.image = self.left_walk2 self.walking = -1 else: self.image = self.left_still self.walking +=1 else: self.walking_timer -= 1 elif direction == "up": patrol_position = x, y - 2 if self.walking_timer <=0: self.walking_timer = 10 if self.walking == 0: self.image = self.back_walk self.walking = 1 elif self.walking == 2: self.image = self.back_walk2 self.walking = -1 else: self.image = self.back_still self.walking += 1 else: self.walking_timer -= 1 elif direction == "down": patrol_position = x, y + 2 if self.walking_timer <=0: self.walking_timer = 10 if self.walking == 0: self.image = self.front_walk self.walking = 1 elif self.walking == 2: self.image = self.front_walk2 self.walking = -1 else: self.image = self.front_still self.walking +=1 else: self.walking_timer -= 1 self.rect.topleft = helpers.checkBoundry(patrol_position)