for my project "python fighter framework" (http://www.pygame.org/project-fighter+framework-1550-2747.html), i handle keyup and keydown events separately and maintain a dictionary of pressed keys. then the game can properly handle multiple key presses (though subject to the evil keyboard problem).
also, i have a dict that maps keys to specific actions, so that reconfiguring the keys doesn't require modifying the source code. consider: BUTTON_HI_KICK = 1 BUTTON_MED_KICK = 2 BUTTON_LOW_KICK = 4 etc... # define the default keys. change the dict at runtime or with a config file. p1_key_def = { BUTTON_HI_KICK: K_e, BUTTON_MED_KICK: K_w, etc... } ------------------------------------------------------------------------------------------- then later.... if keys[p1_key_def[BUTTON_HI_KICK]]: do stuff if keys[p1_key_def[BUTTON_MED_KICK]]: do stuff if you have a background that doesn't change often, then i would say that 99% of the time you are better off with the "dirty rect" method of drawing. I use that for my game and it works pretty well. On Fri, Nov 26, 2010 at 2:18 AM, Nathan BIAGINI <nathan.o...@gmail.com> wrote: > Ok thanks but i saw that psyco do not supports 2.7 release of python so i > think i ll not try it for the moment. > > Ok so thanks everybody be sure to see me again on this mail list, i ll of > course do my best to read doc to solve my problem the best i can, it s > always a pretty good exercice for my english haha > > 2010/11/24 Kris Schnee <ksch...@xepher.net> >> >> On 2010.11.24 1:53 PM, Nathan BIAGINI wrote: >>> >>> Ok thanks to reply so fast :) yeah of course, it seems obvious now but i >>> didn't know there is a way to manage keyboard state without the common >>> event loop. >>> I ll use this created topic to ask something else about the optimization >>> of a game written with pygame. Restrict frames per second with >>> clock.tick(xx) and only update dirty rects (in case of static >>> background) is enough for a quite "simple" 2D game? Or there re more >>> optimizations to do? I don't try to reach perfect performance, only want >>> to make my faster as possible and less CPU consuming. >> >> One other thing to try is an acceleration system. >> "Psyco" uses a compiler to speed up a Python program very easily. See >> http://psyco.sourceforge.net/ . All you need to do after installing it is >> add the code "import psyco ; psyco.full()". >> >> "Boost" ( http://beta.boost.org/doc/libs/1_45_0/libs/python/doc/index.html >> ) lets you write code in the C language and access that from Python. I've >> not tried that. > >