def __init__(self, canvas, field: Field): self.field = field self.canvas = canvas self.pos = Vector(0, 0) self.old_pos = Vector(0, 0) self.v = Vector(0, 0) self.shape = None
def __init__(self, canvas, team): self.canvas = canvas self.team = team self.pos = Vector(0, 0) self.old_pos = Vector(0, 0) self.shape = None self.miss_ball = False
def shoot(self, num_goal): y_min = self.field.center_y - Field.BOX y_max = self.field.center_y + Field.BOX y = y_min + randint(0, y_max - y_min) if num_goal == 1: point = Vector(self.field.start_x, y) else: point = Vector(self.field.end_x, y) m = randint(40, 80) / 10 self.v = Vector(m, m).mul(point.sub(self.pos).norm())
def set_rand_speed(self, team: int): if team == 1: vx = randint(40, 60) / 10 if randint(0, 1) == 0: vy = randint(1, 10) / 5 else: vy = -randint(1, 10) / 5 self.v = Vector(vx, vy) elif team == 2: vx = -randint(40, 60) / 10 if randint(0, 1) == 0: vy = randint(1, 10) / 5 else: vy = -randint(1, 10) / 5 self.v = Vector(vx, vy)
def stop(self): self.v = Vector(0, 0)
def direct_to_point(self, point: Vector): m = randint(20, 60) / 10 self.v = Vector(m, m).mul(point.sub(self.pos).norm())
def goal2(self): return Vector(self.end_x, self.center_y)
def left(self): return self.pos.add(Vector(Player.RADIUS, 0))
def set_on_center(self, field: Field): if self.team == 1: self.set(Vector(field.start_x + Field.BOX / 3, field.center_y)) elif self.team == 2: self.set(Vector(field.end_x - Field.BOX / 3, field.center_y))
def is_goal2(self) -> bool: return self.field.goal2_rectangle.hit( self.pos.add(Vector(Ball.RADIUS, 0)))
def is_goal1(self) -> bool: return self.field.goal1_rectangle.hit( self.pos.sub(Vector(Ball.RADIUS, 0)))
def end_xy(self): return Vector(self.end_x, self.end_y)
def start_xy(self): return Vector(self.start_x, self.start_y)
def center(self): return Vector(self.center_x, self.center_y)
def left(self): return self.pos.sub(Vector(Goalkeeper.RADIUS, 0))
def right(self): return self.pos.add(Vector(Goalkeeper.RADIUS, 0))
def set_in_goal1(self): self.set(Vector(self.field.start_x - 2 * Ball.RADIUS, self.pos.y))
def move_to_ball_y(self, ball: Ball, field: Field): if field.goal_start_y <= ball.pos.y <= field.goal_end_y: y = field.center_y + (ball.pos.y - field.center_y) / 2 self.set(Vector(self.pos.x, y))
def set_in_goal2(self): self.set(Vector(self.field.end_x + 2 * Ball.RADIUS, self.pos.y))
def right(self): return self.pos.sub(Vector(Player.RADIUS, 0))
def set(self, new_pos: Vector): self.old_pos = self.pos self.pos = new_pos self.v = Vector(0, 0) self.paint()
def move_to_point(self, point: Vector): v = randint(1, 10) / 10 self.move(point.sub(self.pos).norm().mul(Vector(v, v)))
def goal1(self): return Vector(self.start_x, self.center_y)