def lock_enemy(self, tower, enemy): """Locks missile onto enemy and calls shoot() To lock on need shoot_counter at 0, enemy alive, no missile alive. Then, if enemy in range of tower, un-destroy missile. Then call shoot and listen for and return hit. Args: tower (obj): Tower associated with missile enemy (obj): Enemy to try to lock on to Returns: hit (tuple, int, str, obj): The result passed returned by shoot() """ if self.shoot_counter < 1: if not enemy.destroy: if self.destroy is True: if self.lock_on is None: if helpers.collision(tower, enemy): tower_shoot_sound.play() self.lock_on = enemy self.destroy = False self.shoot_counter = self.shoot_rate hit = self.shoot(enemy) return hit
def draw_mage(mage, game_clock, score_board, funds, enemies_list): """Draw mage, kill enemies if spell hits them, pop enemies from enemies_list Args: mage (obj): The mage hero object to draw and interact with enemies game_clock (obj): Game time to pass to mage score_board (obj): Score to adjust when enemies die funds (obj): Players money to adjust when enemies die enemies_list (list of obj): List of enemies for mage to interact with """ # Draw mage mage.draw(game_clock.stat) # Kill enemies hit by mage spell and collect their points/money for enemy in enemies_list: if helpers.collision(mage, enemy): if not enemy.destroy: enemy.take_damage(3000, True) kill = enemy.check_death() if kill: points, cash = kill score_board.adjust(points) funds.adjust(cash) # Pop enemies from from enemy_list when indicated by mage if mage.pop_enemies_counter == 0: enemies_list.pop(enemies_list.index(enemy))
def draw_enemies(enemies_list, castle): """Draw enemies, damage castle if appropriate and check enemy interactions Enemies struck by fire tower will light other nearby enemies on fire. Function will pop enemies from enemies_list once they die and have 0 lives. Enemies will damage castle if they reach it. Args: enemies_list (list of obj): list of all enemies in play castle (obj): Castle object determines game loss if too many hits """ # Iterate over all enemies for enemy in enemies_list: # Pop from list after last death if enemy.lives == 0: enemies_list.pop(enemies_list.index(enemy)) # Check for enemies damaging castle castle_damage = enemy.draw() # Check for enemies lit on fire by fire tower # Light other nearby enemies on fire if current enemy is aflame if enemy.fireball2: for adjacent in enemies_list: if adjacent != enemy: if helpers.collision(enemy, adjacent): adjacent.fire2 = enemy.fire2 adjacent.burned_counter = 3 if enemy.fireball1 and not enemy.fireball2: for adjacent in enemies_list: if adjacent != enemy: if helpers.collision(enemy, adjacent): adjacent.fire1 = enemy.fire1 adjacent.burned_counter = 3 # Reduce castle health if enemy reaches castle if castle_damage: if castle.stat > 0: castle.adjust(-castle_damage) castle_hit.play()
def lock_enemy(self, tower, enemy): """Locks missile onto enemy and calls shoot() Difference with BasicMissile lock_enemy: Will not lock onto enemy if burn just applied to that enemy. """ if self.shoot_counter < 1: # Only lock-on if not freshly burned if enemy.burned_counter < 2: if not enemy.destroy: if self.destroy is True: if self.lock_on is None: if helpers.collision(tower, enemy): self.lock_on = enemy self.destroy = False self.shoot_counter = self.shoot_rate hit = self.shoot(enemy) return hit
def lock_enemy(self, tower, enemy): """Locks missile onto enemy and calls shoot() Difference with BasicMissile lock_enemy: Will not lock onto enemy until poison off or nearly off. """ if self.shoot_counter < 1: # Only lock-on if not poisoned (or about to be) if enemy.poison_charges < 2: if not enemy.destroy: if self.destroy is True: if self.lock_on is None: if helpers.collision(tower, enemy): self.lock_on = enemy self.destroy = False self.shoot_counter = self.shoot_rate hit = self.shoot(enemy) return hit
def hit(self, enemy): """Determines if missile hit enemy Check for collision between missile and enemy. If collision with locked on target occurs, destroy missile and set its location back to tower. If the enemy is not destroyed, return damage, specialty and hit_sound. Args: enemy: Locked on enemy to check missile collision against Returns: self.damage (int): Damage given to enemy on hit (varies by specialty) self.specialty (str): Defines special attributes of missile self.hit_sound (obj): Object of sound to play on missile hit """ if helpers.collision(self, enemy): self.destroy = True self.lock_on = None self.x, self.y = self._tower_location if not enemy.destroy: return self.damage, self.specialty, self.hit_sound