[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Shooting an image



On Tue, 14 Oct 2008 02:49:11 +0800, "yanom @linuxmail.org"
<yanom@xxxxxxxxxxxxx> wrote:
> I have this chunk of code that's should make the player shoot a torpedo,
as
> long as their isn't another torpedo on the screen and the player has the
> space key down. Why dosen't this work:
> 
> 		
> 
>                 if key[K_SPACE] and torpedorect.top < -600:
> 			torpedorect.left = playerrect.left
> 			torpedorect.top = playerrect.top
> 		else:
> 			torpedorect = torpedorect.move(0,-7)##############

Could you please post more context, such as the specific error message or
what you see?
 
I surmise that you've got a "torpedo" object whose location is defined by
"torpedorect," and that you're getting "key" by calling "key =
pygame.keyboard.get_pressed()" to get a table of what keys are currently
being held down. You seem to be recycling the same torpedo by just changing
its location when it's re-fired rather than spawning a new one, which was
the topic of some jokes earlier about "bullet theology."

Not sure why you're doing it this way. Why should you have to hold the key
down to fire instead of just pressing it? And doesn't this code move the
torpedo to be right on top of the player, causing a collision if it's
checked for, and probably a moment of weirdly overlapping graphics?