13 raise SystemExit("Usage: %s filename ..." % sys
.argv
[0])
16 screen
= pygame
.display
.set_mode([600, 600], pygame
.DOUBLEBUF
)
17 bullet
= pygame
.Surface([3, 3])
18 bullet
.fill([255, 0, 0])
19 clock
= pygame
.time
.Clock()
20 target
= bulletml
.Bullet()
25 filename
= argv
[file_idx
% len(argv
)]
26 doc
= bulletml
.BulletML
.FromDocument(open(filename
, "rU"))
27 actions
= [act([], 0.5) for act
in doc
.top
]
28 source
= bulletml
.Bullet(
29 x
=150, y
=150, target
=target
, actions
=actions
, rank
=0.5)
31 active
= set([source
])
32 source
.vanished
= True
34 print " Loaded %d top-level actions." % len(source
._actions
)
40 pygame
.display
.set_caption(os
.path
.basename(filename
))
42 while active
and not newfile
:
45 for event
in pygame
.event
.get():
46 if event
.type == pygame
.QUIT
:
48 elif event
.type == pygame
.KEYDOWN
:
49 if event
.key
== pygame
.K_SPACE
:
51 elif event
.key
== pygame
.K_RIGHT
:
53 elif event
.key
== pygame
.K_PAGEUP
:
56 elif event
.key
== pygame
.K_PAGEDOWN
:
59 elif event
.key
== pygame
.K_RETURN
:
61 elif event
.key
== pygame
.K_s
:
62 actions
= [act([], 0.5) for act
in doc
.top
]
63 source
= bulletml
.Bullet(
64 x
=150, y
=150, target
=target
,
65 actions
=actions
, rank
=0.5)
66 source
.vanished
= True
68 target
.x
, target
.y
= pygame
.mouse
.get_pos()
76 for obj
in list(active
):
81 or not (-50 < obj
.x
< 350)
82 or not (-50 < obj
.y
< 350)):
84 elapsed
= time
.time() - start
88 seconds_per_bullet
= elapsed
/ count
89 bullets_per_second
= count
/ elapsed
90 print " Processing: %04d: %d bullets, %d active." % (
92 print " %g seconds per bullet (60Hz max: %g)." % (
93 seconds_per_bullet
, bullets_per_second
/ 60)
95 screen
.fill([0, 0, 0])
99 except AttributeError:
107 screen
.blit(bullet
, [x
, y
])
109 pygame
.display
.flip()
111 print " Finished: %04d: %d bullets." % (frames
, total
)
113 if __name__
== "__main__":