-
Notifications
You must be signed in to change notification settings - Fork 0
/
particles.py
54 lines (41 loc) · 1.75 KB
/
particles.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pygame
from utils import Arithmetic, Constants, Settings
from math import *
class Particle(object):
def __init__(self, pos, size, vel, col, mingfx=2):
self.pos = pos
self.size = size
self.vel = vel
self.col = col
self.minfx = mingfx
def draw(self, surface):
pygame.draw.circle(surface, self.col, [int(round(self.pos[0])), int(round(self.pos[1]))], self.size)
def tick(self):
self.pos[0] += self.vel[0]
self.pos[1] += self.vel[1]
def dead(self):
return Settings.GRAPHICS < self.minfx or \
not(0 <= self.pos[0] <= Constants.WIDTH and 0 <= self.pos[1] <= Constants.HEIGHT)
class FadingParticle(Particle):
def __init__(self, pos, size, vel, col, fade, mingfx=2):
Particle.__init__(self, pos, size, vel, col, mingfx=mingfx)
self.alpha = col.a
self.fade = fade
def tick(self):
Particle.tick(self)
self.alpha = Arithmetic.clamp(0.0, 255.0, self.alpha - self.fade)
self.col.a = int(round(self.alpha))
def dead(self):
return Particle.dead(self) or self.alpha <= 0
class FlippyLineParticle(Particle):
def __init__(self, pos, size, vel, col, rot, rotRate, mingfx=2):
Particle.__init__(self, pos, size, vel, col, mingfx=mingfx)
self.rot = rot
self.rotRate = rotRate
def tick(self):
Particle.tick(self)
self.rot += self.rotRate
def draw(self, surface):
sx, ex = int(round(self.pos[0] - self.size * cos(self.rot))), int(round(self.pos[0] + self.size * cos(self.rot)))
sy, ey = int(round(self.pos[1] - self.size * sin(self.rot))), int(round(self.pos[1] + self.size * sin(self.rot)))
pygame.draw.line(surface, self.col, (sx, sy), (ex, ey))