猫史档案馆


【Python作品分享】小鸟飞翔

用户:黄铭瑞黄铭瑞查看:0 回复:0 评论:0 创建时间:2023-04-21T17:28:09


【作品展示】

center_image

 

【作品介绍】

谁可以改进一下吗???

 

【作品源代码】

import pgzrun  
import random  
WIDTH = 1200   
HEIGHT = 700
background = Actor('a') 
bird = Actor('bird') 
bird.x = 50          
bird.y = HEIGHT/2
bar_up = Actor('bar_up')   
bar_up.x = 300             
bar_up.y = 0         
bar_down = Actor('bar_down')  
bar_down.x = 300                
bar_down.y = 600        
score = 0    
speed = 1   
def draw(): 
    background.draw()  
    bar_up.draw()       
    bar_down.draw()         
    bird.draw()       
    screen.draw.text(str(score), (30, 30), fontsize=50, color='Turquoise')
def update():
    global score,speed
    bird.y = bird.y + 1 
    bar_up.x = bar_up.x - speed  
    bar_down.x = bar_down.x - speed  
    if bar_up.x < 0:
        bar_up.x = WIDTH
        bar_down.x = WIDTH
        bar_up.y = random.randint(-200, 200) 
        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('游戏失败')
        score = 0
        speed = 1
        bird.x = 50          
        bird.y = HEIGHT/2    
        bar_up.x = WIDTH      
        bar_up.y = 0          
        bar_down.x = WIDTH    
        bar_down.y = 600    
def on_mouse_down(): 
    bird.y = bird.y - 100 
pgzrun.go()  

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页