-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticle.py
More file actions
28 lines (24 loc) · 840 Bytes
/
Copy pathparticle.py
File metadata and controls
28 lines (24 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pygame
import random
class Particle:
def __init__(self, x, y, color):
self.x = x
self.y = y
self.vx = random.uniform(-4, 4) # x veolcity
self.vy = random.uniform(-4, 4)
self.lifetime = 255 # Used for transparency (alpha)
self.color = color
self.size = random.randint(2, 5)
def update(self):
self.x += self.vx
self.y += self.vy
self.lifetime -= 7 # How fast the particle fades
def draw(self, surface):
if self.lifetime > 0:
# Create a small surface for the particle to allow transparency
s = pygame.Surface((self.size, self.size))
s.set_alpha(self.lifetime)
s.fill(self.color)
surface.blit(s, (self.x, self.y))
def is_dead(self):
return self.lifetime <= 0