Skip to content

Commit be85a02

Browse files
committed
Create SubClock Class
1 parent b441fb9 commit be85a02

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

arcade/future/sub_clock.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,34 @@ def add_child(child: SubClock):
3636

3737
clock.add_child = add_child # type: ignore -- we know the clock will have .children
3838

39+
40+
class SubClock(Clock):
41+
"""
42+
A SubClock which gets ticked by a parent clock and can have its flow
43+
of time altered independantly of its parent or siblings.
44+
45+
Args:
46+
parent: The clock which will tick the SubClock.
47+
could be the GLOBAL_CLOCK or another SubClock
48+
tick_speed: A multiplier on how the 'speed' of time.
49+
i.e. a value of 0.5 means time elapsed half as fast for this clock. Defaults to 1.0.
50+
"""
51+
52+
def __init__(self, parent: Union[Clock, SubClock, None] = None, tick_speed: float = 1):
53+
parent = parent or GLOBAL_CLOCK
54+
super().__init__(parent._elapsed_time, parent._tick, tick_speed)
55+
self.children: list[SubClock] = []
56+
try:
57+
parent.add_child(self) # type: ignore -- we know the clock will have .children (or if not we want it to yell)
58+
except AttributeError:
59+
raise AttributeError(f'The clock {parent} has not been bootstrapped properly'
60+
f'call boot_strap_clock({parent}) before adding children')
61+
62+
def add_child(self, child: SubClock):
63+
self.children.append(child)
64+
65+
def tick(self, delta_time: float):
66+
super().tick(delta_time)
67+
68+
for child in self.children:
69+
child.tick(self.delta_time)

0 commit comments

Comments
 (0)