So I'm making a clone of Super Mario Bros in pygame. As of now I am in the middle of making my keypoll function, to check all the keys that are currently being pressed. I am wondering which would be better:
Have the keypoll function modify marios attributes (ex. horizontal direction), then based on those, have mario decide which action he should be doing (ie. walk, run, jump, etc.) and call the function cooresponding to that action (ex. mario.moveHorz())
OR
Have the keypoll function call the function of the action he should be doing, and then the mario instance would decide what state he is currently in.
Here is some semi-pseudo code for the first one:
def doAction():
if mario.horzDir == 'r' or 'l':
mario.moveHorz()
elif mario.action == 'jump':
mario.jump()
def keyPoll(keys):
if keys[K_RIGHT]:
mario.horzDir = 'r'
elif keys[K_LEFT]:
mario.horzDir = 'l'
if keys[K_z]:
mario.action = 'jump'
Here is some more semi-pseudo code for the second one:
def keyPoll(keys):
if keys[K_RIGHT]:
mario.moveHorz('r')
elif keys[K_LEFT]:
mario.moveHorz('l')
if keys[K_z]:
mario.jump()
def setProperties():
if mario.x_vel > 0:
mario.horzDir = 'r'
elif mario.x_vel < 0:
mario.horzDir = 'l'
elif mario.y > ground:
mario.action = 'jump'
Both essentially accomplish the same thing, I just don't know which one is more correct.
Thanks!