Added mousejoint to example
Brian Jordan
15 years ago
10 | 10 | # set up the physics world (instance of Elements) |
11 | 11 | world = physics.Elements(screen.get_size()) |
12 | 12 | world.renderer.set_surface(screen) |
13 | ||
13 | ||
14 | 14 | # set up initial physics objects |
15 | 15 | world.add.ground() |
16 | 16 | world.add.ball((600,0), 50) |
33 | 33 | elif event.type == KEYDOWN: |
34 | 34 | sys.exit() |
35 | 35 | |
36 | elif event.type == MOUSEBUTTONDOWN and event.button == 1: | |
37 | bodylist = world.get_bodies_at_pos(event.pos, include_static=False) | |
38 | if bodylist and len(bodylist) > 0: | |
39 | world.add.mouseJoint(bodylist[0], event.pos) | |
40 | ||
41 | elif event.type == MOUSEBUTTONUP and event.button == 1: | |
42 | world.add.remove_mouseJoint() | |
43 | ||
44 | elif event.type == MOUSEMOTION and event.buttons[0]: | |
45 | world.mouse_move(event.pos) | |
46 | ||
36 | 47 | # clear display with a color |
37 | 48 | # (r,g,b), where 0<=value<256 |
38 | 49 | screen.fill((80,160,240)) |