I am trying to collide my car sprite with another rect, right now I am using rect collisions and my car collision video, but each time I rotate the hitbox it moves somewhere else.
Is there a way I could collide my car sprite with that hitbox instead of using a car hitbox?
My car class:
class Car:
def __init__(self, x, y, height, width, color):
self.x = x - width / 2
self.y = y - height / 2
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x, y, height, width)
self.surface = pygame.Surface((height, width), pygame.SRCALPHA)
self.surface.blit(img, (0, 0))
self.angle = 250
self.speed = 0# 2
self.hitbox = (self.x + 90, self.y + 620, 370, 63)# CARS HITBOX
pygame.draw.rect(window, (255, 0, 0), self.hitbox, 2)
def draw(self): #3
self.rect.topleft = (int(self.x), int(self.y))
rotated = pygame.transform.rotate(self.surface, self.angle)
surface_rect = self.surface.get_rect(topleft = self.rect.topleft)
new_rect = rotated.get_rect(center = surface_rect.center)
window.blit(rotated, new_rect.topleft)
self.hitbox = (self.x, self.y, 70, 40)# CARS HITBOX BLITTING AT car x, y
pygame.draw.rect(window, (255, 0, 0), self.hitbox, 2)# draw the car hitbox
white = (255, 255, 255)
car1 = Car(100, 630, 73, 73, white)# 4
My full code is here