I am trying to make a game in pygame, and I am almost done. I am just having problems with my game over mechanics. After I die by touching my enemy my enemies dissappear, i send them to Y=2000 when I die, and now they continue moving and then comes up after a few seconds. My game over music works, but my game over text wont.
In my code I have this code for game over, because I want to lose when the enemies touch me:
# Game Over
if isCollision(enemyX[i], enemyY[i], playerX, playerY):
for j in range(num_of_enemies):
enemyY[j] = 2000
game_over_text()
break
This wont work, because what I described just now happens.
I have tried to change the code and use this:
# Game Over
if enemyY[i] > 440:
for j in range(num_of_enemies):
enemyY[j] = 2000
game_over_text()
break
This works, and I get the game over text, the game over sound and my enemies wont come back. But this is not how I want it to work.
Anyone have any ideas on how I can fix this?
this is my code for the iscollision function:
def isCollision(enemyX, enemyY, bulletX, bulletY):
# Formel for distanse mellom to koordinater
distance = math.sqrt((math.pow(enemyX-bulletX, 2)) + (math.pow(enemyY-bulletY, 2)))
if distance < 30:
return True
else:
return False
It detects the collision, but the collision code stops the game over text from working.
My whole code: https://gist.github.com/EkteFrokostNam/a46b8a905ec3d1f190af482887a80341