python文字游戏源代码_python 像素小鸟小游戏源码(flappybird)

news/2025/2/27 10:34:52

【实例简介】

像素小鸟这个简单的游戏于2014年在网络上爆红,游戏上线一段时间内appleStore上的下载量一度达到5000万次,风靡一时

【实例截图】

51162023925d34f664e0acdaba7c7e15.gif

【核心代码】

from Class import *

# 检查停止事件

def checkEvent():

time.sleep(0.1)

press = pygame.key.get_pressed() # 检测按下ESC键退出游戏

if (press[K_ESCAPE]):

sys.exit()

# elif press[K_SPACE]:

# return "buttonDownKSpace"

for event in pygame.event.get():

if event.type == pygame.QUIT: # 检测单击X,退出游戏

sys.exit()

elif event.type == MOUSEBUTTONDOWN: # 获取鼠标单击位置

buttonDownPos = event.pos

return ("buttonDownPos", buttonDownPos)

elif event.type == KEYDOWN and event.key == K_SPACE: # 检测是否按下SPACE键

# if event.key == K_SPACE:

return "buttonDownK_SPACE"

# 三张夜晚背景和三张白天背景交替出现,向左移动

def movingBackground(bgListNight, bgListDay):

for i in range(3):

bgListNight[i].display()

bgListNight[i].moveLeft()

for i in range(3):

bgListDay[i].display()

bgListDay[i].moveLeft()

def movingPipe(pipeList):

for i in pipeList:

i[0].display()

i[0].moveLeft()

i[1].display()

i[1].moveLeft()

def birdAnimationAlive(pipeList, birdList, isButtonDownK_SPACE): # 自由下落的鸟

deltaTime = time.time()

frameIndex = (int)(deltaTime / (1.0 / frameCountPerSeconds))

if isButtonDownK_SPACE == "buttonDownK_SPACE":

for i in range(3):

birdList[i].moveUp()

else:

for i in range(3):

birdList[i].moveDown()

if frameIndex % 3 == 0:

birdList[0].display()

if frameIndex % 3 == 1:

birdList[1].display()

if frameIndex % 3 == 2:

birdList[2].display()

for i in pipeList:

if birdList[0].rect.colliderect(i[0].rect) or birdList[0].rect.colliderect(i[1].rect):

return "birdHasDeath"

if birdList[0].rect.y >= 512:

return "birdHasDeath"

else:

return "birdIsAlive"

def birdAnimationDeath(birdList):

deltaTime = time.time()

frameIndex = (int)(deltaTime / (1.0 / frameCountPerSeconds))

if frameIndex % 3 == 0:

birdList[0].display()

if frameIndex % 3 == 1:

birdList[1].display()

if frameIndex % 3 == 2:

birdList[2].display()

for i in range(3):

birdList[i].deathDown()

def showScore(moveDistance):

score = moveDistance // 220

if score <= 0:

score = 0

if score >= 6:

score = 6

screen.blit(good, (30, 200))

getScoreStart = font.render(str(score), True, (255, 0, 0))

screen.blit(getScoreStart, (260, 0))


http://www.niftyadmin.cn/n/3879794.html

相关文章

转贴存储过程分页的例子

CREATE PROCEDURE pageTest --用于翻页的测试--需要把排序字段放在第一列 ( FirstID nvarchar(20)null, --当前页面里的第一条记录的排序字段的值 LastID nvarchar(20)null, --当前页面里的最后一条记录的排序字段的值 isNext bitnull, --true 1 :下一页&#xff1b;f…

卡尔曼滤波五个公式_卡尔曼滤波详细解析

对于机器人领域的同学来说&#xff0c;卡尔曼滤波是永远绕不开的话题。我曾不止一次浏览介绍卡尔曼滤波理论和推导的文章&#xff0c;但从没有完全弄懂过。究其原因&#xff0c;一是对卡尔曼滤波依赖的概率学知识所知甚少&#xff0c;二是没有勇气亲手推导一遍。最近&#xff0…

.net remoting中的一点收获

作了将近半年的项目&#xff0c;几乎都是复制粘贴&#xff0c;今天突然要配置一下.net remoting 中的设置&#xff0c;试了半天也老出错&#xff0c;最后找到这边文章&#xff0c;才稍微明白了一点。Internet 信息服务 (IIS) 承载服务器激活的或客户端激活的对象时&#xff0c;…

关于自定义事件的一点体会

今天在msdn上搜索文章的时候无意中看到一个涉及 自定义事件 的部分&#xff0c;整天用到的基本都是windows开发环境下Ide的自带事件&#xff0c;比如click什么的&#xff0c;一时竟没看懂&#xff0c;回头翻书查了查&#xff0c;才稍微理解了&#xff0c;并加深了印象。虽然以前…

python脚本如何自动运行_怎么启动python脚本

Python是一种跨平台的计算机程序设计语言。是一种面向对象的动态类型语言&#xff0c;最初被设计用于编写自动化脚本(shell)&#xff0c;随着版本的不断 更新和语言新功能的添加&#xff0c;越来越多被用于独立的、大型项目的开发。 1、使用Pyhton自身提供的交互式解释器 在Lin…

python去重txt文本_Python实现对文件进行单词划分并去重排序操作示例

本文实例讲述了Python实现对文件进行单词划分并去重排序操作。分享给大家供大家参考&#xff0c;具体如下&#xff1a; 文件名&#xff1a;test1.txt 文件内容&#xff1a; But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair…

python3 excel读写_【实战】Python读写Excel实例应用

#coding:utf-8 import xlrd import xlwt import re import sys import string from datetime import datetime #read the ad play time data programFile rad.xlsx #读取广告播放时间数据文件 adFile rad.xlsx #打开文件并获取数据 adWb xlrd.open_workbook(adFile) adSheet…

python数学计算优先级_1.python基础之常见运算符整理

一.基本的数学运算符&#xff0b;加&#xff0c;两个对象相加&#xff0c;用来计算最基本的加法&#xff0c;比如11&#xff0c;等于2。&#xff08;同时&#xff0c;加法还可以用来拼接字符串&#xff09; 2. &#xff0d;减&#xff0c;可以让两个数相减&#xff0c;活着定义…