Skip to content
Browse files

added explosion effect on menu

  • Loading branch information...
1 parent be6f62a commit d4d38fcc3d1ba5459c4c9f54819228113eb76c1e michael committed
Showing with 22 additions and 8 deletions.
  1. +7 −1 sources/menu.py
  2. +15 −7 sources/particles.py
View
8 sources/menu.py
@@ -7,10 +7,13 @@
from pygame.locals import *
import pickle
import effects
+import particles
+
pygame = common_pygame.pygame
screen= common_pygame.screen
clock = common_pygame.clock
+
class Menu():
def play_sound(self, sound):
@@ -98,7 +101,8 @@ def launch(self, withresume):
screen.blit(self.single_sprites['menu_micshooter.png'],(120,40))
self.compteur=self.compteur+1
-
+ #update the particles
+ particles.blitAndUpdate()
@@ -106,6 +110,7 @@ def launch(self, withresume):
#change the selection
if pygame.key.get_pressed()[pygame.K_UP]:
if self.compteur>=5:
+ particles.addRandomExplosion(3)
#print(self.selection)
self.play_sound(self.sounds["menu.wav"])
self.selection=self.selection-1
@@ -114,6 +119,7 @@ def launch(self, withresume):
self.compteur=0
if pygame.key.get_pressed()[pygame.K_DOWN] and self.compteur>=5:
+ particles.addRandomExplosion(3)
#print(self.selection)
self.play_sound(self.sounds["menu.wav"])
self.selection=self.selection+1
View
22 sources/particles.py
@@ -28,16 +28,24 @@ def addExplosion ( x, y, size):
directiony =random.randrange(-10, 10)
whatsprite=random.randrange(1, 5)
- print (whatsprite)
+ speedspritex=random.randrange(1, 10)
+ speedspritey=random.randrange(1, 10)
+ #print (whatsprite)
spritename= "particle" + str(whatsprite) + ".png"
sprite = single_sprites[spritename]
#x position, y position, directionx, directiony, time, sprite size, sprite
- particleList.append((x, y, directionx, directiony, 0, sprite.get_width(), sprite ))
+ particleList.append((x, y, directionx, directiony, 0, sprite.get_width(), sprite, speedspritex, speedspritey ))
explosions.append(particleList)
+
+def addRandomExplosion (size):
+ placeX = random.randrange(00, 800)
+ placeY = random.randrange(0, 600)
+ addExplosion ( placeX, placeY, size)
+
def determine(k):
- (x, y, directionx, directiony, time, size, sprite) = k
+ (x, y, directionx, directiony, time, size, sprite, speedspritex, speedspritey) = k
if time > 30:
return False
return True
@@ -48,15 +56,15 @@ def blitAndUpdate():
explosions[i][:]=[k for k in explosions[i] if determine(k)]
for j in range(len(explosions[i])):
#blit the concerned particle
- (x, y, directionx, directiony, time, size, sprite) = explosions[i][j]
+ (x, y, directionx, directiony, time, size, sprite, speedspritex, speedspritey) = explosions[i][j]
if size>0 and time%2 ==0:
size=size-1
toblit = pygame.transform.scale(sprite,( size, size))
screen.blit(toblit, (x,y))
- x=x+directionx
- y=y+directiony
+ x=x+directionx+speedspritex
+ y=y+directiony+speedspritey
time=time+1
- explosions[i][j]=(x, y, directionx, directiony, time, size, sprite)
+ explosions[i][j]=(x, y, directionx, directiony, time, size, sprite,speedspritex, speedspritey )

0 comments on commit d4d38fc

Please sign in to comment.
Something went wrong with that request. Please try again.