You can use a sprite group as your bullet list container. [
http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.Group ] You
can use groups to iterate updates and drawing.
When space is pressed, check if conditions are right, and spawn. (
Does player have enough ammo, has weapon cooldown elapsed, etc )
psuedo code:
class Game():
def __init__(self, width=1024, height=768):
"""initialize game stuff"""
# ...
def loop(self):
"""main game loop"""
while not self.bDone:
self.handle_events()
# update, and draw()
def handle_events(self):
"""do regular events, and optionally pass copy to player"""
for event in pygame.event.get():
# if needed: copy events to player object
self.player.handle_event( event )
if event.type == pygame.QUIT: sys.exit()
elif event.type == KEYDOWN:
# exit on 'escape'
if (event.key == K_ESCAPE): self.bDone = True
# fire bullet, with cooldown time
elif event.key == K_SPACE:
if now - last_fired > player.cooldown:
bullet_spawn( player.loc )
--
Jake