Ejemplo n.º 1
0
 def __init__(self, origin, target, tick, type_, attack_package, nondefaultlist=None):
     pygame.sprite.Sprite.__init__(self)
     self.pos = origin
     self.type = type_
     self.target = target
     self.atk_package = attack_package
     self.damage = self.atk_package[0]
     self.lifepsan = self.atk_package[2]
     self.angle = functions.get_angle(self.pos, self.target)
     self.speed = self.atk_package[1]
     self.tickmade = tick
     self.rect = pygame.Rect(self.pos[0] + 8, self.pos[1] + 7, 17, 17)
     if nondefaultlist is None:
         pass
     else:
         nondefaultlist.append(self)
Ejemplo n.º 2
0
    def cast_ray(self, phys_space, origin, targets, single=False):
        collisions = []
        view_dist = 500
        a_offset = 0.00001
        col_group = 2
        for target in targets:
            a = -get_angle(*origin, *target)
            c1p = self.move_in_angle(a, origin, view_dist)
            c1 = phys_space.segment_query_first(
                origin, c1p, group=col_group
            )
            if c1:
                hp = c1.get_hit_point()
                collisions.append((hp.x, hp.y, a))
            else:
                collisions.append((c1p[0], c1p[1], a))
            if not single:
                a2 = a - a_offset
                c2p = self.move_in_angle(a2, origin, view_dist)
                # print(pos, mp, c2p)
                c2 = phys_space.segment_query_first(
                    origin, c2p, group=col_group
                )
                a3 = a + a_offset
                c3p = self.move_in_angle(a3, origin, view_dist)
                c3 = phys_space.segment_query_first(
                    origin, c3p, group=col_group
                )
                if c2:
                    hp = c2.get_hit_point()
                    collisions.append((hp.x, hp.y, a2))
                else:
                    collisions.append((*c2p, a2))
                if c3:
                    hp = c3.get_hit_point()
                    collisions.append((hp.x, hp.y, a3))
                else:
                    collisions.append((*c3p, a3))

        return collisions
Ejemplo n.º 3
0
def draw_wedge(center, radius, start, end):

    x, y = draw_circle(center, radius)
    angle = np.zeros(x.shape)
    for i in range(x.size):
        angle[i] = get_angle(center[0], center[1], y[i], x[i])

    angle = np.round(angle, 2)

    # When the positive x-axis is included in the wedge, the end
    # angle is smaller than the start angle. In this case all the
    # angles between 0° and the end angle must be increased by 360°
    # so the condition for selecting the window works as intended.
    if start > end:

        condition = (angle >= 0) & (angle <= end)
        angle = np.where(condition, angle + 360, angle)
        end = end + 360

    # The positive x-axis has an angle of 0°. It must be set
    # to 360°, when the end angle is exactly 360°, so the condition
    # for selecting the window works as intended.
    if end == 360:
        angle = np.where(angle == 0, 360, angle)

    # selecting cells that fall into the window.
    window = np.where((angle >= start) & (angle <= end))

    x = x[window]
    x = np.append(center[1], x)
    x = np.append(x, center[1])
    y = y[window]
    y = np.append(center[0], y)
    y = np.append(y, center[0])

    return (x, y)
Ejemplo n.º 4
0
 def update(self):
     if self.pos == self.target:
         self.kill()
     self.angle = functions.get_angle(self.pos, self.target)
     self.pos = functions.project(self.pos, self.angle, self.speed)
     self.rect = pygame.Rect(self.pos[0] + 8, self.pos[1] + 7, 17, 17)
Ejemplo n.º 5
0
 def __init__(self, p1, p2):
     self.p1, self.p2 = p1, p2
     self.angle = get_angle(*p1, *p2)