I have these two class and I want to check if there's any collision between them: I wanted to make a simple collision between those two, even if it is with both of them with square hitboxes. The bullets are also in a list bullets = [].
class Enemies(object):
def __init__(self, rank):
self.rank = rank
if self.rank == 1:
self.points = [(-20, 20), (20, 20), (5, 30), (-5, 30)]
elif self.rank == 2:
self.points = [(-25, 20), (25, 20), (10, 30), (-10, 30)]
elif self.rank == 3:
self.points = [(-35, 20), (35, 20), (20, 30), (-20, 30)]
elif self.rank == 4:
self.points = [(-45, 20), (45, 20), (30, 30), (-30, 30)]
elif self.rank == 5:
self.points = [(-55, 20), (55, 20), (40, 30), (-40, 30)]
self.x = 1100
self.y = 300
self.speed = 1
self.spawn_delay = 2000
def update(self):
self.x -= self.speed
def draw(self, screen, color):
points = [(x + self.x, y + self.y) for x, y in self.points]
pygame.draw.polygon(screen, color, points, 0)
class Bullet(object):
def __init__(self, player, time):
self.x = player.x + 25 * math.cos(player.angle)
self.y = player.y - 25 * math.sin(player.angle)
self.angle = player.angle
self.initial_velocity = 50
self.time = time
self.g = 9.8
self.active = True
self.last_shoot_time = 0
self.radius = 5
def update(self):
self.x += + self.initial_velocity * self.time * math.cos(self.angle)
self.y -= + self.initial_velocity * self.time * math.sin(self.angle) - 0.5 * self.g * self.time ** 2
screen_width = 1000
screen_height = 380
if self.x < 0 or self.x > screen_width or self.y < 0 or self.y > screen_height:
self.active = False
def draw(self, screen, color):
pygame.draw.circle(screen, color, (int(self.x), int(self.y)), self.radius)```