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 red
= pygame
.Surface([3, 3])
33 green
= pygame
.Surface([3, 3])
34 green
.fill([0, 255, 0])
35 blue
= pygame
.Surface([3, 3])
36 blue
.fill([0, 0, 255])
37 clock
= pygame
.time
.Clock()
38 target
= bulletml
.Bullet()
40 bullets
= dict(red
=red
, green
=green
, blue
=blue
)
45 filename
= argv
[file_idx
% len(argv
)]
46 doc
= bulletml
.BulletML
.FromDocument(open(filename
, "rU"))
47 source
= bulletml
.Bullet
.FromDocument(
48 doc
, x
=150, y
=150, target
=target
, rank
=0.5)
50 active
= set([source
])
51 source
.vanished
= True
53 print " Loaded %d top-level actions." % len(source
._actions
)
59 pygame
.display
.set_caption(os
.path
.basename(filename
))
61 while active
and not newfile
:
64 for event
in pygame
.event
.get():
65 if event
.type == pygame
.QUIT
:
67 elif event
.type == pygame
.KEYDOWN
:
68 if event
.key
== pygame
.K_SPACE
:
70 elif event
.key
== pygame
.K_RIGHT
:
72 elif event
.key
== pygame
.K_PAGEUP
:
75 elif event
.key
== pygame
.K_PAGEDOWN
:
78 elif event
.key
== pygame
.K_RETURN
:
80 elif event
.key
== pygame
.K_s
:
81 actions
= [act([], 0.5) for act
in doc
.actions
]
82 source
= bulletml
.Bullet(
83 x
=150, y
=150, target
=target
,
84 actions
=actions
, rank
=0.5)
85 source
.vanished
= True
87 target
.x
, target
.y
= pygame
.mouse
.get_pos()
90 target
.y
= 300 - target
.y
93 lactive
= list(active
)
101 or not (-50 < obj
.x
< 350)
102 or not (-50 < obj
.y
< 350)):
105 collides_all(lactive
[0], lactive
)
106 elapsed
= time
.time() - start
109 if frames
% 100 == 0:
110 print " Processing: %04d: %d bullets, %d active." % (
111 frames
, total
, count
)
113 seconds_per_bullet
= elapsed
/ count
114 bullets_per_second
= count
/ elapsed
115 print " %g seconds per bullet (60Hz max: %g)." % (
116 seconds_per_bullet
, bullets_per_second
/ 60)
118 screen
.fill([0, 0, 0])
122 except AttributeError:
130 bullet
= bullets
.get(obj
.appearance
, red
)
131 screen
.blit(bullet
, [x
, 600 - y
])
133 pygame
.display
.flip()
135 print " Finished: %04d: %d bullets." % (frames
, total
)
137 if __name__
== "__main__":