I am trying to handle the collision with shot and asteroid, but after the collision I want to add an explosion.
I added a timer so the explosion is going to show on the screen after some time, but the the explosion shows immediately, and I dont see the problem. This is the function with the problem in my code.
def handle_collision_with_shot_asteroid(self):
for asteroid_rect in self.asteroid_list:
for shot_rect in self.shots:
# check for collision
if asteroid_rect.colliderect(shot_rect):
# remove the shot and the asteroid from the screen
self.asteroid_list.remove(asteroid_rect)
self.shots.remove(shot_rect)
# create an effect after the asteroid get shot
explosion_rect = self.explosion_big.get_rect(center=(asteroid_rect.x+29, asteroid_rect.y+29))
# record the time the explosion started
self.explosion_start_time = pygame.time.get_ticks()
try:
if pygame.time.get_ticks() - self.explosion_start_time > 1000:
# show the explosion
screen.blit(self.explosion_big, explosion_rect)
# Reset the explosion start time so it doesn't show again
self.explosion_start_time = 0
except:
pass