-
大小: 73KB文件类型: .zip金币: 2下载: 1 次发布日期: 2021-05-08
- 语言: Python
- 标签: Python flappybird
资源简介
使用了pygame和gameobject实现的python版的flappybird小游戏
代码片段和文件信息
start_image_filename = ‘start.png‘
back_image_filename = ‘bg.jpg‘
block_image_filename = ‘pipe.png‘
bird_image_filename = ‘bird.png‘
import pygame
from pygame.locals import *
from gameobjects.vector2 import *
import random
import math
SCREEN_SIZE = (378537)
#SCREEN_SIZE = (600800)
run1 = 0
run2 = 0
over = 0
def load_image(file width number):
surface = pygame.image.load(file).convert_alpha()
height = surface.get_height()
return [surface.subsurface(
Rect((i * width 0) (width height))
) for i in range(number)]
class object(object):#实体类
def __init__(selfnameposition):
self.name = name
self.position = Vector2(*position)
self.speed = 0
class Fish(pygame.sprite.Sprite):
#_life = 100
images = []
def __init__(selfr):
self.order = 0
self.rate = 0.2
self.height = 60
self.number = 3
self.position = Vector2(189269)
self.r = r
self.speed = 0
pygame.sprite.Sprite.__init__(self)
self.images = load_image(bird_image_filename80 3)
self.image = self.images[self.order]
#self.rect = Rect(0 0 self.width self.height)
#self.life = self._life
self.passed_time = 0
def update(self passed_time):
self.passed_time += passed_time
self.order = ( self.passed_time / self.rate ) % self.number
if self.order == 0 and self.passed_time > self.rate:
self.passed_time = 0
self.image = self.images[int(self.order)]
def render(selfscreen):
xy = self.position
x -= 40
y -= 30
screen.blit(self.image(int(x)int(y)))
#class Fish(object):#小球类
#def __init__(selfnamepositionr):
#object.__init__(selfnameposition)
#self.r = r
#def render(selfscreen):#绘制小球自己
#xy = self.position
#pygame.draw.circle(screen (25116240) (int(x)int(y))self.r)
class Block(object):#方块类
def __init__(selfnamepositionIDimage):
object.__init__(selfnameposition)
self.ran = random.randint(0200)#随机值用于开口位置
self.ID = ID#用于标记这是第几个方块,方便统计分数
self.image = image
def render(selfscreen):#绘制上下两个长方形形成障碍物
xy = self.position
screen.blit(self.image(x250+self.ran))
screen.blit(self.image(xself.ran-353))
class Button(object):#按钮类
def __init__(self positionimage):
self.position = position
self.image = image
def render(self screen):
x y = self.position
w h = self.image.get_size()
screen.blit(self.image (x-w/2 y-h/2))
def is_over(self point):#判断鼠标是否在按钮上
if (SCREEN_SIZE[0]-self.image.get_size()[0])/2 < point[0]<(SCREEN_SIZE[0]+self.image.get_size()[0])/2:
if (SCREEN_SIZE[1]-self.image.get_size()[1])/2 < point[1]<(SCREEN_SIZE[1]+self.image.get_size()[1])/2:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 49954 2014-03-09 23:41 bg.jpg
文件 12443 2014-03-09 23:40 bird.png
文件 9398 2014-07-03 00:05 flappyfish1.2test.py
文件 13607 2014-03-12 15:34 pipe.png
文件 158 2014-07-01 20:05 readme.txt
文件 10288 2014-03-13 19:58 start.png
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论