Ejemplo n.º 1
0
    def step(self, units):
        """Rotates toward 'target' and fires missile if possible"""
        self.cool_down.step()

        target = self._get_target(units.enemies)

        if target is None:
            return None

        # Rotate toward target
        angle = angle_between(self.position, target.position)
        partial_angle = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)

        self.rotation = partial_angle

        if angle != partial_angle or not self.cool_down.is_done():
            return None

        self.cool_down.start()

        # Spawn missile on tower
        missile = Missile(self.position,
                          self.cell_size,
                          target,
                          rotation=self.rotation,
                          damage=self.get_damage(),
                          grid_speed=.3)

        # Move missile to outer edge of tower
        radius = self.grid_size[0] / 2
        delta = polar_to_rectangular(self.cell_size * radius, partial_angle)
        missile.move_by(delta)

        return [missile]
Ejemplo n.º 2
0
    def step(self, units):
        """Performs a time step for this missile
        
        Moves towards target and damages if collision occurs
        If target is dead, this missile expires
        
        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
        """
        if self.target.is_dead():
            return False, None

        # move toward the target
        radius = euclidean_distance(self.position, self.target.position)

        if radius <= self.speed:
            self.target.damage(self.damage, 'explosive')
            return False, None

        # Rotate toward target and move
        angle = angle_between(self.position, self.target.position)
        self.rotation = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)

        dx, dy = polar_to_rectangular(self.speed, self.rotation)
        x, y = self.position
        self.position = x + dx, y + dy

        return True, None
Ejemplo n.º 3
0
    def step(self, data):
        """Rotates toward 'target' and attacks if possible"""
        self.cool_down.step()

        target = self.get_unit_in_range(data.enemies)

        if target is None:
            return

        # check if the enemy is custom enemy.
        for enemy in self.get_units_in_range(data.enemies):
            if not enemy.name == "Energy Enemy":
                return
            else:
                target = enemy
                break

        angle = angle_between(self.position, target.position)
        partial_angle = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)
        self.rotation = partial_angle

        # use energy to attack enemies.
        if partial_angle == angle:
            target.damage(self.get_damage(), 'energy')
Ejemplo n.º 4
0
Archivo: a3.py Proyecto: mj221/CSSE1001
    def step(self, data):
        """Rotates toward 'target' and attacks if possible"""
        self.cool_down.step()

        target = self.get_unit_in_range(data.enemies)

        if target is None:
            return

        angle = angle_between(self.position, target.position)
        partial_angle = rotate_toward(self.rotation, angle, self.rotation_threshold)
        self.rotation = partial_angle

        if partial_angle == angle:
            target.damage(self.get_damage(), 'energy')
Ejemplo n.º 5
0
    def step(self, data):
        """Rotates toward 'target' and attacks if possible"""
        self.cool_down.step()

        #If no enemy in range does nothing
        if self.get_unit_in_range(data.enemies) is None:
            return

        #If energy enemy is in range it faces and damages it
        target = self.get_unit_in_range(data.enemies)
        angle = angle_between(self.position, target.position)
        partial_angle = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)
        self.rotation = partial_angle
        if partial_angle == angle:
            if target.name == "Energy Enemy":
                target.damage(self.get_damage(), 'energy')
        else:
            return
Ejemplo n.º 6
0
    def step(self, units):
        if self.target.is_dead():
            return False, None

        # move toward the target
        radius = euclidean_distance(self.position, self.target.position)

        if radius <= self.speed:
            self.target.damage(self.damage, 'fire')
            return False, None

        # Rotate toward target and move
        angle = angle_between(self.position, self.target.position)
        self.rotation = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)

        dx, dy = polar_to_rectangular(self.speed, self.rotation)
        x, y = self.position
        self.position = x + dx, y + dy

        return True, None
Ejemplo n.º 7
0
    def step(self, data):
        """Rotates toward 'target' and slow down it if possible"""
        self.cool_down.step()

        target = self.get_unit_in_range(data.enemies)

        if target is None:
            return

        angle = angle_between(self.position, target.position)
        partial_angle = rotate_toward(self.rotation, angle,
                                      self.rotation_threshold)
        self.rotation = partial_angle

        if angle != partial_angle or not self.cool_down.is_done():
            return None

        self.cool_down.start()

        # slow down the target.
        if partial_angle == angle:
            if target.grid_speed > 1 / 50:
                target.grid_speed -= 1 / 600