-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathobjects.py
44 lines (35 loc) · 953 Bytes
/
objects.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
# ------------------------------------------------------------------
# objects.py
#
# The game objects such as Player etc.
# ------------------------------------------------------------------
world = []
proxy_map = {}
destroy_requests = []
def create(cons, *args):
if hasattr(cons, 'proxy_type'):
proxy = cons.proxy_type()
obj = cons(proxy, *args)
obj.proxy = proxy
proxy_map[proxy] = obj
else:
obj = cons(*args)
world.append(obj)
return obj
def handle_requests():
while destroy_requests:
destroy(destroy_requests.pop())
def request_destroy(obj):
destroy_requests.append(obj)
def destroy(obj):
if hasattr(obj, 'proxy'):
del proxy_map[obj.proxy]
obj.destroy()
world.remove(obj)
def destroy_all():
global world
for obj in world:
if hasattr(obj, 'proxy'):
del proxy_map[obj.proxy]
obj.destroy()
world = []