-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticles.py
71 lines (57 loc) · 1.74 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from config import *
from utils import *
import gameObjects
import threading
import factory
class ParticleObj(gameObjects.GameObject):
""" generic particle object
"""
PARAMS = ["parent_id", "rect", "duration"]
def __init__(self, **kwargs):
# particle specific params
self.parent_id = None
self.duration = None
self.dead = False
self.die_on_impact = False # against tiles or go's
# internal usage
self.t0 = 0.0
self.update_rate = 0.1
self._started = False
self._done = False
kwargs["moveable"] = False
super().__init__(**kwargs)
#
def start(self):
self._started = True
# spin up thread
thread = Thread(target = self.thread)
thread.start()
# add self to game-objects
tup = make_gen_msg(self)
MESSAGES.put(tup)
def set_done(self):
self._done = True
def thread(self):
""" independent countdown thread """
t0 = get_game_time()
tt = t0
while not self._done:
dt = get_game_time() - tt
# BUG: is update getting called for this obj in physics too? idk...
# self.update(dt) # in parent game obj
# sleep
time.sleep(self.update_rate)
# exit condition
tt = get_game_time()
if (tt - t0) > self.duration:
# print("dt: {}".format(tt-t0))
self.set_done()
# self-destruct
self.die()
def die(self):
if not self.dead:
self.dead = True
""" add self to the del list """
tup = make_del_msg(self)
# print(tup[1].id)
MESSAGES.put(tup)