猫史档案馆


【Python作品分享】新的作品

用户:彻夜星空彻夜星空查看:0 回复:0 评论:0 创建时间:2023-12-03T12:29:58


【作品展示】

center_image

 

【作品介绍】

家人们看一看有什么错误,打在评论区里(原创:技术喵)

 

【作品源代码】

from pgzrun import *
import random

backgroud = Actor('bg')

WIDTH = backgroud.width
HEIGHT = backgroud.height

GRAVITY = 0.3

FLAP_STRENGTH = 0.5

GAP = (WIDTH / 2.5)

SPEED = 3

bird = Actor('cat', (WIDTH / 4,200))
bird.dead = False
bird.score = 0
bird.vy = 0

pipe_top = Actor('pite.top', (WIDTH,0))
bottom = Actor('pite.bottom', (WIDTH,HEIGHT-50))

def reset_pipes():

    pipe_gap_y = random.randint(-100,200)
    pipe_top.pos = (WIDTH, pipe_gap_y)
    pipe_bottom.pos = (WIDTH, ((pipe_top.height + pipe_top.pos[1]) + GAP))

def update_pipes():
    pipe_top.x -= SPEED
    pipe_bottom.x -= SPEED
    if (pipe_top.x < 0):
        reset_pipes()
        if not (bird.dead):
            bird.score += 1

def update_bird():

    uy = bird.vy
    bird.vy += GRAVITY
    bird.y += ((uy + bird.vy) / 2)
    bird.x = (WIDTH / 4)
    if (bird.colliderect(pipe_top) or bird.colliderect(pipe_bottom)):
        bird.dead = True
    if not (0 < (bird.y < HEIGHT)):
        bird.y = 200
        bird.dead = False
        bird.score = 0
        bird.vy = 0
        reset_pipes()

def on_key_up(key):
    if not (bird.dead):
        bird.vy = -FLAP_STRENGTH

def update():
    update_pipes()
    update_bird()

def draw():
    screen.clear()
    backgroud.draw()
    pipe_top.draw()
    pipe_bottom.draw()
    bird.draw()
    screen.draw.text(str(bird.score),(WIDTH * 0.5,100),color = "white",fontsize=70)

go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页