猫史档案馆


【Python作品分享】飞翔的小鸟

用户:真诚的皮皮蟹SdR_真诚的皮皮蟹SdR_查看:1 回复:1 评论:1 创建时间:2022-07-14T13:27:24


【作品展示】

center_image

 

【作品介绍】

做的真好!

 

【作品源代码】

import pgzrun
import random


WIDTH = 350
HEIGHT = 600
background = Actor("background")
bar_up = Actor("bar_up")
bar_down = Actor("bar_up")
bird = Actor("bird")
bar_up.x = 300
bar_up.y = 600
bar_down.x = 300
bar_down.y = 100
bird.x = 50
bird.y = HEIGHT/2
score = 0
speed = 1


def draw():

    background.draw()
    bird.draw()
    bar_down.draw()
    bar_up.draw()
    screen.draw.text(str(score), (30, 30), fontsize=50, color="green")


def update():
    global score, speed
    bird.y = bird.y + 2
    bar_up.x = bar_up.x - 2
    bar_down.x = bar_down.x - 2
    if (bar_up.x < 0):
        bar_up.x = WIDTH
        bar_down.x = WIDTH
        bar_up.y = random.randint(-200, 50)
        bar_down.y = 600 + bar_up.y
        score = score + 1
        if score % 5 == 0:
            speed = speed + 1
    if (bird.colliderect(bar_up) or bird.colliderect(bar_down) or bird.y < 0 or bird.y > HEIGHT):
        print('游戏失败')
        bar_up.x = 300
        bar_up.y = 600
        bar_down.x = 300
        bar_down.y = 100
        bird.x = 50
        bird.y = HEIGHT/2
        score = 0
        speed = 1


def on_mouse_down():
    bird.y = bird.y - 50


pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
忠诚的独角蛛2bTB忠诚的独角蛛2bTB

第三方库我下了,第7行报错

点赞0


评论