Hi, I'm using your pygamge_function with my High School Computer Science students in Chile, and I want to share with you this idea... I take your keyPressed function and add a simple modification to add multiple keys detecting (for jumping with direction for example, or move in diagonal):
KeyCheck must be a list with the keys to check
def keysPressed(keyCheck):
global keydict
pygame.event.clear()
keys = pygame.key.get_pressed()
pressedKeys = 0
if sum(keys) > 0:
for key in keyCheck:
if key == "" or keys[keydict[key.lower()]]:
pressedKeys += 1
if pressedKeys == len(keyCheck):
return True
return False
When we use this, in the game loop, we must check the multiple keys pressed actions first, before of the single keystroke in the "if" that controls the movement.
Hi, I'm using your pygamge_function with my High School Computer Science students in Chile, and I want to share with you this idea... I take your keyPressed function and add a simple modification to add multiple keys detecting (for jumping with direction for example, or move in diagonal):
KeyCheck must be a list with the keys to check
def keysPressed(keyCheck):
global keydict
pygame.event.clear()
keys = pygame.key.get_pressed()
pressedKeys = 0
if sum(keys) > 0:
for key in keyCheck:
if key == "" or keys[keydict[key.lower()]]:
pressedKeys += 1
if pressedKeys == len(keyCheck):
return True
return False
When we use this, in the game loop, we must check the multiple keys pressed actions first, before of the single keystroke in the "if" that controls the movement.