用海龟画图模块制作的跳跃小游戏,方便学习此类游戏的基本原理
""" 最简滚动平台跳跃 """ from sprites import * width,height = 480,360 screen = Screen() screen.tracer(0,0) screen.bgcolor('dodger blue') screen.colormode(255) screen.setup(width,height) screen.title("最简滚动平台跳跃") screen.bgpic("bg.png") ground0 = Sprite(shape='square',visible=False) ground0.goto(-100,20) ground0.color('dodger blue') ground0.shapesize(2,2) ground0.show() ground1 = Sprite(shape='square',visible=False) ground1.goto(0,-150) ground1.color('cyan') ground1.shapesize(2,130) ground1.show() ground2 = Sprite(shape='square',visible=False) ground2.goto(50,-50) ground2.color('green') ground2.shapesize(1,4) ground2.show() ground3 = Sprite(shape='square',visible=False) ground3.goto(150,50) ground3.color('blue') ground3.shapesize(1,4) ground3.show() ground4 = Sprite(shape='square',visible=False) ground4.goto(350,0) ground4.color('brown') ground4.shapesize(1,4) ground4.show() ground5 = Sprite(shape='square',visible=False) ground5.penup() ground5.goto(550,20) ground5.color('magenta') ground5.shapesize(1,4) ground5.show() grounds = [ground0,ground1,ground2,ground3,ground4,ground5] akey = Key('a') # 新建a键实例 dkey = Key('d') # 新建d键实例 wkey = Key('w') # 新建w键实例 images1 = ['cat1.png','cat2.png'] # 朝右造型表 images2 = ['cat1_l.png','cat2_l.png'] # 朝左造型表 sp = AnimatedSprite(images1,images2) sp.up() # 抬笔 sp.dy = 0 # 垂直速度 sp.da = -0.02 # 加速度 screen.listen() ground_dx = 0 m1 = Mouse() 以下代码省略......
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)