猫史档案馆


【Python作品分享】是凤凰蛋就达到一万分

用户:PSHH83gCPSHH83gC查看:0 回复:3 评论:0 创建时间:2023-01-15T12:10:03


【作品展示】

center_image

 

【作品介绍】

是凤凰蛋就达到一万分

 

【作品源代码】

import pgzrun
import random

WIDTH = 500
HEIGHT = 700

dudu = Actor('嘟嘟')

score = 0

music.play('背景音乐')

# direction表示踏板2当前运动的方向和速度, 初始值为3
direction = 3

bricks = []
for i in range(5):
    n = random.randint(1, 4)
    b = Actor('踏板' + str(n))
    min_x = b.width // 2
    max_x = WIDTH - b.width // 2
    b.x = random.randint(min_x, max_x)
    b.y = 140 * (i + 1)
    bricks.append(b)
    if i == 2:
        dudu.x = b.x
        dudu.bottom = b.top
        b.image = '踏板1'

def draw():
    global score
    screen.blit('背景', [0, 0])
    dudu.draw()
    for brick in bricks:
        brick.draw()
    screen.draw.text(str(score), (20, 10))

def update():
    global score, direction
    if dudu.image == '嘟嘟':
        score += 1
        on_brick = 0
        for b in bricks:
            b.y -= 3
            if b.image == '踏板2':
                b.x += direction
                if b.right >= WIDTH:
                    direction = -3
                elif b.left <= 0:
                    direction = 3
            if b.y < 0:
                n = random.randint(1, 4)
                b.image = '踏板' + str(n)
                b.y = HEIGHT
                min_x = b.width // 2
                max_x = WIDTH - b.width // 2
                b.x = random.randint(min_x, max_x)
        for b in bricks:
            if dudu.colliderect(b) and dudu.bottom < b.bottom:
                dudu.bottom = b.top
                on_brick = 1
                if b.image == '踏板4':
                    dudu.image = '嘟嘟哭'
                # 当嘟嘟踩在踏板2上时,跟随踏板一起左右移动
                if b.image == '踏板2':
                    dudu.x += direction

        if on_brick == 0:
            dudu.y += 8
        if dudu.bottom > HEIGHT:
            dudu.image = '嘟嘟哭'
        if keyboard.left:
            if dudu.left > 0:
                dudu.x -= 5
        if keyboard.right:
            if dudu.right < WIDTH:
                dudu.x += 5
    if dudu.image == '嘟嘟哭':
        music.stop()

def on_key_down(key):
    if key == keys.SPACE and dudu.image == '嘟嘟哭':
        global score, bricks
        music.play('背景音乐')
        dudu.image = '嘟嘟'
        bricks = []
        score = 0
        for i in range(5):
            n = random.randint(1, 4)
            b = Actor('踏板' + str(n))
            min_x = b.width // 2
            max_x = WIDTH - b.width // 2
            b.x = random.randint(min_x, max_x)
            b.y = 140 * (i + 1)
            bricks.append(b)
            if i == 2:
                b.image = '踏板1'
                dudu.x = b.x
                dudu.bottom = b.top


pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
超级无敌编程大神超级无敌编程大神

猿编程的代码??!

点赞0


评论


晴天宝r晴天宝r

怎么又是核桃编程 而且我现在就在上center_image

点赞0


评论


白给坤白给坤

额额

点赞0


评论