Я создал несколько функций для обнаружения столкновений. Только моя ewasteCollsion работает прямо сейчас, но мои другие нет. Например, когда батарея сталкивается с электронными отходами, происходит взрыв. Для моих других, как spacehipCollsion не работает. Кто-нибудь знает, как решить эту проблему? (Моего полного кода здесь нет. Я хотел сделать его максимально сжатым)
if spaceship.colliderect(star):
shipEats += 1
return True
False
def ewasteCollision(battery, ewaste): #If battery hits ewaste
global yWastePos
if battery.colliderect(ewaste):
#addEwaste()
yWastePos += 1 #DOESN"T WORK
return True
False
def spaceshipCollision(spaceship, ewaste): #If spaceship hits ewaste
if spaceship.collidrect(ewaste):
health -= 20
return True
False
#=========================IN THE GAME LOOP========================
if is_battery_on_screen == True: #Collsion with battery and ewaste
batteryRect = pygame.Rect(x_battery_pos, y_battery_pos, batteryImage.get_width(), batteryImage.get_height()) #Dimensions of battery
ewasteRect3 = pygame.Rect(xWaste3 + 100, yWaste3, 150, 120) #Dimensions of ewaste
spaceshipRect = pygame.Rect(x_ship_pos + 22, y_ship_pos, 60, 100) #Dimensions of spaceship
if ewasteCollision(batteryRect, ewasteRect3) == True: #If its true, ewaste explodes and disappears
is_battery_on_screen = False
drawExplosion()
drawStars() #Stars appear for user to collect
if spaceshipCollision == True: #DOES NOT WORK!!
ewasteRect = pygame.Rect(xWastePos + 100, yWastePos, 150, 120) #Dimensions of ewaste
spaceshipRect = pygame.Rect(x_ship_pos + 22, y_ship_pos, 60, 100) #Dimensions of spaceship
drawScene3() #Goes to game over page
if starCollsion == True: #DOES NOT WORK!!
starRect = pygame.Rect(xStarPos + 100, yStarPos, 150, 120) #Dimensions of star
spaceshipRect = pygame.Rect(x_ship_pos + 22, y_ship_pos, 60, 100) #Dimensions of spaceship
pygame.draw.rect(screen, RED, starRect, 5) #Remove once done resizing and figured out collsion dimensions```