I don't get why whenever I execute the program and my character collides with the star, it does not execute the following codes? What happens is that it executes the code already even if they are not colliding.
class FinishStar:
def __init__(self):
self.x = screenWidth + 100
self.y = 290
self.image = Finish
self.width = self.image.get_width()
self.rect = self.image.get_rect()
def update(self):
self.x -= gameSpeed
if self.x < -self.width:
self.x = screenWidth + 2500
self.y = 50
def draw(self, screen):
screen.blit(self.image, (self.x, self.y))
and this is the code in main():
if scorePoints >= 100:
star.draw(screen)
star.update()
if player.character_rect.colliderect(star.rect):
font = pygame.font.Font('Fonts/Bubblebody.ttf', 22)
font1 = pygame.font.Font('Fonts/Affogato-Bold.otf', 20)
font2 = pygame.font.Font('Fonts/Billgis - Personal Use.ttf', 38)
font3 = pygame.font.Font('Fonts/Affogato-Medium.otf', 31)
background_image = pygame.image.load(os.path.join("Images/Start",
"Level1Complete.png"))
screen.blit(background_image, [0, 0])
text = font1.render("PRESS ANY KEY TO CONTINUE", True, (122, 166, 185))
screen.blit(text, [411, 400])
text = font2.render("level one completed", True, (163, 213, 176))
screen.blit(text, [467, 292])
text = font.render("Congratulations!", True, (163, 213, 176))
screen.blit(text, [473, 321])
text = font3.render("SCORE: 400/400", True, (122, 166, 185))
screen.blit(text, [450, 349])
pygame.display.update()
TriviaLvl1.mainTrivia()