-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_clear_static_shapes.py
More file actions
30 lines (30 loc) · 1.64 KB
/
Copy pathtest_clear_static_shapes.py
File metadata and controls
30 lines (30 loc) · 1.64 KB
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
import importlib.util, pymunk
mod_path = r'c:\Users\RIC0016\OneDrive - Templestowe College\Desktop\Coding\Python\Rohan_Python_Sims\Jelly Pytruck.py'
spec = importlib.util.spec_from_file_location('mod', mod_path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
space = pymunk.Space()
space.gravity = mod.GRAVITY
print('Initial static shapes:', len(list(space.static_body.shapes)))
start, finish = mod.load_level(space, 1)
print('After load_level 1 static shapes:', len(list(space.static_body.shapes)))
print('Static shapes types:', [type(s).__name__ for s in list(space.static_body.shapes)])
for i,s in enumerate(list(space.static_body.shapes)):
print(' member', i, 'in space.shapes?', s in list(space.shapes))
truck = mod.Truck(space, pymunk.Vec2d(150,250))
mod.clear_level(space, truck)
print('After clear_level static shapes:', len(list(space.static_body.shapes)))
for i,s in enumerate(list(space.static_body.shapes)):
print(' post-clear member', i, 'in space.shapes?', s in list(space.shapes))
mod.load_level(space, 2)
print('After load_level 2 static shapes:', len(list(space.static_body.shapes)))
print('Static types now:', [type(s).__name__ for s in list(space.static_body.shapes)])
# Print first 5 segment endpoints for inspection
segs = [s for s in list(space.static_body.shapes) if isinstance(s, pymunk.Segment)]
print('Segments count:', len(segs))
for i,s in enumerate(segs[:5]):
print(i, 'p1', s.a, 'p2', s.b, 'rad', s.radius)
polys = [s for s in list(space.static_body.shapes) if isinstance(s, pymunk.Poly)]
print('Polys count:', len(polys))
for i,s in enumerate(polys[:5]):
print(i, 'verts', [v for v in s.get_vertices()])