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

Re: [pygame] Two questions regarding a simple space shooter



I just use a static background Surface.

http://dmsoft.cc/images/screenshot3.png

On Wed, 24 May 2006 10:52:24 +0200, "Kai Kuehne" <kai.kuehne@xxxxxxxxx>
said:
> Hi list. :)
> Wanted to start programming with pygame while making a pacman-clone.
> But that's to hard. Now I'm creating a simple scroll-shooter with a ship
> sitting on a starfield and some enemy ships.
> 
> I have a question regarding the design of this space shooter.
> 
> I'm pondering how to handle the stars. For now, I just use
> screen.set_at and "overdraw" the old star with the new one.
> 
> Dump question, i know.. but, is this commonly used this way?
> Or would you prefer to make a "Star" class. I thought, this would
> be - maybe - a little bit of overkill. :-)
> 
> Another question is how to handle the keyboard input.
> I wanted to control the ship by the left and right arrow keys and
> as long I press $the button, the ship shall fly into this direction. :-)
> 
> I have no code here, atm. But I try to remember what I've written:
> 
> The following code just do nothing (I thought this would do it):
> while 1:
> ....
>     pygame.event.pump()
>     keys = pygame.key.get_pressed()
>     if K_LEFT in keys:
>         ship.move_left()
> ...
> 
> When I print out 'keys', I see correct output since there is a 1 in the
> list.
> 
> 
> This code works, but I have to press the direction several
> times to make the ship fly (one press, one pixel):
> 
> while 1:
> ....
> for event in pygame.event.get():
>     if event.type == KEYDOWN:
>         if event.key == K_LEFT:
>             ship.move_left()
> ....
> 
> 
> Thanks for you help!
> Kai