Oct-24-2019, 07:34 AM
I've been following a tutorial on youtube "buildwithpython" on a spaced invaders game. tutorial went great leaning alot. I've been tweaking and experimenting on adding different thind. I'm having problems getting my explosion image to appear on every monster hit. It will appear from 1 to 3 times and then nothing for two or three more then repeats.
Relevant code below. if you need more let me know.
Thanks for any help
Relevant code below. if you need more let me know.
Thanks for any help
# Explosion
explosionImg = pygame.image.load('explosion2.png')
explosionX = 0
explosionY = 0
explosionX_change = 0
explosion_change = 0
explosion_state = "ready"
def isCollision(monsterX, monsterY, bulletX, bulletY, explosionX, explosionY):
distance = math.sqrt((math.pow(monsterX - bulletX, 2)) + (math.pow(monsterY - bulletY, 2)))
if distance < 27:
return True
else:
return False
#### My addition #####
def explosion(x, y):
global explosion_state
explosion_state = "explode"
screen.blit(explosionImg, (x, y))
# Monster Movement
for i in range(num_of_monsters):
monsterX[i] += monsterX_change[i]
if monsterX[i] <= 0:
monsterX_change[i] = 2
monsterY[i] += monsterY_change[i]
elif monsterX[i] >= 736:
monsterX_change[i] = -2
monsterY[i] += monsterY_change[i]
# Collision
collision = isCollision(monsterX[i], monsterY[i], bulletX, bulletY,explosionX, explosionY)
if collision:
bulletY = 480
bullet_state = "ready"
score_value += 1
#### My addition ####
explosion_state = "ready"
explosion(monsterX[i], monsterY[i])
#####################################
monsterX[i] = random.randint(0, 735)
monsterY[i] = random.randint(50, 150)
sounds('explosion.wav')
monster(monsterX[i], monsterY[i], i)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
Download my project scripts
