首页 > 其他分享 >bird

bird

时间:2023-12-27 10:15:24浏览次数:32  
标签:Pipeline self Bird bird pygame font screen

import pygame
import sys
import random 
class Bird(object):
    def __init__(self):
        self.birdRect = pygame.Rect(65, 50, 50, 50)
        self.birdStatus = [pygame.image.load("1.png"),
                           pygame.image.load("2.png"),
                           pygame.image.load("dead.png")]
        self.status = 0
        self.birdX = 120
        self.birdY = 350
        self.jump = False
        self.jumpSpeed = 10
        self.gravity = 5
        self.dead = False
    def birdUpdate(self):
        if self.jump:
            self.jumpSpeed -= 1
            self.birdY -= self.jumpSpeed
        else:
            self.gravity += 0.2
            self.birdY += self.gravity
        self.birdRect[1] = self.birdY
class Pipeline(object):
    def __init__(self):
        self.wallx = 400
        self.pineUp = pygame.image.load("top.png")
        self.pineDown = pygame.image.load("bottom.png")
    def updatePipeline(self):
        self.wallx -= 5
        if self.wallx < -80:
            global score
            score += 1
            self.wallx = 400
            global rom
            rom=int(round(random.random() * 80, 0))
def createMap():
    screen.fill((255, 255, 255))
    screen.blit(background, (0, 0))
    screen.blit(Pipeline.pineUp, (Pipeline.wallx, -300+rom))
    screen.blit(Pipeline.pineDown, (Pipeline.wallx, 500+rom))
    Pipeline.updatePipeline()
    if Bird.dead:
        Bird.status = 2
    elif Bird.jump:
        Bird.status = 1
    screen.blit(Bird.birdStatus[Bird.status], (Bird.birdX, Bird.birdY))
    Bird.birdUpdate()
    screen.blit(font.render('Score:' + str(score), -1, (255, 255, 255)), (100, 50))
    pygame.display.update()
def checkDead():
    upRect = pygame.Rect(Pipeline.wallx, -300,
                         Pipeline.pineUp.get_width() - 10,
                         Pipeline.pineUp.get_height())
    downRect = pygame.Rect(Pipeline.wallx, 500,
                           Pipeline.pineDown.get_width() - 10,
                           Pipeline.pineDown.get_height())
    if upRect.colliderect(Bird.birdRect) or downRect.colliderect(Bird.birdRect):
        Bird.dead = True
    if not 0 < Bird.birdRect[1] < height:
        Bird.dead = True
        return True
    else:
        return False
def getResutl():
    final_text1 = "Game Over"
    final_text2 = "Your final score is:  " + str(score)
    ft1_font = pygame.font.SysFont("Arial", 70)
    ft1_surf = font.render(final_text1, 1, (242, 3, 36))
    ft2_font = pygame.font.SysFont("Arial", 50)
    ft2_surf = font.render(final_text2, 1, (253, 177, 6))
    screen.blit(ft1_surf, [screen.get_width() / 2 - ft1_surf.get_width() / 2, 100])
    screen.blit(ft2_surf, [screen.get_width() / 2 - ft2_surf.get_width() / 2, 200])
    pygame.display.flip()
if __name__ == '__main__':
    pygame.init()
    pygame.font.init()
    font = pygame.font.SysFont("Arial", 50)
    size = width, height = 400, 650
    screen = pygame.display.set_mode(size)
    clock = pygame.time.Clock()
    Pipeline = Pipeline()
    Bird = Bird()
    score = 0
    rom=0
    while True:
        clock.tick(40)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if (event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN) and not Bird.dead:
                Bird.jump = True
                Bird.gravity = 5
                Bird.jumpSpeed = 10
        background = pygame.image.load("background.png")
        if checkDead():
            getResutl()
        else:
            createMap()
    pygame.quit()
 

 

标签:Pipeline,self,Bird,bird,pygame,font,screen
From: https://www.cnblogs.com/guowenye/p/17929857.html

相关文章

  • 开发Flappy Bird游戏
    #-*-coding:utf-8-*-"""CreatedonSatDec2316:26:062023@author:86135"""importpygameimportsysimportrandomclassBird(object):"""定义一个鸟类"""def__init__(self):......
  • FirebirdSql.Data.FirebirdClient.FbDataAdapter的bug吗
    在连接Firebird4数据库时,使用以下: FbDataAdapterda=newFbDataAdapter(sql,this.cnstring); DataTabledt=newDataTable(); da.Fill(dt); returndt;在一直的相像中,FbDataAdapter在接收到连接字符串时,会自动创建一个Connection并Open使用,用完再Close,即不需......
  • flappy bird
    importpygameimportsysimportrandom#素材参考地址:https://www.aigei.com/s?q=flappy+bird&type=2dclassBird(object):"""定义一个鸟类"""def__init__(self):"""定义初始化方法"""self.birdRect......
  • python——小游戏(ball,bird)
      ball #-*-coding:utf-8-*-"""CreatedonWedDec1309:19:382023@author:kabuqinuo"""importsys#导入sys模块importpygame#导入pygame模块pygame.init()#初始化pygamesize=width,height=640,480#设置窗......
  • NetBird 开源网络管理平台 部署安装
    NetBird简介NetBird是一个建立在WireGuard之上的开源网络管理平台,它允许计算机、设备和服务器通过快速加密隧道直接连接,无需配置或中央V*N服务器。它使专用网络变得安全,并创建了一个专用网络,在没有手动配置和专家的情况下应用安全实践。NetBird网络普遍适用于云、本地、边缘和容器......
  • 自建Netbird中续组网
    介绍引用:https://docs.netbird.io/selfhosted/selfhosted-quickstartNetBird开源,可以在服务器上自托管。它依赖于由NetBirdAuthorsManagementService、ManagementUIDashboard、SignalService、第三方开源STUN/TURN服务Coturn和身份提供程序开发的组件。实验环......
  • 解密Prompt系列15. LLM Agent之数据库应用设计:DIN & C3 & SQL-Palm & BIRD
    上一章我们主要讲搜索引擎和LLM的应用设计,这一章我们来唠唠大模型和DB数据库之间的交互方案。有很多数据平台已经接入,可以先去玩玩再来看下面的实现方案,推荐sqltranslate:简单,文本到SQL,SQL到文本双向翻译,新手体验ai2sql:功能更全,包括语法检查,格式化等chat2query:可处理复杂query......
  • 关闭Thunderbird的自动换行
    参考https://blog.csdn.net/cuma2369/article/details/107667731https://support.mozilla.org/en-US/questions/1307935点击设置->配置编辑器:然后搜索mailnews.wraplength,把值修改为0:......
  • k8s集群在扩容的是某个节点出现 Error querying BIRD: unable to connect to BIRDv4 s
    k8s集群在扩容的是某个节点出现ErrorqueryingBIRD:unabletoconnecttoBIRDv4socket1、问题背景:原因是因为新扩容的机器在扩容之前安装过docker切和当前的版本相差较大:在k8s扩容的时候扩容完发现calico异常,describe查看事件后发现报错如下:发现Kubernetes容器集群中有......
  • BIRD:划定text-to-sql的基准
    Abstarct存在的问题:在Text-to-SQL问题中,之前的基准(Spider和WikiSQL)聚焦于数据库中较少的行,学术研究和现实应用的距离较大。BIRD主要重视dirtycontent,externalknowledge和SQL的效率三方面。对比了human和ChatGPT生成语句的精度,发现chatgpt和人类仍存在很大的差距。1.Introd......