Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame, random
- pygame.init()
- clock = pygame.time.Clock()
- WIDTH = 800
- HEIGHT = 600
- screen = pygame.display.set_mode((WIDTH, HEIGHT))
- particles = []
- # Creating a semi-transparent surface to create fade-effect.
- bg = pygame.Surface((WIDTH,HEIGHT))
- bg.set_alpha(70)
- bg.fill((0,0,0))
- class Particle():
- def __init__(self,x,y):
- self.x = x
- self.y = y
- self.speed_x = random.randint(-12,12)
- self.speed_y = random.randint(-12,2)
- self.life = random.randint(3,9)
- self.farge = 255
- def update(self):
- self.x += self.speed_x
- self.y += self.speed_y
- self.speed_y += 0.5
- self.life -= 0.5
- self.farge -= 7
- if self.x > WIDTH or self.x < 0: self.speed_x *= -1
- if self.y > HEIGHT: self.speed_y *= -1
- if self.life < 1:
- particles.remove(self)
- del self
- def draw(self):
- pygame.draw.circle(screen,(255,self.farge,0),(int(self.x),int(self.y)),int(self.life))
- # END OF PARTICLE CLASS
- def explotion(mx,my):
- for i in range(60):
- minPartikkel = Particle(mx,my)
- particles.insert(0,minPartikkel)
- while True:
- screen.blit(bg,(0,0))
- for particle in particles[::-1]:
- particle.update()
- particle.draw()
- clock.tick(30)
- pygame.display.update()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- running = False
- # create explotion everywhere the mouse moves
- if event.type == pygame.MOUSEMOTION:
- mx,my = pygame.mouse.get_pos()
- explotion(mx,my)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement