[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Two questions regarding a simple space shooter
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Two questions regarding a simple space shooter
- From: "Kai Kuehne" <kai.kuehne@xxxxxxxxx>
- Date: Wed, 24 May 2006 10:52:24 +0200
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Wed, 24 May 2006 04:52:41 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=rtENc+tBiNbnZhy74iKvajK2y+i5+49q02+YyOFaiCPo/Hjs6/Cbe9zr8V2VwCVe8gjIM65/lJBT64oR22q9cff1On7U8Bk0KQsYg9XoeFlgQaz5aBnhQsrFxitM1YEbd42VnXxEb10n/lFksG5gk1bDI05I9MYO0Ws0/m9yt24=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
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