I want to make a class "Player" that has a list containing the inputs I want as strings, like ['w','a','s','d']
,
and using the pygame module to get all the pressed keys through pygame.key.get_pressed()
, find a way to generalize the conditions:
keys_pressed[pygame.K_w]
|keys_pressed[pygame.K_a]
|keys_pressed[pygame.K_s]
|keys_pressed[pygame.K_d]
,using the list of keys from the Player class.
pseudo-code:
player.list = ['w','a','s','d']
keys_pressed = pygame.key.get_pressed()
if keys_pressed[pygame.K_<player.list[0]>]:move up
if keys_pressed[pygame.K_<player.list[1]>]:move left
if keys_pressed[pygame.K_<player.list[2]>]:move down
if keys_pressed[pygame.K_<player.list[3]>]:move right
Is there a way I can implement this? If so, what's the right way to concatenate the "K_" + list[i] so that pygame accepts it?