[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[pygame] solving a few event problems



Okay, these aren't really problems per se, but I'm looking for better ways to do each of the following, and was hoping someone had run into this before:

1) Is there an easy way to initialise, say, all joysticks at once? I mean, sure, I could do:

  totaljoy = pygame.joystick.get_count()
  if totaljoy > 0:
    joy1 = pygame.joystick.Joystick(1)
    joy1.init()
  if totaljoy > 1:
    joy2 = pygame.joystick.Joystick(2)
    joy2.init()
  ........

but it sure as hell would be nice if I could create a list of joysticks or something like that and not have to worry about doing that for every single joystick, so I could just do something like:

  for i in range( pygame.joystick.get_count() )
    j.append( pygame.joystick.Joystick(i) )
    j[len(j)-1].init()

I realise this might not be valid code, but hopefully you can see what I'm trying to do. The idea is that there might be up to 8 or more controllers plugged into this box, and I don't want to initialise them individually.

2) I'm looking for an easy way to save events, like with a keymapper. For instance, think a controls configuration menu in a game, going through and customising your controls, where you click on a certain description of a control "Move Up" and then press the up key. Sure, I could save event.key's value to a file or something. But what if "move up" could be a keypress OR a buttonpress? I don't want to say:

  if ev.type == KEYDOWN:
    savedevent = "KEY "+repr(ev.key)
  if ev.type == JOYBUTTONDOWN:
    savedevent = "JOY "+repr(ev.button)
  ....

I'd like a simple way to just say:

  if (ev.type == KEYDOWN) or (ev.type == JOYBUTTONDOWN)
    savedevent = event

then I could load the event in:

  evmoveup = mainconfig.load("moveup")

and pull it straight from a configuration file without having to think about it.

Okay, enough hot air. I'll go back to coding now =]

B
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org