7c262b02ba3d0ce9bf01e9d4bea0be7507a67213
10 import bulletml
.bulletyaml
11 from bulletml
.collision
import collides_all
27 raise SystemExit("Usage: %s filename ..." % sys
.argv
[0])
30 screen
= pygame
.display
.set_mode([600, 600], pygame
.DOUBLEBUF
)
31 bullet
= pygame
.Surface([3, 3])
32 bullet
.fill([255, 0, 0])
33 clock
= pygame
.time
.Clock()
34 target
= bulletml
.Bullet()
39 filename
= argv
[file_idx
% len(argv
)]
40 doc
= bulletml
.BulletML
.FromDocument(open(filename
, "rU"))
41 source
= bulletml
.Bullet
.FromDocument(
42 doc
, x
=150, y
=150, target
=target
, rank
=0.5)
44 active
= set([source
])
45 source
.vanished
= True
47 print " Loaded %d top-level actions." % len(source
._actions
)
53 pygame
.display
.set_caption(os
.path
.basename(filename
))
55 while active
and not newfile
:
58 for event
in pygame
.event
.get():
59 if event
.type == pygame
.QUIT
:
61 elif event
.type == pygame
.KEYDOWN
:
62 if event
.key
== pygame
.K_SPACE
:
64 elif event
.key
== pygame
.K_RIGHT
:
66 elif event
.key
== pygame
.K_PAGEUP
:
69 elif event
.key
== pygame
.K_PAGEDOWN
:
72 elif event
.key
== pygame
.K_RETURN
:
74 elif event
.key
== pygame
.K_s
:
75 actions
= [act([], 0.5) for act
in doc
.actions
]
76 source
= bulletml
.Bullet(
77 x
=150, y
=150, target
=target
,
78 actions
=actions
, rank
=0.5)
79 source
.vanished
= True
81 target
.x
, target
.y
= pygame
.mouse
.get_pos()
86 lactive
= list(active
)
94 or not (-50 < obj
.x
< 350)
95 or not (-50 < obj
.y
< 350)):
98 collides_all(lactive
[0], lactive
)
99 elapsed
= time
.time() - start
102 if frames
% 100 == 0:
103 print " Processing: %04d: %d bullets, %d active." % (
104 frames
, total
, count
)
106 seconds_per_bullet
= elapsed
/ count
107 bullets_per_second
= count
/ elapsed
108 print " %g seconds per bullet (60Hz max: %g)." % (
109 seconds_per_bullet
, bullets_per_second
/ 60)
111 screen
.fill([0, 0, 0])
115 except AttributeError:
123 screen
.blit(bullet
, [x
, y
])
125 pygame
.display
.flip()
127 print " Finished: %04d: %d bullets." % (frames
, total
)
129 if __name__
== "__main__":