猫史档案馆


【Python作品分享】新的作品【作业帖】

用户:威武的阿尔法qorq威武的阿尔法qorq查看:0 回复:0 评论:0 创建时间:2021-10-10T16:52:58


【作品展示】

center_image

 

【作品介绍】

 

【作品源代码】

# 导入库中大部分功能
from arcade import *
from random import*
from arcade import color
# 子类继承父类Window
a = input("选择模式:1.解压 2.20命 3.5命 4.1命")


class MyWindow(Window):
    # 初始化方法,也叫构造函数
    def __init__(self):  # 该方法在类被实例化的时候会被自动调用一次
        super().__init__()  # 继承父类里面原有的初始化方法
        self.background_color = 119, 181, 254
        self.wl = SpriteList()
        self.e = PymunkPhysicsEngine((0, -900))
        self.r = Sprite("bed.png")
        self.r.position = 400, 100
        self.e.add_sprite(self.r, elasticity=0.8, body_type=self.e.STATIC)
        if a == 2:
            self.b = 20
        elif a == 3:
            self.b = 5
        elif a != 1:
            self.b = 1
    # 重写【鼠标按下】方法,当鼠标在arcade窗口中按下的时候,会自动调用

    def on_mouse_press(self, x, y, button, modifiers):
        self.w = Sprite("codemao.png")
        self.w.position = x, y
        self.e.add_sprite(self.w, elasticity=0.8)
        self.wl.append(self.w)
        Sound("duang.wav").play(10)
# 重写绘制方法,这个方法在程序执行run()指令后,会每秒被执行60次

    def check(self):
        for i in self.wl:
            if i.bottom < 0:
                self.wl.remove(i)
                if a != 1:
                    self.b -= 1

    def on_draw(self):
        start_render()  # 清屏并重新开始绘制
        self.wl.draw()
        self.r.draw()
        if len(self.wl) >= 20 and a != 1:
            draw_text("You win", 400, 400, color.BLUE, 60)
        if self.b <= 0 and a != 1:
            draw_text("You lose", 400, 400, color.BLUE, 60)
    # 重写更新方法,这个方法在程序执行run()指令后,会每秒被执行60次

    def on_update(self, time):
        self.e.step(1/60)
        self.check()


# 创建MyWindow类的实例,将会自动执行 __init__ 方法里面的代码
w = MyWindow()  # 实例化
# 运行(调用Window类中的方法)
run()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页