def update(self, mouse_pos): self.hovered = get_distance(self.pos, mouse_pos) <= self.radius if self.grabbed: angle = get_angle(self.pos, mouse_pos) if self.angle < .5 * pi: if angle > self.min_angle: angle = self.max_angle else: if angle > self.min_angle: angle = self.min_angle self.angle = angle if self.angle != self.last_angle: self.rotate() self.adjust_output() self.last_angle = self.angle
def attack(self, dt, other): dist = angles.get_distance(self.pos, other.pos) to_other = angles.get_angle(self.pos, other.pos) rot_diff = self.get_rotation(to_other) try: direction = rot_diff / abs(rot_diff) except ZeroDivisionError: direction = 0 if abs(rot_diff) < ONEDEG * 1.5: self.laser.fire(dt, self) else: self.steering.rotate(dt, self, direction) if abs(rot_diff) < (.5 * math.pi): if self.speed < self.thruster.max_speed: self.thruster.accelerate(dt, self) else: if self.speed > 0: self.retro_thruster.decelerate(dt, self)
def new_destination(self, planets): if self.destination is None: p = random.choice(planets.sprites()) self.destination = p.pos self.angle = angles.get_angle(self.pos, self.destination)