用户:
坚强的超能鸭nGCy查看:0 回复:0 评论:0 创建时间:2021-05-05T09:02:34
【作品展示】

【作品介绍】
这是一个躲避陨石的游戏,用鼠标控制。用鼠标左键点一下后,左键按下去是升高,松开是下降。一起用鼠标来穿越陨石吧!
【作品源代码】
from arcade import *
#定义个性化窗体
class MyWindow(Window):
def setup(self):
#背景
self.bg = Sprite("bg.png")
self.bg.left = 0
self.bg.bottom = 0
#战机
self.airship = Sprite("airship.png", scale=0.9)
self.airship.position = 60, 400
self.airship.change_y = 2
schedule(self.create_stone,2)
self.stone_list = SpriteList()
def create_stone(self,time):
#陨石
for i in range(9):
self.stone = Sprite("stone.png", scale=0.2)
self.stone.center_y = random.randint(0,600)
self.stone.center_x = random.randint(750, 800)
self.stone.change_x = random.randint(-5, -2)
self.stone_list.append(self.stone)
def on_mouse_release(self, x, y, button, modifiers):
self.airship.change_y = -2
def on_mouse_press(self, x, y, button, modifiers):
self.airship.change_y = 2
def is_hit(self):
hit = check_for_collision_with_list(self.airship,self.stone_list)
if hit:
self.airship.change_y = 0
for s in self.stone_list:
s.change_x = 0
unschedule(self.create_stone)
def on_draw(self):
start_render()
self.bg.draw()
self.airship.draw()
self.stone_list.draw()
def on_update(self,time):
self.is_hit()
self.airship.update()
self.stone_list.update()
w = MyWindow()
w.setup()
run()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn