用户:
内向的暴风雀_py5查看:1 回复:1 评论:1 创建时间:2021-09-19T08:40:48
【作品展示】

【作品介绍】
穿越行星光环:点击鼠标飞船就会往上飞,
松开鼠标飞船就会往下落,
控制飞船躲避陨石,
飞船碰到陨石游戏结束。
【作品源代码】
from arcade import *
import random
class My_window(Window):
def setup(self):
self.bg = Sprite('bg.png')
self.bg.left = 0
self.bg.bottom = 0
self.airship = Sprite('airship.png')
self.airship.position = 400, 300
self.stone_list = SpriteList()
schedule(self.create_stone, 2)
def create_stone(self, time):
for i in range(3):
self.stone = Sprite('stone.png', scale=0.15)
self.stone.center_x = random.randint(750, 800)
self.stone.center_y = random.randint(0, 600)
self.stone.change_x = -2
self.stone_list.append(self.stone)
def on_mouse_release(self, x, y, button, modifiers):
self.airship.change_y = -2
hit = check_for_collision_with_list(self.airship, self.stone_list)
if hit:
self.airship.change_y = 0
def on_mouse_press(self, x, y, button, modifiers):
self.airship.change_y = 2
hit = check_for_collision_with_list(self.airship, self.stone_list)
if hit:
self.airship.change_y = 0
def is_hit(self):
hit = check_for_collision_with_list(self.airship, self.stone_list)
if hit:
self.airship.change_y = 0
for i in self.stone_list:
i.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.airship.update()
self.stone_list.update()
self.is_hit()
w = My_window()
w.setup()
run()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn