def rotate_angle(self): if self.direction == Direction.CLOCKWISE: self.angle = util.mod_angle(self.angle - settings.rot_speed) elif self.direction == Direction.COUNTERCLOCKWISE: self.angle = util.mod_angle(self.angle + settings.rot_speed)
def adjust_target_angle(self, angle): self.target_angle = angle clockwise_angle = util.mod_angle(self.angle - self.target_angle) counterclockwise_angle = util.mod_angle(self.target_angle - self.angle) self.direction = self.get_direction(clockwise_angle, counterclockwise_angle)
def get_reflect_angle(self, angle): if self.side == Side.LEFT and util.is_left(angle): return util.mod_angle(180 - angle) if self.side == Side.RIGHT and util.is_right(angle): return util.mod_angle(180 - angle) if util.is_vertical(angle): return 180 if self.side == Side.LEFT else 0 return angle
def shoot(self): if self.state != State.SWINGING: # enter swinging state, note that speed and pos are kept the same self.state = State.SWINGING self.adjust_target_angle(util.mod_angle(self.angle - settings.swing_angle)) self.shoot_angle = self.angle # angle before swinging is angle to shoot the ball assert(self.direction == Direction.CLOCKWISE)
def check_walls(self): if self.pos[1] <= settings.topwall + self.radius and util.is_up( self.angle): self.angle = util.mod_angle(360 - self.angle) elif self.pos[1] >= settings.bottomwall - self.radius and util.is_down( self.angle): self.angle = util.mod_angle(360 - self.angle) if self.pos[0] <= settings.leftwall + self.radius and util.is_left( self.angle) and self.not_within_goal(): self.angle = util.mod_angle(180 - self.angle) elif self.pos[0] >= settings.rightwall - self.radius and util.is_right( self.angle) and self.not_within_goal(): self.angle = util.mod_angle(180 - self.angle)
def target_angle_reached(self): if self.state == State.NORMAL: self.direction = Direction.STATIONARY else: if self.direction == Direction.CLOCKWISE: # just swung the stick to full potential self.adjust_target_angle(util.mod_angle(self.angle + settings.swing_angle)) else: # in the middle of swinging assert(self.direction == Direction.COUNTERCLOCKWISE and self.state == State.SWINGING) self.direction = Direction.STATIONARY self.state = State.NORMAL