def step(self, data): """Move the enemy forward a single time-step Parameters: grid (GridCoordinateTranslator): Grid the enemy is currently on path (Path): The path the enemy is following Returns: bool: True iff the new location of the enemy is within the grid """ grid = data.grid path = data.path #starts generating swarm enemies if below half life if self.health / SuperRichardEnemy.health <= 0.5: swarm = [(5, SwarmEnemy())] if self.swarm_count < 10: for i in range(5): for step, enemy in swarm: enemy.set_cell_size(self.game.grid.cell_size) self.spawn_swarm(swarm) self.swarm_count += 1 # Repeatedly move toward next cell centre as much as possible movement = self.grid_speed while movement > 0: cell_offset = grid.pixel_to_cell_offset(self.position) # Assuming cell_offset is along an axis! offset_length = abs(cell_offset[0] + cell_offset[1]) if offset_length == 0: partial_movement = movement else: partial_movement = min(offset_length, movement) cell_position = grid.pixel_to_cell(self.position) delta = path.get_best_delta(cell_position) # Ensures enemy will move to the centre before moving toward delta dx, dy = get_delta_through_centre(cell_offset, delta) speed = partial_movement * self.cell_size self.move_by((speed * dx, speed * dy)) self.position = tuple(int(i) for i in self.position) movement -= partial_movement intersects = rectangles_intersect(*self.get_bounding_box(), (0, 0), grid.pixels) return intersects or grid.pixel_to_cell(self.position) in path.deltas
def step(self, units): """Performs a time step for this pulse Moves according to direction, damaging any enemies that are collided with along the way If hits is non-zero, this pulse expires if it has the number of enemies hit is at least 'hits', else continues until off the grid Parameters: units.enemies (UnitManager): The unit manager to select targets from Return: (persist, new_obstacles) pair, where: - persist (bool): True if the obstacle should persist in the game (else will be removed) - new_obstacles (list[AbstractObstacle]): A list of new obstacles to add to the game, or None """ dx, dy = tuple(self.speed * i for i in self.direction) x, y = old_position = self.position self.position = new_position = x + dx, y + dy try: old_bucket = units.enemies.get_bucket_for_position(old_position) new_bucket = units.enemies.get_bucket_for_position(self.position) except IndexError: return False, None for enemy in old_bucket.union(new_bucket): if enemy in self._damaged: continue x1, y1 = old_position x2, y2 = new_position if x2 < x1: x1, x2 = x2, x1 if y2 < y1: y1, y2 = y2, y1 tl1, br1 = (x1, y1), (x2, y2) tl2, br2 = enemy.get_bounding_box() if rectangles_intersect(tl1, br1, tl2, br2): enemy.damage(self.damage, 'pulse') self._damaged.add(enemy) if self._hit_count and len(self._damaged) >= self._hit_count: return False, None return True, None
def step(self, data): """Move the enemy forward a single time-step Parameters: grid (GridCoordinateTranslator): Grid the enemy is currently on path (Path): The path the enemy is following Returns: bool: True iff the new location of the enemy is within the grid """ grid = data.grid path = data.path # Repeatedly move toward next cell centre as much as possible movement = self.grid_speed while movement > 0: cell_offset = grid.pixel_to_cell_offset(self.position) # Assuming cell_offset is along an axis! offset_length = abs(cell_offset[0] + cell_offset[1]) if offset_length == 0: partial_movement = movement else: partial_movement = min(offset_length, movement) cell_position = grid.pixel_to_cell(self.position) delta = path.get_best_delta(cell_position) # Ensures enemy will move to the centre before moving toward delta dx, dy = get_delta_through_centre(cell_offset, delta) speed = partial_movement * self.cell_size self.move_by((speed * dx, speed * dy)) self.position = tuple(int(i) for i in self.position) movement -= partial_movement # regenerate health (x times where x is a random integer from 2 to 4) when health hits 10% regenerate_times = random.randrange(2, 5) while self.health <= 10 and self.regeneration_counter <= regenerate_times: self.health = self.health * 10 self.regeneration_counter += 1 intersects = rectangles_intersect(*self.get_bounding_box(), (0, 0), grid.pixels) return intersects or grid.pixel_to_cell(self.position) in path.deltas
def step(self, data): """Move the enemy forward a single time-step Parameters: grid (GridCoordinateTranslator): Grid the enemy is currently on path (Path): The path the enemy is following Returns: bool: True iff the new location of the enemy is within the grid """ grid = data.grid path = data.path # Repeatedly move toward next cell centre as much as possible movement = self.grid_speed while movement > 0: cell_offset = grid.pixel_to_cell_offset(self.position) # Assuming cell_offset is along an axis! offset_length = abs(cell_offset[0] + cell_offset[1]) if offset_length == 0: partial_movement = movement else: partial_movement = min(offset_length, movement) cell_position = grid.pixel_to_cell(self.position) delta = path.get_best_delta(cell_position) call_enemy._spawn_count += 1 # Add a count for each step it makes. At count 50, a new minion will be spawned. # Ensures enemy will move to the centre before moving toward delta dx, dy = get_delta_through_centre(cell_offset, delta) speed = partial_movement * self.cell_size self.move_by((speed * dx, speed * dy)) self.position = tuple(int(i) for i in self.position) call_enemy._position = self.position # Current updated position movement -= partial_movement # Heal health if self.health < 5500: self.health += 10 # Heal health by 15 points intersects = rectangles_intersect(*self.get_bounding_box(), (0, 0), grid.pixels) return intersects or grid.pixel_to_cell(self.position) in path.deltas
def step(self, data): """Move the enemy forward a single time-step Parameters: grid (GridCoordinateTranslator): Grid the enemy is currently on path (Path): The path the enemy is following Returns: bool: True iff the new location of the enemy is within the grid """ grid = data.grid path = data.path # Repeatedly move toward next cell centre as much as possible movement = self.grid_speed while movement > 0: cell_offset = grid.pixel_to_cell_offset(self.position) #Assuming cell_offset is along an axis! offset_length = abs(cell_offset[0] + cell_offset[1]) if offset_length == 0: partial_movement = movement else: partial_movement = min(offset_length, movement) cell_position = grid.pixel_to_cell(self.position) delta = path.get_best_delta(cell_position) #Ensures enemy will move to the centre before moving toward delta dx, dy = get_delta_through_centre(cell_offset, delta) speed = partial_movement * self.cell_size self.move_by((speed * dx, speed * dy)) self.position = tuple(int(i) for i in self.position) movement -= partial_movement intersects = rectangles_intersect(*self.get_bounding_box(), (0, 0), grid.pixels) return intersects or grid.pixel_to_cell(self.position) in path.deltas """Tried to destroy all tower as an advanced enemy feature,