我正在上python课程.我已经在论坛上询问过这方面的提示,但没有运气.我认为我的实施非常糟糕.我对此非常陌生,所以请耐心等待,即使我提出问题的方式.
上面的问题是我被告知需要做的事情.我试过但没有运气,所以我来这里寻求帮助.
最终,我试图让我的主要处理程序回应我的按键.我以前做过这个,但我们还没有上课.这就是障碍所在.我应该实现类方法/变量来使它们工作,而不是使用新变量或新的全局变量.
例如
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
...
Run Code Online (Sandbox Code Playgroud)
下面的处理程序在SuchAndSuch类之外:
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???
...
Run Code Online (Sandbox Code Playgroud)
因此,所有更新都应该发生在SuchAndSuch类中,并且 …