猫史档案馆


Fly bird

用户:林733241林733241查看:0 回复:0 评论:0 创建时间:2021-12-25T13:06:21


图片和PY文件放一起center_imagecenter_imagecenter_imagecenter_image

import pgzrun
import random
import time

WIDTH = 288
HEIGHT = 512

backgroud = Actor('bg')

bird = Actor('bird1')
bird.x = 50
bird.y = HEIGHT/2

pipe_down = Actor('pipe_up')
pipe_down.x =300
pipe_down.y = 0
pipe_up = Actor('pipe_down')
pipe_up.x = 300
pipe_up.y = 600

score = 0
is_out = False
speed = 1
startTime = time.time()
newTime = 0
def draw():
    if is_out == False:
        backgroud.draw()
        pipe_down.draw()
        pipe_up.draw()
        bird.draw()
        screen.draw.text(str(score),(30,30),fontsize = 50,color = 'blue')
        newTime = int(time.time() - startTime)
        screen.draw.text("Time:"+str(newTime),(150,30),fontsize = 50,color = 'blue')
    else: 
        screen.draw.text("GAWE OVER",(0,HEIGHT/2),fontsize = 65,color = 'blue')

def update():
    global score,speed,is_out,HEIGHT,WIDTH
    if is_out == False:
        bird.y += 2 
        pipe_up.x -= speed
        pipe_down.x -= speed
        if pipe_up.x < 0:
            pipe_down.x=WIDTH
            pipe_up.x=WIDTH
            pipe_up.y = random.randint(400,600)
            pipe_down.y = pipe_up.y - 600
            score += 1
            if (score % 5 == 0):
                speed +=1
    if bird.colliderect(pipe_up) or bird.colliderect(pipe_down) or bird.y < 0 or bird.y > HEIGHT:
        is_out = True
def on_key_down():
    if is_out == False:
        bird.y -= 50
pgzrun.go()
        


回复

上一页1 页 / 共 0下一页