Class 实施“重力”效应
目前,我正在尝试制作一个游戏,用一匹马跳过障碍物,我目前正在制作马的动画。我可以让马跳起来,但我仍然无法实现重力,也无法让马在跳跃后回到地面 以下是我当前的代码:Class 实施“重力”效应,class,sprite,gravity,pyglet,Class,Sprite,Gravity,Pyglet,目前,我正在尝试制作一个游戏,用一匹马跳过障碍物,我目前正在制作马的动画。我可以让马跳起来,但我仍然无法实现重力,也无法让马在跳跃后回到地面 以下是我当前的代码: import pyglet import time # background_sound = pyglet.media.load( # 'Documents/Leave The Night On.mp3', # streaming=False) class horse(pyglet.sprit
import pyglet
import time
# background_sound = pyglet.media.load(
# 'Documents/Leave The Night On.mp3',
# streaming=False)
class horse(pyglet.sprite.Sprite):
def __init__(self, batch):
self._img_main = pyglet.image.load("sihorseav.png")
self.img_right1 = pyglet.image.load("sihorseav.png")
self.img_right2 = pyglet.image.load("sihorseav.png")
self.anim_right = pyglet.image.Animation.from_image_sequence([self.img_right1, self.img_right2], 0.5, True)
pyglet.sprite.Sprite.__init__(self, self._img_main)
self.time = 0
def forward_movement(self, flag=True):
if keymap[pyglet.window.key.UP]:
self.horse.time = time.time()
self.horse.jump()
def jump(self):
print time.time()-self.time
self.y -= -200 +20**(time.time()-self.time+.2)
class Window(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.batch = pyglet.graphics.Batch()
self.label = pyglet.text.Label(text="Score: 0", x=850, y=650, batch=self.batch)
image = pyglet.resource.image('sibackground.jpg')
self.background = pyglet.sprite.Sprite(image, batch=self.batch)
self.player = horse(batch = self.batch)
self.keys_held = []
def on_key_press(self, symbol, modifiers):
self.keys_held.append(symbol)
if symbol == pyglet.window.key.UP:
self.player.time=time.time()
self.player.jump()
def on_draw(self):
self.clear()
self.batch.draw()
self.player.draw()
self.label.draw()
def main():
window = Window(width=960, height=700, caption='Pyglet')
pyglet.app.run()
if __name__ == '__main__':
main()
从技术上讲,你的问题标题是错误的。我会改变名字以反映你的真实问题。