-
Notifications
You must be signed in to change notification settings - Fork 3
/
particle.py
executable file
·69 lines (54 loc) · 1.38 KB
/
particle.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
import pygame
import numpy
class Particle:
sprite=pygame.image.load("gfx/particle.png")
def __init__(self, world, pos, vel, timeout):
self.world = world
self.pos = numpy.array(pos)
self.vel = numpy.array(vel)
self.timeout = timeout
def __call__(self):
self.pos += self.vel
self.timeout -= 1
if self.timeout <= 0:
self.world.background.blit(self.sprite, self.pos)
return True
return False
def draw(self, screen):
screen.blit(self.sprite, self.pos)
class Smoke:
sprite = pygame.image.load("gfx/smoke.png")
def __init__(self, world, pos, vel, timeout):
self.pos = numpy.array(pos)
self.vel = numpy.array(vel)
self.timeout = timeout
def __call__(self):
self.pos += self.vel
self.timeout -= 1
if self.timeout <= 0:
return True
return False
def draw(self, screen):
screen.blit(self.sprite, self.pos)
class Plus(Smoke):
sprite = pygame.image.load("gfx/plus.png")
class Dot(Smoke):
sprite = pygame.image.load("gfx/snipetrace.png")
class ParticleSystem:
def __init__(self):
self.particles = []
def create(self, part):
self.particles.append(part)
def __call__(self):
eraseList = []
for p in self.particles:
if p():
eraseList.append(p)
for p in eraseList:
self.particles.remove(p)
def draw(self, screen):
for p in self.particles:
p.draw(screen)
def clean(self):
self.particles = []