猫史档案馆


【Python作品分享】新的作品【求助帖】

用户:快到呙里来快到呙里来查看:0 回复:1 评论:0 创建时间:2023-08-09T12:37:29


【作品展示】

center_image

 

【作品介绍】

???

 

【作品源代码】

from pgzrun import *
import random

WIDTH = 1400
HEIGHT = 800
life = 5
bg = Actor("bg.png")
plat = Actor("plat.png", (50, 400))
shooter = Actor("shooter.png", (50, 400))
shield = Actor("shield5.png", (100, 400))
stone_list = []
bullet = Actor("bullet.png", (50, 400))
state = "封面"
over = Actor("over.png", (700, 400))
cover = Actor("cover1.png")
start = Actor("start1.png", (700, 600))


def draw():
    global state
    screen.clear()
    bg.draw()
    if state == "游戏中":
        plat.draw()
        bullet.draw()
        shooter.draw()
        shield.draw()
        for stone in stone_list:
            stone.draw()
    elif state == "结束":
        over.draw()
    elif state == "封面":
        cover.draw()
        start.draw()


# 创建陨石
def create():
    global state
    if state == "游戏中":
        num = random.randint(1, 4)
        pos = (random.randint(WIDTH-200, WIDTH), random.randint(0, HEIGHT))
        stone = Actor(f"stone{num}.png", pos)
        stone_list.append(stone)


# 定时器
clock.schedule_interval(create, 1)


def update():
    global life, state
    # 陨石运动
    for stone in stone_list:
        animate(stone, tween='decelerate', duration=6, pos=(200, stone.y))
    # 碰撞检测
    for stone in stone_list:
        if stone.colliderect(bullet):
            sounds.boom.play()
            stone_list.remove(stone)
        if shield.colliderect(stone):
            stone_list.remove(stone)
            life -= 1
            if life > 0:
                shield.image = f"shield{life}.png"
            else:
                state = "结束"


# 点击创建和发射子弹
def on_mouse_down(pos):
    global bullet, state
    if state == "封面":
        if start.collidepoint(pos):
            state = "游戏中"
    elif state == "游戏中":
        bullet = Actor("bullet.png", (50, 400))
        shooter.angle = shooter.angle_to(pos)
        bullet.angle = bullet.angle_to(pos)
        sounds.biu.play()
        animate(bullet, tween='linear', duration=0.3, pos=pos)


go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
玛卡巴卡126玛卡巴卡126

你的图片要跟这个代码文件放在同一个文件夹里面

点赞0


评论