猫史档案馆


【Python作品分享】Fly Bird【作品秀】

用户:洲RON2洲RON2查看:0 回复:1 评论:0 创建时间:2020-08-26T19:36:10


【作品展示】

center_image

 

【作品介绍】

初学,以Fly Bird游戏为灵感,

制作出的一个简易游戏。

鼠标点击即可

有一个喵ug,小鸟挂了之后,再按鼠标还会运行,望大神给出解决方法

 

【作品源代码】

import pgzrun #导入游戏库
import random #导入随机库
WIDTH = 350   #设置背景宽度
HEIGHT = 600  #设置背景高度
score = 0     #设置初始分数


background = Actor('background') #导入背景
bird = Actor('bird')             #导入小鸟
bar_up = Actor('zhuzishang2')    #导入上柱子
bar_down = Actor('zhuzixia2')    #导入下柱子
jieshu = Actor('jieshu')         #导入结束背景
bird.x = WIDTH/3                 #设置鸟的x坐标
bird.y = HEIGHT/2                #设置鸟的y坐标
bar_up.x = 300                   #设置上柱子的x坐标
bar_up.y = 30                    #设置上柱子的y坐标 
bar_down.x = 300                 #设置下柱子的x坐标
bar_down.y = 580                 #设置下柱子的y坐标
jieshu.x = WIDTH/2               #设置结束背景的x坐标
jieshu.y = HEIGHT/2              #设置结束背景的x坐标


def draw(): #定义画图
    background.draw() #绘制背景
    bird.draw()       #绘制小鸟
    bar_up.draw()     #绘制上柱子
    bar_down.draw()   #绘制下柱子
                            
                        #如果碰到边缘
#                       ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
    if bird.colliderect(bar_up) or bird.colliderect(bar_down) or bird.y < 0 or bird.y > HEIGHT:
        jieshu.draw()
        screen.draw.text(str(score), (30, 30), fontsize=50, color='blue')
    else:
        screen.draw.text(str(score), (30, 30), fontsize=50, color='blue')
        

def update():
    global score
    if bird.colliderect(bar_up) or bird.colliderect(bar_down) or bird.y < 0 or bird.y > HEIGHT:
        jieshu.draw()
        screen.draw.text(str(score), (30, 30), fontsize=50, color='blue')
    else:
        screen.draw.text(str(score), (30, 30), fontsize=50, color='blue')
        bird.y = bird.y + 1.7
        bar_up.x = bar_up.x - 2
        bar_down.x = bar_down.x - 2
    if bar_up.x < 0:
        score = score + 1
        bar_up.x = WIDTH
        bar_down.x = WIDTH
        bar_up.y = random.randint(-110,110)
        bar_down.y = bar_up.y + 555
        
def on_mouse_down():
    bird.y = bird.y - 50



pgzrun.go()

 

【提示】

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

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
会python的狸忍会python的狸忍

a……又是一个大佬呵呵emotion_doge

点赞0


评论