예제 #1
0
 def collides(self, hb):
     if hb.shape =='circle':
         if gamemath.distance_between_two_points(self.get_position(), hb.get_position()) < self.radius + hb.radius:
             return True
     elif hb.shape =='rectangle':
         coords = self.get_position()
         if hb.point_in_hitbox(coords):
             return True
         if gamemath.distance_between_two_points(coords, gamemath.closest_point_in_rectangle(coords, hb.rect)) < self.radius:
             return True
     return False
예제 #2
0
 def collides(self, hb):
     if hb.shape == 'circle':
         if gamemath.distance_between_two_points(hb.get_position(), gamemath.closest_point_in_rectangle(hb.get_position(), self.rect)) < hb.radius:
             return True
         return False
     elif hb.shape == 'rectangle':
         return self.rect.colliderect(hb.rect)
     return False
예제 #3
0
def circle_on_circle(objOne, objTwo):
    hbOne = objOne.hitbox
    hbTwo = objTwo.hitbox
    theta = gamemath.radians_between_two_points(hbOne.get_position(),
                                                hbTwo.get_position())
    d = objTwo.hitbox.radius + hbOne.radius - gamemath.distance_between_two_points(
        hbOne.get_position(), hbTwo.get_position())
    xy = gamemath.get_xy_move(theta)
    return (xy, d)
예제 #4
0
    def update(self, dt):
        theta = gamemath.degrees_between_two_points((self.x, self.y),
                                                    self.coordList[self.index])
        xy = gamemath.get_xy_move(theta)
        self.increment_position(xy[0] * self.moveSpeed * dt,
                                xy[1] * self.moveSpeed * dt)
        checkForCollision(self)

        if gamemath.distance_between_two_points(
            (self.x, self.y), self.coordList[self.index]) < 7:
            self.index += 1
            print(self.index)
            if self.index > 1:
                self.index = 0
예제 #5
0
def circle_on_rectangle(objOne, objTwo):
    hbOne = objOne.hitbox
    hbTwo = objTwo.hitbox
    closest_point = gamemath.closest_point_in_rectangle(
        hbOne.get_position(), hbTwo.rect)
    # calculate the angle:
    theta = gamemath.radians_between_two_points(hbOne.get_position(),
                                                closest_point)
    # calculate the distance of the intersect:
    d = hbOne.radius - gamemath.distance_between_two_points(
        hbOne.get_position(), closest_point)
    # move back d
    xy = gamemath.get_xy_move(theta)
    return (xy, d)
예제 #6
0
def rectangle_on_circle(self, x, y, hb):
    if hb.property_flag == 'wall':
        closest_point = gamemath.closest_point_in_rectangle(
            hb.get_position(), self.hitbox.rect)
        # calculate the angle:
        theta = gamemath.radians_between_two_points(closest_point,
                                                    hb.get_position())
        # calculate the distance of the intersect:
        d = hb.radius - gamemath.distance_between_two_points(
            closest_point, hb.get_position())
        # move back d
        xy = gamemath.get_xy_move(theta)
        self.hitbox.increment_position(xy[0] * -d, xy[1] * -d)
        self.set_position_by_tuple(self.hitbox.get_position())
예제 #7
0
 def checkForArrival(self):
     if gamemath.distance_between_two_points(
         (self.x, self.y), self.targetPoint) < self.tolerance:
         self.atTargetPoint = True
     else:
         self.atTargetPoint = False
예제 #8
0
 def point_in_hitbox(self, pos):
     if gamemath.distance_between_two_points((self.x, self.y),pos) < self.radius:
         return True
     return False