[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Shooting an image
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Shooting an image
- From: "Jake b" <ninmonkeys@xxxxxxxxx>
- Date: Wed, 15 Oct 2008 13:20:11 -0500
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Wed, 15 Oct 2008 14:20:15 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=WJhHT+YA8UD9VPydeOk/c5Eu3zXo9VFFP6L2hTmajlw=; b=gqbhXbn5a7s+3CUqmDCIYG9AGzO0AvdVg8/yjk6o55HcOIrKWvgkBYO1mlOtp5CbBA E1hKAeTLtp/Iw2atp84RxApGxd0fS1xnzt8L6sKQUvC7yLn7uXizCdE5MAPNA1FJ0ErS wprgWrjPCSP24zOZHviQ3ch9ag1AigYMaHwjU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=nMsXaGHHfnWELKGzMXjppPolC2dpiHdGMeXVGxjznYHrTGvA5rDFOszqnGAjyR406t yv+taIHsXqOJx4IQ9cXgzC8e+/6wpW3YP8z3VicLb+Fewm+qKQoCbXlTl0JjFLUhYzH/ z3HkBcLE47zWsxqi6gpdK2YOllbT0pFUzUr8s=
- In-reply-to: <20081015004157.75A9A7BD4F@xxxxxxxxxxxxxxxxxxxxxxx>
- References: <20081015004157.75A9A7BD4F@xxxxxxxxxxxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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