I'm taking python classes. I've asked for hints about this in our forums but with no luck. I think my implementation is very bad. I'm very new at this, so bear with me, even with the way I ask the question.
The question above is what I am told I need to do. I've tried but with no luck, so I've come here for help.
Ultimately, I am trying to get my key handlers to respond to my keypresses. I've done this previously, but we were not yet working with classes. That's where the snag is. I'm supposed to implement class methods/variables to make them work, not use new variables or new globals.
e.g.
class SuchAndSuch:
def __init__(self, pos, vel, ang, ang_vel, image, info, sound = None):
self.pos = [pos[0],pos[1]]
self.vel = [vel[0],vel[1]]
self.angle = ang
self.angle_vel = ang_vel
self.image = image
def update(self):
# this is where all the actual movement and rotation should happen
...
The handler below is outside the SuchAndSuch class:
def keydown(key):
# need up left down right buttons
if key == simplegui.KEY_MAP["up"]:
# i'm supposed to just call methods here to make the keys respond???
...
So, all updates are supposed to be happening in the SuchAndSuch class and only calls for this updates are supposed to be inside my keyhandler.
Can someone please give me an example on what they mean when they say this? All the variables (or ideas given in forums) I try to implement in my key handlers error as "undefined".