[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Two questions regarding a simple space shooter
Two comments:
1) Instead of:
if event.key == K_LEFT:
it may be better to do:
keymap = [K_LEFT, K_RIGHT, K_SPACE] # Put this in initialization
for event in
pygame.event.get():
if event.type == KEYDOWN:
if event.key == keymap[0]: # Left
ship.changeSpeed(-1)
if event.key == keymap[1]: # Right
ship.changeSpeed(+1)
You could also change keymap to a Dictionary. Anyway, this lets you pretty easily remap the keys, which I think is a good standard to support.
2) Instead of just changing speed, I actually use a function startUp, startDown, startLeft, startRight, as there may be occasions where I'll need to do things like set the current animation loop, call other functions, etc. and I want to hide this functionality in my class, or maybe overload it at runtime.
Looking forward to seeing your successful project,
--
Andrew Ulysses Baker
"failrate"